Skip to content

Commit c3a6f1b

Browse files
committed
Change assert library with cmp library
This commit changes assert library with `github.com/google/go-cmp/cmp` library. This is because for fitting to google go style guide.
1 parent f77bb49 commit c3a6f1b

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ require (
88
github.com/go-git/go-git/v5 v5.1.0
99
github.com/go-logr/logr v0.4.0
1010
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
11+
github.com/google/go-cmp v0.5.5
1112
github.com/prometheus/client_golang v1.11.0
12-
github.com/stretchr/testify v1.7.0
1313
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
1414
golang.org/x/tools v0.1.0
1515
k8s.io/api v0.21.1

pkg/patterns/declarative/pkg/manifest/objects_test.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"fmt"
66
"testing"
77

8-
"github.com/stretchr/testify/assert"
8+
"github.com/google/go-cmp/cmp"
9+
"github.com/google/go-cmp/cmp/cmpopts"
910

1011
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1112
)
@@ -210,10 +211,8 @@ spec:
210211
if len(tt.expectedLabels) != len(o.object.GetLabels()) {
211212
t.Errorf("Expected length of labels to be %v but is %v", len(tt.expectedLabels), len(o.object.GetLabels()))
212213
}
213-
for k, v := range tt.expectedLabels {
214-
if o.object.GetLabels()[k] != v {
215-
t.Fatalf("unexpected result, expected ========\n%v\n\nactual ========\n%v\n", tt.expectedLabels, o.object.GetLabels())
216-
}
214+
if diff := cmp.Diff(tt.expectedLabels, o.object.GetLabels()); diff != "" {
215+
t.Fatalf("result mismatch (-want +got):\n%s", diff)
217216
}
218217
}
219218
})
@@ -621,11 +620,16 @@ spec:
621620
if tt.inputManifest == "" {
622621
o, _ := NewObject(&unstructured.Unstructured{})
623622
err = o.MutateContainers(tt.fn)
624-
assert.EqualError(t, err, tt.errorString)
623+
if diff := cmp.Diff(tt.errorString, err.Error()); diff != "" {
624+
t.Errorf("error mismatch (-want +got):\n%s", diff)
625+
}
626+
625627
} else {
626628
for _, o := range objects.Items {
627629
err = o.MutateContainers(tt.fn)
628-
assert.EqualError(t, err, tt.errorString)
630+
if diff := cmp.Diff(tt.errorString, err.Error()); diff != "" {
631+
t.Errorf("error mismatch (-want +got):\n%s", diff)
632+
}
629633
}
630634
}
631635
}
@@ -829,11 +833,15 @@ spec:
829833
if tt.inputManifest == "" {
830834
o, _ := NewObject(&unstructured.Unstructured{})
831835
err = o.MutatePodSpec(tt.fn)
832-
assert.EqualError(t, err, tt.errorString)
836+
if diff := cmp.Diff(tt.errorString, err.Error()); diff != "" {
837+
t.Errorf("error mismatch (-want +got):\n%s", diff)
838+
}
833839
} else {
834840
for _, o := range objects.Items {
835841
err = o.MutatePodSpec(tt.fn)
836-
assert.EqualError(t, err, tt.errorString)
842+
if diff := cmp.Diff(tt.errorString, err.Error()); diff != "" {
843+
t.Errorf("error mismatch (-want +got):\n%s", diff)
844+
}
837845
}
838846
}
839847
}
@@ -978,7 +986,9 @@ func Test_Sort(t *testing.T) {
978986
for _, tt := range tests {
979987
t.Run(tt.name, func(t *testing.T) {
980988
tt.inputObjects.Sort(tt.scoreFunc)
981-
assert.Equal(t, tt.expectedObjects, tt.inputObjects)
989+
if diff := cmp.Diff(tt.expectedObjects, tt.inputObjects, cmpopts.IgnoreUnexported(Object{})); diff != "" {
990+
t.Errorf("objects mismatch (-want +got):\n%s", diff)
991+
}
982992
})
983993
}
984994
}

pkg/patterns/declarative/watch_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package declarative
33
import (
44
"testing"
55

6+
"github.com/google/go-cmp/cmp"
7+
68
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
79
"k8s.io/apimachinery/pkg/runtime/schema"
810
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative/pkg/manifest"
9-
10-
"github.com/stretchr/testify/assert"
1111
)
1212

1313
func Test_uniqueGroupVersionKind(t *testing.T) {
@@ -131,7 +131,9 @@ func Test_uniqueGroupVersionKind(t *testing.T) {
131131
for _, tt := range tests {
132132
t.Run(tt.name, func(t *testing.T) {
133133
actualSchema := uniqueGroupVersionKind(tt.inputObjects)
134-
assert.Equal(t, tt.expectedSchema, actualSchema)
134+
if diff := cmp.Diff(tt.expectedSchema, actualSchema); diff != "" {
135+
t.Errorf("schema mismatch (-want +got):\n%s", diff)
136+
}
135137
})
136138
}
137139
}

0 commit comments

Comments
 (0)