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

chore: add unit test for updating ur status (#4541)

* fix: defer ur update until validation passes

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

* chore: add unit test for updating ur status

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-09-08 15:59:51 +02:00 committed by GitHub
parent 8fb0a9e8c7
commit 3b556abe63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -105,3 +105,68 @@ func Test_updateRequestUpdater_updateAnnotation(t *testing.T) {
})
}
}
func Test_updateRequestUpdater_setPendingStatus(t *testing.T) {
type data struct {
objects []runtime.Object
}
tests := []struct {
name string
data data
urName string
updated bool
}{{
name: "success",
data: data{
[]runtime.Object{
&kyvernov1beta1.UpdateRequest{
ObjectMeta: v1.ObjectMeta{
Name: "test",
Namespace: config.KyvernoNamespace(),
},
},
},
},
urName: "test",
updated: true,
}, {
name: "not found",
data: data{
[]runtime.Object{
&kyvernov1beta1.UpdateRequest{
ObjectMeta: v1.ObjectMeta{
Name: "dummy",
Namespace: config.KyvernoNamespace(),
},
},
},
},
urName: "dummy",
updated: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
done := ctx.Done()
t.Cleanup(cancel)
client := fake.NewSimpleClientset(tt.data.objects...)
kyvernoInformers := kyvernoinformers.NewSharedInformerFactory(client, 0)
lister := kyvernoInformers.Kyverno().V1beta1().UpdateRequests().Lister().UpdateRequests(config.KyvernoNamespace())
kyvernoInformers.Start(done)
kyvernoInformers.WaitForCacheSync(done)
h := &updateRequestUpdater{
client: client,
lister: lister,
}
h.setPendingStatus(logr.Discard(), "test")
ur, err := client.KyvernoV1beta1().UpdateRequests(config.KyvernoNamespace()).Get(ctx, tt.urName, v1.GetOptions{})
assert.NoError(t, err)
assert.NotNil(t, ur)
if tt.updated {
assert.Equal(t, kyvernov1beta1.Pending, ur.Status.State)
} else {
assert.NotEqual(t, kyvernov1beta1.Pending, ur.Status.State)
}
})
}
}