Skip to content

Commit

Permalink
Merge pull request #1578 from arajkumar/use-go-cmp-for-test-diff
Browse files Browse the repository at this point in the history
test: Use go-cmp package to diff test expectation vs actual
  • Loading branch information
k8s-ci-robot committed Sep 16, 2021
2 parents 57cd09a + 26a9a66 commit 2fed5d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require (
github.com/brancz/gojsontoyaml v0.1.0
github.com/campoy/embedmd v1.0.0
github.com/dgryski/go-jump v0.0.0-20170409065014-e1f439676b57
github.com/google/go-cmp v0.5.5
github.com/google/go-jsonnet v0.17.0
github.com/jsonnet-bundler/jsonnet-bundler v0.4.1-0.20200708074244-ada055a225fa
github.com/oklog/run v1.1.0
Expand Down Expand Up @@ -44,7 +45,6 @@ require (
github.com/go-logr/logr v0.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/imdario/mergo v0.3.5 // indirect
Expand Down
5 changes: 3 additions & 2 deletions internal/store/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sort"
"strings"

"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"

"k8s.io/kube-state-metrics/v2/pkg/metric"
Expand Down Expand Up @@ -68,8 +69,8 @@ func compareOutput(expected, actual string) error {
}
}

if entities[0] != entities[1] {
return errors.Errorf("\nEXPECTED:\n--------------\n%v\nACTUAL:\n--------------\n%v", entities[0], entities[1])
if diff := cmp.Diff(entities[0], entities[1]); diff != "" {
return errors.Errorf("(-want, +got):\n%s", diff)
}

return nil
Expand Down

0 comments on commit 2fed5d9

Please sign in to comment.