Files
open-cluster-management/pkg/common/helpers/annotations_test.go
xuezhaojun 142fd5b247 Add ClusterAnnotations support. (#234)
Signed-off-by: xuezhaojun <zxue@redhat.com>
2023-07-27 04:31:25 +02:00

72 lines
1.8 KiB
Go

package helpers
import (
"reflect"
"testing"
operatorv1 "open-cluster-management.io/api/operator/v1"
)
func TestFilterClusterAnnotations(t *testing.T) {
tests := []struct {
name string
annotations map[string]string
want map[string]string
}{
{
name: "empty annotations",
annotations: map[string]string{},
want: map[string]string{},
},
{
name: "no cluster annotations",
annotations: map[string]string{
"foo": "bar",
"baz": "qux",
},
want: map[string]string{},
},
{
name: "one cluster annotation",
annotations: map[string]string{
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar",
"baz": "qux",
},
want: map[string]string{
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar",
},
},
{
name: "multiple cluster annotations",
annotations: map[string]string{
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar",
operatorv1.ClusterAnnotationsKeyPrefix + "baz": "qux",
"quux": "corge",
},
want: map[string]string{
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar",
operatorv1.ClusterAnnotationsKeyPrefix + "baz": "qux",
},
},
{
name: "all annotations are cluster annotations",
annotations: map[string]string{
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar",
operatorv1.ClusterAnnotationsKeyPrefix + "baz": "qux",
},
want: map[string]string{
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar",
operatorv1.ClusterAnnotationsKeyPrefix + "baz": "qux",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FilterClusterAnnotations(tt.annotations); !reflect.DeepEqual(got, tt.want) {
t.Errorf("FilterClusterAnnotations() = %v, want %v", got, tt.want)
}
})
}
}