Skip to content

Commit

Permalink
tests: fix TestPod to search conditions instead of hardcoding index p…
Browse files Browse the repository at this point in the history
…ositions
  • Loading branch information
rquitales committed Mar 12, 2024
1 parent 32862c1 commit c80f2f8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tests/sdk/nodejs/nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c80f2f8

Please sign in to comment.