From c80f2f8e044917ed95b297cab549573676d17b2f Mon Sep 17 00:00:00 2001 From: Ramon Quitales Date: Mon, 11 Mar 2024 18:25:53 -0700 Subject: [PATCH] tests: fix TestPod to search conditions instead of hardcoding index positions --- tests/sdk/nodejs/nodejs_test.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/sdk/nodejs/nodejs_test.go b/tests/sdk/nodejs/nodejs_test.go index c16c5b38dd..4b9a6383cd 100644 --- a/tests/sdk/nodejs/nodejs_test.go +++ b/tests/sdk/nodejs/nodejs_test.go @@ -453,6 +453,19 @@ func TestCRDs(t *testing.T) { } func TestPod(t *testing.T) { + getCondition := func(conditions []any, conditionType string) map[string]any { + // Order of conditions is not guaranteed, so we need to search for the condition of the given type. + for _, condition := range conditions { + conditionMap, ok := condition.(map[string]any) + require.True(t, ok, "condition items should be maps") + if conditionMap["type"] == conditionType { + return conditionMap + } + } + t.Fatalf("condition of type %s not found", conditionType) + return nil + } + test := baseOptions.With(integration.ProgramTestOptions{ Dir: filepath.Join("delete-before-replace", "step1"), Quick: true, @@ -486,9 +499,7 @@ func TestPod(t *testing.T) { // Status "Ready" is "True". conditions, _ := openapi.Pluck(pod.Outputs, "status", "conditions") - ready := conditions.([]any)[1].(map[string]any) - readyType := ready["type"] - assert.Equal(t, "Ready", readyType, conditions) + ready := getCondition(conditions.([]any), "Ready") readyStatus := ready["status"] assert.Equal(t, "True", readyStatus) @@ -539,9 +550,7 @@ func TestPod(t *testing.T) { // Status "Ready" is "True". conditions, _ := openapi.Pluck(pod.Outputs, "status", "conditions") - ready := conditions.([]any)[1].(map[string]any) - readyType := ready["type"] - assert.Equal(t, "Ready", readyType) + ready := getCondition(conditions.([]any), "Ready") readyStatus := ready["status"] assert.Equal(t, "True", readyStatus)