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 cdf9a6e commit bd0f58d
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 @@ -458,6 +458,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 @@ -491,9 +504,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 @@ -544,9 +555,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 bd0f58d

Please sign in to comment.