Skip to content

Commit

Permalink
Switch to validating the parsed JSON mmatches.
Browse files Browse the repository at this point in the history
The marshaled JSON output is flaky, this ensures that it matches after parsing.
  • Loading branch information
bigkevmcd authored and tekton-robot committed Jul 8, 2020
1 parent 8231975 commit 322acc3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/interceptors/cel/cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cel

import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -242,8 +243,9 @@ func TestInterceptor_ExecuteTrigger(t *testing.T) {
rt.Fatalf("error reading response body: %v", err)
}
defer resp.Body.Close()
if diff := cmp.Diff(tt.want, got); diff != "" {
rt.Errorf("Interceptor.ExecuteTrigger (-want, +got) = %s", diff)

if diff := cmp.Diff(mustUnmarshal(t, tt.want), mustUnmarshal(t, got)); diff != "" {
t.Errorf("Interceptor.ExecuteTrigger (-want, +got) = %s", diff)
}
})
}
Expand Down Expand Up @@ -635,3 +637,13 @@ func makeSecret() *corev1.Secret {
},
}
}

func mustUnmarshal(t *testing.T, b []byte) map[string]interface{} {
t.Helper()
v := map[string]interface{}{}
err := json.Unmarshal(b, &v)
if err != nil {
t.Fatalf("failed to unmarshal the body '%s': %s", b, err)
}
return v
}

0 comments on commit 322acc3

Please sign in to comment.