From 4b5d6634702ecadf47f26300f9424b84ded02073 Mon Sep 17 00:00:00 2001 From: Zach Aller Date: Thu, 23 Feb 2023 14:13:00 -0600 Subject: [PATCH] fix: flakey TestWriteBackToInformer test (#2621) * fix: flakey TestWriteBackToInformer test Signed-off-by: zachaller * change docs to better explain issue Signed-off-by: zachaller * use built in ToUnstructured function Signed-off-by: zachaller * no need to put into Unstructured type Signed-off-by: zachaller * remove commented code and update comments Signed-off-by: zachaller --------- Signed-off-by: zachaller --- rollout/controller_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rollout/controller_test.go b/rollout/controller_test.go index d7683fddec..c953447fbd 100644 --- a/rollout/controller_test.go +++ b/rollout/controller_test.go @@ -1948,9 +1948,14 @@ func TestWriteBackToInformer(t *testing.T) { obj, exists, err := c.rolloutsIndexer.GetByKey(roKey) assert.NoError(t, err) assert.True(t, exists) - un, ok := obj.(*unstructured.Unstructured) - assert.True(t, ok) - stableRS, _, _ := unstructured.NestedString(un.Object, "status", "stableRS") + + // The type returned from c.rolloutsIndexer.GetByKey is not always the same type it switches between + // *unstructured.Unstructured and *v1alpha1.Rollout the underlying cause is not fully known. We use the + // runtime.DefaultUnstructuredConverter to account for this. + unObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) + assert.NoError(t, err) + + stableRS, _, _ := unstructured.NestedString(unObj, "status", "stableRS") assert.NotEmpty(t, stableRS) assert.Equal(t, rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey], stableRS) }