Skip to content

Change assert library with cmp library in test #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/go-git/go-git/v5 v5.1.0
github.com/go-logr/logr v0.4.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/google/go-cmp v0.5.5
github.com/prometheus/client_golang v1.11.0
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
golang.org/x/tools v0.1.0
k8s.io/api v0.21.1
Expand Down
30 changes: 20 additions & 10 deletions pkg/patterns/declarative/pkg/manifest/objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
Expand Down Expand Up @@ -210,10 +211,8 @@ spec:
if len(tt.expectedLabels) != len(o.object.GetLabels()) {
t.Errorf("Expected length of labels to be %v but is %v", len(tt.expectedLabels), len(o.object.GetLabels()))
}
for k, v := range tt.expectedLabels {
if o.object.GetLabels()[k] != v {
t.Fatalf("unexpected result, expected ========\n%v\n\nactual ========\n%v\n", tt.expectedLabels, o.object.GetLabels())
}
if diff := cmp.Diff(tt.expectedLabels, o.object.GetLabels()); diff != "" {
t.Fatalf("result mismatch (-want +got):\n%s", diff)
}
}
})
Expand Down Expand Up @@ -621,11 +620,16 @@ spec:
if tt.inputManifest == "" {
o, _ := NewObject(&unstructured.Unstructured{})
err = o.MutateContainers(tt.fn)
assert.EqualError(t, err, tt.errorString)
if diff := cmp.Diff(tt.errorString, err.Error()); diff != "" {
t.Errorf("error mismatch (-want +got):\n%s", diff)
}

} else {
for _, o := range objects.Items {
err = o.MutateContainers(tt.fn)
assert.EqualError(t, err, tt.errorString)
if diff := cmp.Diff(tt.errorString, err.Error()); diff != "" {
t.Errorf("error mismatch (-want +got):\n%s", diff)
}
}
}
}
Expand Down Expand Up @@ -829,11 +833,15 @@ spec:
if tt.inputManifest == "" {
o, _ := NewObject(&unstructured.Unstructured{})
err = o.MutatePodSpec(tt.fn)
assert.EqualError(t, err, tt.errorString)
if diff := cmp.Diff(tt.errorString, err.Error()); diff != "" {
t.Errorf("error mismatch (-want +got):\n%s", diff)
}
} else {
for _, o := range objects.Items {
err = o.MutatePodSpec(tt.fn)
assert.EqualError(t, err, tt.errorString)
if diff := cmp.Diff(tt.errorString, err.Error()); diff != "" {
t.Errorf("error mismatch (-want +got):\n%s", diff)
}
}
}
}
Expand Down Expand Up @@ -978,7 +986,9 @@ func Test_Sort(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.inputObjects.Sort(tt.scoreFunc)
assert.Equal(t, tt.expectedObjects, tt.inputObjects)
if diff := cmp.Diff(tt.expectedObjects, tt.inputObjects, cmpopts.IgnoreUnexported(Object{})); diff != "" {
t.Errorf("objects mismatch (-want +got):\n%s", diff)
}
})
}
}
8 changes: 5 additions & 3 deletions pkg/patterns/declarative/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package declarative
import (
"testing"

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

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative/pkg/manifest"

"github.com/stretchr/testify/assert"
)

func Test_uniqueGroupVersionKind(t *testing.T) {
Expand Down Expand Up @@ -131,7 +131,9 @@ func Test_uniqueGroupVersionKind(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actualSchema := uniqueGroupVersionKind(tt.inputObjects)
assert.Equal(t, tt.expectedSchema, actualSchema)
if diff := cmp.Diff(tt.expectedSchema, actualSchema); diff != "" {
t.Errorf("schema mismatch (-want +got):\n%s", diff)
}
})
}
}