mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 02:45:06 +00:00
add test for HasAutoGenAnnotation (#10487)
Signed-off-by: brf153 <153hsb@gmail.com>
This commit is contained in:
parent
fdf1f3d115
commit
124b0a3abd
1 changed files with 34 additions and 0 deletions
|
@ -53,3 +53,37 @@ func Test_ClusterPolicy_Autogen_All(t *testing.T) {
|
|||
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")
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue