Skip to content

Commit 28f6e0b

Browse files
committed
chore: cleanup tests
Signed-off-by: Jonathan Ogilvie <[email protected]>
1 parent f7bba09 commit 28f6e0b

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

cmd/diff/client/kubernetes/type_converter_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
tu "github.com/crossplane-contrib/crossplane-diff/cmd/diff/testutils"
9+
"github.com/google/go-cmp/cmp"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"k8s.io/apimachinery/pkg/runtime/schema"
1112
testdiscovery "k8s.io/client-go/discovery/fake"
@@ -171,9 +172,8 @@ func TestTypeConverter_GVKToGVR(t *testing.T) {
171172
return
172173
}
173174

174-
if gvr != tc.want.gvr {
175-
t.Errorf("\n%s\nGVKToGVR(...): -want GVR, +got GVR:\n%v vs %v",
176-
tc.reason, tc.want.gvr, gvr)
175+
if diff := cmp.Diff(tc.want.gvr, gvr); diff != "" {
176+
t.Errorf("\n%s\nGVKToGVR(...): -want GVR, +got GVR:\n%s", tc.reason, diff)
177177
}
178178
})
179179
}
@@ -357,9 +357,8 @@ func TestTypeConverter_GetResourceNameForGVK(t *testing.T) {
357357
return
358358
}
359359

360-
if resourceName != tc.want.resourceName {
361-
t.Errorf("\n%s\nGetResourceNameForGVK(...): want %q, got %q",
362-
tc.reason, tc.want.resourceName, resourceName)
360+
if diff := cmp.Diff(tc.want.resourceName, resourceName); diff != "" {
361+
t.Errorf("\n%s\nGetResourceNameForGVK(...): -want, +got:\n%s", tc.reason, diff)
363362
}
364363
})
365364
}

cmd/diff/diffprocessor/diff_calculator_test.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/crossplane-contrib/crossplane-diff/cmd/diff/renderer"
1111
dt "github.com/crossplane-contrib/crossplane-diff/cmd/diff/renderer/types"
1212
tu "github.com/crossplane-contrib/crossplane-diff/cmd/diff/testutils"
13+
gcmp "github.com/google/go-cmp/cmp"
1314
apierrors "k8s.io/apimachinery/pkg/api/errors"
1415
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1516
un "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -382,16 +383,16 @@ func TestDefaultDiffCalculator_CalculateDiff(t *testing.T) {
382383
}
383384

384385
// Check the basics of the diff
385-
if diff.Gvk != tt.wantDiff.Gvk {
386-
t.Errorf("Gvk = %v, want %v", diff.Gvk.String(), tt.wantDiff.Gvk.String())
386+
if diff := gcmp.Diff(tt.wantDiff.Gvk, diff.Gvk); diff != "" {
387+
t.Errorf("Gvk mismatch (-want +got):\n%s", diff)
387388
}
388389

389-
if diff.ResourceName != tt.wantDiff.ResourceName {
390-
t.Errorf("ResourceName = %v, want %v", diff.ResourceName, tt.wantDiff.ResourceName)
390+
if diff := gcmp.Diff(tt.wantDiff.ResourceName, diff.ResourceName); diff != "" {
391+
t.Errorf("ResourceName mismatch (-want +got):\n%s", diff)
391392
}
392393

393-
if diff.DiffType != tt.wantDiff.DiffType {
394-
t.Errorf("DiffType = %v, want %v", diff.DiffType, tt.wantDiff.DiffType)
394+
if diff := gcmp.Diff(tt.wantDiff.DiffType, diff.DiffType); diff != "" {
395+
t.Errorf("DiffType mismatch (-want +got):\n%s", diff)
395396
}
396397

397398
// For modified resources, check that LineDiffs is populated
@@ -692,8 +693,8 @@ func TestDefaultDiffCalculator_CalculateDiffs(t *testing.T) {
692693
}
693694

694695
// Check that we have the expected number of diffs
695-
if len(diffs) != len(tt.expectedDiffs) {
696-
t.Errorf("CalculateDiffs() returned %d diffs, want %d", len(diffs), len(tt.expectedDiffs))
696+
if diff := gcmp.Diff(len(tt.expectedDiffs), len(diffs)); diff != "" {
697+
t.Errorf("CalculateDiffs() number of diffs mismatch (-want +got):\n%s", diff)
697698

698699
// Print what diffs we actually got to help debug
699700
for key, diff := range diffs {
@@ -709,9 +710,8 @@ func TestDefaultDiffCalculator_CalculateDiffs(t *testing.T) {
709710
continue
710711
}
711712

712-
if diff.DiffType != expectedType {
713-
t.Errorf("CalculateDiffs() diff for key %s has type %s, want %s",
714-
expectedKey, diff.DiffType, expectedType)
713+
if diff := gcmp.Diff(expectedType, diff.DiffType); diff != "" {
714+
t.Errorf("CalculateDiffs() diff type for key %s mismatch (-want +got):\n%s", expectedKey, diff)
715715
}
716716

717717
// Check that LineDiffs is not empty for non-nil diffs
@@ -870,9 +870,8 @@ func TestDefaultDiffCalculator_CalculateRemovedResourceDiffs(t *testing.T) {
870870
}
871871

872872
// Check that the correct resources were identified for removal
873-
if len(diffs) != len(tt.expectedRemoved) {
874-
t.Errorf("CalculateRemovedResourceDiffs() found %d resources to remove, want %d",
875-
len(diffs), len(tt.expectedRemoved))
873+
if diff := gcmp.Diff(len(tt.expectedRemoved), len(diffs)); diff != "" {
874+
t.Errorf("CalculateRemovedResourceDiffs() number of removed resources mismatch (-want +got):\n%s", diff)
876875

877876
// Log what we found for debugging
878877
for key := range diffs {

cmd/diff/diffprocessor/requirements_provider_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
tu "github.com/crossplane-contrib/crossplane-diff/cmd/diff/testutils"
8+
"github.com/google/go-cmp/cmp"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
un "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1011
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -276,9 +277,8 @@ func TestRequirementsProvider_ProvideRequirements(t *testing.T) {
276277
}
277278

278279
// Check resource count
279-
if len(resources) != tt.wantCount {
280-
t.Errorf("ProvideRequirements() returned %d resources, want %d",
281-
len(resources), tt.wantCount)
280+
if diff := cmp.Diff(tt.wantCount, len(resources)); diff != "" {
281+
t.Errorf("ProvideRequirements() resource count mismatch (-want +got):\n%s", diff)
282282
}
283283

284284
// Verify expected resource names if specified

cmd/diff/diffprocessor/schema_validator_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
xp "github.com/crossplane-contrib/crossplane-diff/cmd/diff/client/crossplane"
99
tu "github.com/crossplane-contrib/crossplane-diff/cmd/diff/testutils"
10+
"github.com/google/go-cmp/cmp"
1011
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1112
un "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1213
"k8s.io/apimachinery/pkg/runtime"
@@ -273,9 +274,8 @@ func TestDefaultSchemaValidator_EnsureComposedResourceCRDs(t *testing.T) {
273274

274275
// Verify the CRD count
275276
crds := validator.(*DefaultSchemaValidator).GetCRDs()
276-
if len(crds) != tt.expectedCRDLen {
277-
t.Errorf("EnsureComposedResourceCRDs() resulted in %d CRDs, want %d",
278-
len(crds), tt.expectedCRDLen)
277+
if diff := cmp.Diff(tt.expectedCRDLen, len(crds)); diff != "" {
278+
t.Errorf("EnsureComposedResourceCRDs() CRD count mismatch (-want +got):\n%s", diff)
279279
}
280280
})
281281
}

cmd/diff/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,6 @@ func getRestConfig() (*rest.Config, error) {
8484
if kubeconfig == "" {
8585
return nil, errors.New("KUBECONFIG environment variable is not set. Please set KUBECONFIG to point to your kubeconfig file")
8686
}
87+
8788
return clientcmd.BuildConfigFromFlags("", kubeconfig)
8889
}

0 commit comments

Comments
 (0)