Skip to content
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

#7027 Cleanup cmp.Diff(want, got) for all diff.PrintWantGot() #7209

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 pkg/apis/config/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func verifyConfigFileWithExpectedMetricsConfig(t *testing.T, fileName string, ex
t.Helper()
cm := test.ConfigMapFromTestFile(t, fileName)
if ab, err := config.NewMetricsFromConfigMap(cm); err == nil {
if d := cmp.Diff(ab, expectedConfig); d != "" {
if d := cmp.Diff(expectedConfig, ab); d != "" {
t.Errorf("Diff:\n%s", diff.PrintWantGot(d))
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/config/resolver/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestStoreLoadWithContext(t *testing.T) {

cfg := resolver.FromContext(store.ToContext(context.Background()))

if d := cmp.Diff(cfg, expected); d != "" {
if d := cmp.Diff(expected, cfg); d != "" {
t.Errorf("Unexpected config %s", diff.PrintWantGot(d))
}
}
2 changes: 1 addition & 1 deletion pkg/apis/config/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestStoreLoadWithContext(t *testing.T) {

cfg := config.FromContext(store.ToContext(context.Background()))

if d := cmp.Diff(cfg, expected); d != "" {
if d := cmp.Diff(expected, cfg); d != "" {
t.Errorf("Unexpected config %s", diff.PrintWantGot(d))
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/internal/checksum/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestPrepareObjectMeta(t *testing.T) {
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
task := PrepareObjectMeta(tc.objectmeta)
if d := cmp.Diff(task, tc.expected); d != "" {
if d := cmp.Diff(tc.expected, task); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand All @@ -97,7 +97,7 @@ func TestComputeSha256Checksum(t *testing.T) {
if err != nil {
t.Fatalf("Could not marshal hello %v", err)
}
if d := cmp.Diff(hex.EncodeToString(sha), "5aa762ae383fbb727af3c7a36d4940a5b8c40a989452d2304fc958ff3f354e7a"); d != "" {
if d := cmp.Diff("5aa762ae383fbb727af3c7a36d4940a5b8c40a989452d2304fc958ff3f354e7a", hex.EncodeToString(sha)); d != "" {
t.Error(diff.PrintWantGot(d))
}
}
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/param_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestParamSpec_SetDefaults(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
tc.before.SetDefaults(ctx)
if d := cmp.Diff(tc.before, tc.defaultsApplied); d != "" {
if d := cmp.Diff(tc.defaultsApplied, tc.before); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/pipeline_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ func TestPipelineChecksum(t *testing.T) {
t.Fatalf("Error computing checksum: %v", err)
}

if d := cmp.Diff(hex.EncodeToString(sha), "98bc732636b8fbc08f3d353932147e4eff4e667f0c1af675656a48efdc8178e3"); d != "" {
if d := cmp.Diff("98bc732636b8fbc08f3d353932147e4eff4e667f0c1af675656a48efdc8178e3", hex.EncodeToString(sha)); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1/pipelinerun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
got := tc.in
got.SetDefaults(ctx)
if !cmp.Equal(got, tc.want, ignoreUnexportedResources) {
d := cmp.Diff(got, tc.want, ignoreUnexportedResources)
d := cmp.Diff(tc.want, got, ignoreUnexportedResources)
t.Errorf("SetDefaults %s", diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -486,7 +486,7 @@ func TestPipelineRunDefaultingOnCreate(t *testing.T) {
got := tc.in
got.SetDefaults(ctx)
if !cmp.Equal(got, tc.want, ignoreUnexportedResources) {
d := cmp.Diff(got, tc.want, ignoreUnexportedResources)
d := cmp.Diff(tc.want, got, ignoreUnexportedResources)
t.Errorf("SetDefaults %s", diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1/pipelinerun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestPipelineRunStatusConditions(t *testing.T) {
p.Status.SetCondition(foo)

fooStatus := p.Status.GetCondition(foo.Type)
if d := cmp.Diff(fooStatus, foo, ignoreVolatileTime); d != "" {
if d := cmp.Diff(foo, fooStatus, ignoreVolatileTime); d != "" {
t.Errorf("Unexpected pipeline run condition type; diff %v", diff.PrintWantGot(d))
}

Expand All @@ -61,7 +61,7 @@ func TestPipelineRunStatusConditions(t *testing.T) {

barStatus := p.Status.GetCondition(bar.Type)

if d := cmp.Diff(barStatus, bar, ignoreVolatileTime); d != "" {
if d := cmp.Diff(bar, barStatus, ignoreVolatileTime); d != "" {
t.Fatalf("Unexpected pipeline run condition type; diff %s", diff.PrintWantGot(d))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/pipelinerun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ func TestPipelineRun_InvalidTimeouts(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
err := tc.pr.Validate(ctx)
if d := cmp.Diff(err.Error(), tc.want.Error()); d != "" {
if d := cmp.Diff(tc.want.Error(), err.Error()); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/result_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestTaskResult_SetDefaults(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
tc.before.SetDefaults(ctx)
if d := cmp.Diff(tc.before, tc.after); d != "" {
if d := cmp.Diff(tc.after, tc.before); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/task_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestTask_Checksum(t *testing.T) {
t.Fatalf("Error computing checksum: %v", err)
}

if d := cmp.Diff(hex.EncodeToString(sha), "0cf41a775529eaaa55ff115eebe5db01a3b6bf2f4b924606888736274ceb267a"); d != "" {
if d := cmp.Diff("0cf41a775529eaaa55ff115eebe5db01a3b6bf2f4b924606888736274ceb267a", hex.EncodeToString(sha)); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1/taskrun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func TestTaskRunDefaulting(t *testing.T) {
got := tc.in
got.SetDefaults(ctx)
if !cmp.Equal(got, tc.want, ignoreUnexportedResources) {
d := cmp.Diff(got, tc.want, ignoreUnexportedResources)
d := cmp.Diff(tc.want, got, ignoreUnexportedResources)
t.Errorf("SetDefaults %s", diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -469,7 +469,7 @@ func TestTaskRunDefaultingOnCreate(t *testing.T) {
got := tc.in
got.SetDefaults(ctx)
if !cmp.Equal(got, tc.want, ignoreUnexportedResources) {
d := cmp.Diff(got, tc.want, ignoreUnexportedResources)
d := cmp.Diff(tc.want, got, ignoreUnexportedResources)
t.Errorf("SetDefaults %s", diff.PrintWantGot(d))
}
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1/taskrun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func TestHasTimedOut(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.taskRun.HasTimedOut(context.Background(), testClock)
if d := cmp.Diff(result, tc.expectedStatus); d != "" {
if d := cmp.Diff(tc.expectedStatus, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -440,7 +440,7 @@ func TestIsStepNeedDebug(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.args.trd.StepNeedsDebug(tc.args.stepName)
if d := cmp.Diff(result, tc.want); d != "" {
if d := cmp.Diff(tc.want, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -477,7 +477,7 @@ func TestIsNeedDebug(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.args.trd.NeedsDebug()
if d := cmp.Diff(result, tc.want); d != "" {
if d := cmp.Diff(tc.want, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/run_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func TestRunGetTimeOut(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.run.GetTimeout()
if d := cmp.Diff(result, tc.expectedValue); d != "" {
if d := cmp.Diff(tc.expectedValue, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -408,7 +408,7 @@ func TestRunHasTimedOut(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.run.HasTimedOut(testClock)
if d := cmp.Diff(result, tc.expectedValue); d != "" {
if d := cmp.Diff(tc.expectedValue, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1alpha1/run_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestRun_Invalid(t *testing.T) {
}} {
t.Run(c.name, func(t *testing.T) {
err := c.run.Validate(context.Background())
if d := cmp.Diff(err.Error(), c.want.Error()); d != "" {
if d := cmp.Diff(c.want.Error(), err.Error()); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/customrun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func TestRunGetTimeOut(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.customRun.GetTimeout()
if d := cmp.Diff(result, tc.expectedValue); d != "" {
if d := cmp.Diff(tc.expectedValue, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestRunHasTimedOut(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.customRun.HasTimedOut(testClock)
if d := cmp.Diff(result, tc.expectedValue); d != "" {
if d := cmp.Diff(tc.expectedValue, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/customrun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestCustomRun_Invalid(t *testing.T) {
}} {
t.Run(c.name, func(t *testing.T) {
err := c.customRun.Validate(context.Background())
if d := cmp.Diff(err.Error(), c.want.Error()); d != "" {
if d := cmp.Diff(c.want.Error(), err.Error()); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/param_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestParamSpec_SetDefaults(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
tc.before.SetDefaults(ctx)
if d := cmp.Diff(tc.before, tc.defaultsApplied); d != "" {
if d := cmp.Diff(tc.defaultsApplied, tc.before); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -481,7 +481,7 @@ func TestArrayOrString(t *testing.T) {
expected = v1beta1.NewArrayOrString(tt.inputA, tt.inputB)
}

if d := cmp.Diff(expected, tt.expected); d != "" {
if d := cmp.Diff(tt.expected, expected); d != "" {
t.Errorf(diff.PrintWantGot(d))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/pipeline_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ func TestPipelineChecksum(t *testing.T) {
t.Fatalf("Error computing checksum: %v", err)
}

if d := cmp.Diff(hex.EncodeToString(sha), "ef400089e645c69a588e71fe629ce2a989743e303c058073b0829c6c6338ab8a"); d != "" {
if d := cmp.Diff("ef400089e645c69a588e71fe629ce2a989743e303c058073b0829c6c6338ab8a", hex.EncodeToString(sha)); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
got := tc.in
got.SetDefaults(ctx)
if !cmp.Equal(got, tc.want, ignoreUnexportedResources) {
d := cmp.Diff(got, tc.want, ignoreUnexportedResources)
d := cmp.Diff(tc.want, got, ignoreUnexportedResources)
t.Errorf("SetDefaults %s", diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -437,7 +437,7 @@ func TestPipelineRunDefaultingOnCreate(t *testing.T) {
got := tc.in
got.SetDefaults(ctx)
if !cmp.Equal(got, tc.want, ignoreUnexportedResources) {
d := cmp.Diff(got, tc.want, ignoreUnexportedResources)
d := cmp.Diff(tc.want, got, ignoreUnexportedResources)
t.Errorf("SetDefaults %s", diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestPipelineRunStatusConditions(t *testing.T) {
p.Status.SetCondition(foo)

fooStatus := p.Status.GetCondition(foo.Type)
if d := cmp.Diff(fooStatus, foo, ignoreVolatileTime); d != "" {
if d := cmp.Diff(foo, fooStatus, ignoreVolatileTime); d != "" {
t.Errorf("Unexpected pipeline run condition type; diff %v", diff.PrintWantGot(d))
}

Expand All @@ -65,7 +65,7 @@ func TestPipelineRunStatusConditions(t *testing.T) {

barStatus := p.Status.GetCondition(bar.Type)

if d := cmp.Diff(barStatus, bar, ignoreVolatileTime); d != "" {
if d := cmp.Diff(bar, barStatus, ignoreVolatileTime); d != "" {
t.Fatalf("Unexpected pipeline run condition type; diff %s", diff.PrintWantGot(d))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ func TestPipelineRun_InvalidTimeouts(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
err := tc.pr.Validate(ctx)
if d := cmp.Diff(err.Error(), tc.want.Error()); d != "" {
if d := cmp.Diff(tc.want.Error(), err.Error()); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/result_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestTaskResult_SetDefaults(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
tc.before.SetDefaults(ctx)
if d := cmp.Diff(tc.before, tc.after); d != "" {
if d := cmp.Diff(tc.after, tc.before); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/task_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestTask_Checksum(t *testing.T) {
t.Fatalf("Error computing checksum: %v", err)
}

if d := cmp.Diff(hex.EncodeToString(sha), "c913fb33ce186f8a98e77eb2885495da71103de323a1dc420d1df1809a10dfd4"); d != "" {
if d := cmp.Diff("c913fb33ce186f8a98e77eb2885495da71103de323a1dc420d1df1809a10dfd4", hex.EncodeToString(sha)); d != "" {
t.Error(diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func TestTaskRunDefaulting(t *testing.T) {
got := tc.in
got.SetDefaults(ctx)
if !cmp.Equal(got, tc.want, ignoreUnexportedResources) {
d := cmp.Diff(got, tc.want, ignoreUnexportedResources)
d := cmp.Diff(tc.want, got, ignoreUnexportedResources)
t.Errorf("SetDefaults %s", diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -453,7 +453,7 @@ func TestTaskRunDefaultingOnCreate(t *testing.T) {
got := tc.in
got.SetDefaults(ctx)
if !cmp.Equal(got, tc.want, ignoreUnexportedResources) {
d := cmp.Diff(got, tc.want, ignoreUnexportedResources)
d := cmp.Diff(tc.want, got, ignoreUnexportedResources)
t.Errorf("SetDefaults %s", diff.PrintWantGot(d))
}
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1beta1/taskrun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func TestHasTimedOut(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.taskRun.HasTimedOut(context.Background(), testClock)
if d := cmp.Diff(result, tc.expectedStatus); d != "" {
if d := cmp.Diff(tc.expectedStatus, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestIsStepNeedDebug(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.args.trd.StepNeedsDebug(tc.args.stepName)
if d := cmp.Diff(result, tc.want); d != "" {
if d := cmp.Diff(tc.want, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down Expand Up @@ -537,7 +537,7 @@ func TestIsNeedDebug(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := tc.args.trd.NeedsDebug()
if d := cmp.Diff(result, tc.want); d != "" {
if d := cmp.Diff(tc.want, result); d != "" {
t.Fatalf(diff.PrintWantGot(d))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2717,7 +2717,7 @@ func TestPodBuildwithSpireEnabled(t *testing.T) {
}

want := kmeta.ChildName(tr.Name, "-pod")
if d := cmp.Diff(got.Name, want); d != "" {
if d := cmp.Diff(want, got.Name); d != "" {
t.Errorf("Unexpected pod name, diff=%s", diff.PrintWantGot(d))
}

Expand Down Expand Up @@ -2766,7 +2766,7 @@ func TestMakeLabels(t *testing.T) {
},
},
})
if d := cmp.Diff(got, want); d != "" {
if d := cmp.Diff(want, got); d != "" {
t.Errorf("Diff labels %s", diff.PrintWantGot(d))
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/pipeline/dag/dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestGetSchedulable(t *testing.T) {
if err != nil {
t.Fatalf("Didn't expect error when getting next tasks for %v but got %v", tc.finished, err)
}
if d := cmp.Diff(tasks, tc.expectedTasks, cmpopts.IgnoreFields(v1.PipelineTask{}, "RunAfter")); d != "" {
if d := cmp.Diff(tc.expectedTasks, tasks, cmpopts.IgnoreFields(v1.PipelineTask{}, "RunAfter")); d != "" {
t.Errorf("expected that with %v done, %v would be ready to schedule but was different: %s", tc.finished, tc.expectedTasks, diff.PrintWantGot(d))
}
})
Expand Down
Loading