Skip to content
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
11 changes: 5 additions & 6 deletions cmd/diff/client/kubernetes/type_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

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

if gvr != tc.want.gvr {
t.Errorf("\n%s\nGVKToGVR(...): -want GVR, +got GVR:\n%v vs %v",
tc.reason, tc.want.gvr, gvr)
if diff := cmp.Diff(tc.want.gvr, gvr); diff != "" {
t.Errorf("\n%s\nGVKToGVR(...): -want GVR, +got GVR:\n%s", tc.reason, diff)
}
})
}
Expand Down Expand Up @@ -357,9 +357,8 @@ func TestTypeConverter_GetResourceNameForGVK(t *testing.T) {
return
}

if resourceName != tc.want.resourceName {
t.Errorf("\n%s\nGetResourceNameForGVK(...): want %q, got %q",
tc.reason, tc.want.resourceName, resourceName)
if diff := cmp.Diff(tc.want.resourceName, resourceName); diff != "" {
t.Errorf("\n%s\nGetResourceNameForGVK(...): -want, +got:\n%s", tc.reason, diff)
}
})
}
Expand Down
27 changes: 13 additions & 14 deletions cmd/diff/diffprocessor/diff_calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/crossplane-contrib/crossplane-diff/cmd/diff/renderer"
dt "github.com/crossplane-contrib/crossplane-diff/cmd/diff/renderer/types"
tu "github.com/crossplane-contrib/crossplane-diff/cmd/diff/testutils"
gcmp "github.com/google/go-cmp/cmp"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
un "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -382,16 +383,16 @@ func TestDefaultDiffCalculator_CalculateDiff(t *testing.T) {
}

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

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

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

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

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

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

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

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

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

// Log what we found for debugging
for key := range diffs {
Expand Down
6 changes: 3 additions & 3 deletions cmd/diff/diffprocessor/requirements_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

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

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

// Verify expected resource names if specified
Expand Down
6 changes: 3 additions & 3 deletions cmd/diff/diffprocessor/schema_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

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

// Verify the CRD count
crds := validator.(*DefaultSchemaValidator).GetCRDs()
if len(crds) != tt.expectedCRDLen {
t.Errorf("EnsureComposedResourceCRDs() resulted in %d CRDs, want %d",
len(crds), tt.expectedCRDLen)
if diff := cmp.Diff(tt.expectedCRDLen, len(crds)); diff != "" {
t.Errorf("EnsureComposedResourceCRDs() CRD count mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down
1 change: 1 addition & 0 deletions cmd/diff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ func getRestConfig() (*rest.Config, error) {
if kubeconfig == "" {
return nil, errors.New("KUBECONFIG environment variable is not set. Please set KUBECONFIG to point to your kubeconfig file")
}

return clientcmd.BuildConfigFromFlags("", kubeconfig)
}
Loading