Skip to content

Commit

Permalink
fix: flakey TestWriteBackToInformer test (#2621)
Browse files Browse the repository at this point in the history
* fix: flakey TestWriteBackToInformer test

Signed-off-by: zachaller <zachaller@users.noreply.github.com>

* change docs to better explain issue

Signed-off-by: zachaller <zachaller@users.noreply.github.com>

* use built in ToUnstructured function

Signed-off-by: zachaller <zachaller@users.noreply.github.com>

* no need to put into Unstructured type

Signed-off-by: zachaller <zachaller@users.noreply.github.com>

* remove commented code and update comments

Signed-off-by: zachaller <zachaller@users.noreply.github.com>

---------

Signed-off-by: zachaller <zachaller@users.noreply.github.com>
  • Loading branch information
zachaller authored Feb 23, 2023
1 parent 14a2321 commit 4b5d663
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions rollout/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4b5d663

Please sign in to comment.