1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

add test for HasAutoGenAnnotation ()

Signed-off-by: brf153 <153hsb@gmail.com>
This commit is contained in:
Devaansh Bhandari 2024-06-18 12:17:18 +05:30 committed by GitHub
parent fdf1f3d115
commit 124b0a3abd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -53,3 +53,37 @@ func Test_ClusterPolicy_Autogen_All(t *testing.T) {
assert.Equal(t, len(errs), 1) assert.Equal(t, len(errs), 1)
assert.Equal(t, errs[0].Error(), "metadata.annotations: Forbidden: Autogen annotation does not support 'all' anymore, remove the annotation or set it to a valid value") assert.Equal(t, errs[0].Error(), "metadata.annotations: Forbidden: Autogen annotation does not support 'all' anymore, remove the annotation or set it to a valid value")
} }
func Test_ClusterPolicy_HasAutoGenAnnotation(t *testing.T) {
tests := []struct {
name string
annotations map[string]string
expected bool
}{
{
name: "Policy with AutoGen annotation (true)",
annotations: map[string]string{kyverno.AnnotationAutogenControllers: "pod-policies.kyverno.io/autogen-controllers"},
expected: true,
},
{
name: "Policy with AutoGen annotation (false)",
annotations: map[string]string{kyverno.AnnotationAutogenControllers: "none"},
expected: false,
},
{
name: "Policy without AutoGen annotation",
annotations: map[string]string{},
expected: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
policy := &ClusterPolicy{ObjectMeta: metav1.ObjectMeta{Annotations: tc.annotations}}
result := policy.HasAutoGenAnnotation()
if result != tc.expected {
t.Errorf("Expected HasAutoGenAnnotation for policy %s to be %t, but got %t", tc.name, tc.expected, result)
}
})
}
}