Files
ocdp-go/backend/internal/adapter/output/k8s/entry_client_test.go
mangomqy c5e51ed069 ocdp v1
2025-11-13 02:54:06 +00:00

55 lines
1.1 KiB
Go

package k8s
import (
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/ocdp/cluster-service/internal/domain/entity"
)
func TestResourceMatchesInstance(t *testing.T) {
instance := &entity.Instance{
Name: "demo",
Namespace: "default",
}
testCases := []struct {
name string
meta metav1.ObjectMeta
want bool
}{
{
name: "matches by standard label",
meta: metav1.ObjectMeta{Labels: map[string]string{
"app.kubernetes.io/instance": "demo",
}},
want: true,
},
{
name: "matches by helm annotations",
meta: metav1.ObjectMeta{Annotations: map[string]string{
"meta.helm.sh/release-name": "demo",
"meta.helm.sh/release-namespace": "default",
}},
want: true,
},
{
name: "matches by resource name prefix",
meta: metav1.ObjectMeta{Name: "demo-nginx"},
want: true,
},
{
name: "does not match unrelated resource",
meta: metav1.ObjectMeta{Name: "other"},
want: false,
},
}
for _, tc := range testCases {
if got := resourceMatchesInstance(tc.meta, instance); got != tc.want {
t.Fatalf("%s: expected %v, got %v", tc.name, tc.want, got)
}
}
}