Skip to content

Commit

Permalink
Use cmp.Diff instead of manually comparing keys
Browse files Browse the repository at this point in the history
It feels ironic that I need to tell cmp.Diff how to marshal these in
order to compare them but oh well XD
  • Loading branch information
bobcatfish committed Dec 19, 2019
1 parent fe20b27 commit fa07c73
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ func TestEventListenerCreate(t *testing.T) {
// The structure of this field corresponds to values for the `license` key in
// testdata/pr.json, and can be used to unmarshal the dat.
type license struct {
key string
name string
spdx_id string
url string
node_id string
Key string `json:"key"`
Name string `json:"name"`
SpdxID string `json:"spdx_id"`
URL string `json:"url"`
NodeID string `json:"node_id"`
}

// compareParamsWithLicenseJSON will compare the passed in ResourceParams by further checking
Expand All @@ -398,11 +398,11 @@ func compareParamsWithLicenseJSON(x, y v1alpha1.ResourceParam) bool {
if err := json.Unmarshal([]byte(y.Value), &yData); err != nil {
return false
}
if xData.key != yData.key || xData.name != yData.name || xData.spdx_id != yData.spdx_id || xData.url != yData.url || xData.node_id != yData.node_id {
if diff := cmp.Diff(xData, yData); diff != "" {
return false
}
}
return true
}
return false
}
}

0 comments on commit fa07c73

Please sign in to comment.