diff --git a/pkg/apis/config/default_test.go b/pkg/apis/config/default_test.go index 84eca548ced..8fbe506e603 100644 --- a/pkg/apis/config/default_test.go +++ b/pkg/apis/config/default_test.go @@ -22,6 +22,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" test "github.com/tektoncd/pipeline/pkg/reconciler/testing" + "github.com/tektoncd/pipeline/test/diff" ) func TestNewDefaultsFromConfigMap(t *testing.T) { @@ -186,7 +187,7 @@ func verifyConfigFileWithExpectedConfig(t *testing.T, fileName string, expectedC cm := test.ConfigMapFromTestFile(t, fileName) if Defaults, err := NewDefaultsFromConfigMap(cm); err == nil { if d := cmp.Diff(Defaults, expectedConfig); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } else { t.Errorf("NewDefaultsFromConfigMap(actual) = %v", err) diff --git a/pkg/apis/config/store_test.go b/pkg/apis/config/store_test.go index cc2608b4113..46f9e9c59b3 100644 --- a/pkg/apis/config/store_test.go +++ b/pkg/apis/config/store_test.go @@ -22,6 +22,7 @@ import ( "github.com/google/go-cmp/cmp" test "github.com/tektoncd/pipeline/pkg/reconciler/testing" + "github.com/tektoncd/pipeline/test/diff" logtesting "knative.dev/pkg/logging/testing" ) @@ -33,7 +34,7 @@ func TestStoreLoadWithContext(t *testing.T) { config := FromContext(store.ToContext(context.Background())) expected, _ := NewDefaultsFromConfigMap(defaultConfig) - if diff := cmp.Diff(config.Defaults, expected); diff != "" { - t.Errorf("Unexpected default config (-want, +got): %v", diff) + if d := cmp.Diff(config.Defaults, expected); d != "" { + t.Errorf("Unexpected default config %s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/pipeline/v1alpha1/cluster_task_conversion_test.go b/pkg/apis/pipeline/v1alpha1/cluster_task_conversion_test.go index 89d8a0fd706..16ee18f2847 100644 --- a/pkg/apis/pipeline/v1alpha1/cluster_task_conversion_test.go +++ b/pkg/apis/pipeline/v1alpha1/cluster_task_conversion_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -175,8 +176,8 @@ func TestClusterTaskConversion(t *testing.T) { t.Errorf("ConvertFrom() = %v", err) } t.Logf("ConvertFrom() = %#v", got) - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) + if d := cmp.Diff(test.in, got); d != "" { + t.Errorf("roundtrip %s", diff.PrintWantGot(d)) } }) } @@ -312,8 +313,8 @@ func TestClusterTaskConversionFromDeprecated(t *testing.T) { t.Errorf("ConvertFrom() = %v", err) } t.Logf("ConvertFrom() = %#v", got) - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) + if d := cmp.Diff(test.want, got); d != "" { + t.Errorf("roundtrip %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/condition_defaults_test.go b/pkg/apis/pipeline/v1alpha1/condition_defaults_test.go index 66cd5cafd59..43ae37cf163 100644 --- a/pkg/apis/pipeline/v1alpha1/condition_defaults_test.go +++ b/pkg/apis/pipeline/v1alpha1/condition_defaults_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp" tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" ) func TestConditionSpec_SetDefaults(t *testing.T) { @@ -90,8 +91,8 @@ func TestConditionSpec_SetDefaults(t *testing.T) { t.Run(tc.name, func(t *testing.T) { ctx := context.Background() tc.input.SetDefaults(ctx) - if diff := cmp.Diff(tc.output, tc.input); diff != "" { - t.Errorf("Mismatch of PipelineRunSpec: %s", diff) + if d := cmp.Diff(tc.output, tc.input); d != "" { + t.Errorf("Mismatch of PipelineRunSpec: %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/condition_validation_test.go b/pkg/apis/pipeline/v1alpha1/condition_validation_test.go index a38190374f0..4b7a5dc7456 100644 --- a/pkg/apis/pipeline/v1alpha1/condition_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/condition_validation_test.go @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" "knative.dev/pkg/apis" ) @@ -92,7 +93,7 @@ func TestCondition_Invalidate(t *testing.T) { t.Fatalf("Expected an Error, got nothing for %v", tc) } if d := cmp.Diff(tc.expectedError, *err, cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" { - t.Errorf("Condition.Validate() errors diff -want, +got: %v", d) + t.Errorf("Condition.Validate() errors diff %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/container_replacements_test.go b/pkg/apis/pipeline/v1alpha1/container_replacements_test.go index 22d85ea82f2..ce84bf3a738 100644 --- a/pkg/apis/pipeline/v1alpha1/container_replacements_test.go +++ b/pkg/apis/pipeline/v1alpha1/container_replacements_test.go @@ -21,6 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" ) @@ -121,7 +122,7 @@ func TestApplyContainerReplacements(t *testing.T) { v1alpha1.ApplyContainerReplacements(&s, replacements, arrayReplacements) if d := cmp.Diff(s, expected); d != "" { - t.Errorf("Container replacements failed: %s", d) + t.Errorf("Container replacements failed: %s", diff.PrintWantGot(d)) } } @@ -142,6 +143,6 @@ func TestApplyContainerReplacements_NotDefined(t *testing.T) { } v1alpha1.ApplyContainerReplacements(&s, replacements, arrayReplacements) if d := cmp.Diff(s, expected); d != "" { - t.Errorf("Unexpected container replacement: %s", d) + t.Errorf("Unexpected container replacement: %s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/pipeline/v1alpha1/merge_test.go b/pkg/apis/pipeline/v1alpha1/merge_test.go index fecccd86dec..23f41367d30 100644 --- a/pkg/apis/pipeline/v1alpha1/merge_test.go +++ b/pkg/apis/pipeline/v1alpha1/merge_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) @@ -130,7 +131,7 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { } if d := cmp.Diff(tc.expected, result, resourceQuantityCmp); d != "" { - t.Errorf("merged steps don't match, diff: %s", d) + t.Errorf("merged steps don't match, diff: %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/param_types_test.go b/pkg/apis/pipeline/v1alpha1/param_types_test.go index 5b17ab8f841..bc320ef014e 100644 --- a/pkg/apis/pipeline/v1alpha1/param_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/param_types_test.go @@ -25,6 +25,7 @@ import ( "github.com/google/go-cmp/cmp" tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" ) func TestParamSpec_SetDefaults(t *testing.T) { @@ -72,7 +73,7 @@ func TestParamSpec_SetDefaults(t *testing.T) { ctx := context.Background() tc.before.SetDefaults(ctx) if d := cmp.Diff(tc.before, tc.defaultsApplied); d != "" { - t.Errorf("ParamSpec.SetDefaults/%s (-want, +got) = %v", tc.name, d) + t.Errorf("ParamSpec.SetDefaults/%s %s", tc.name, diff.PrintWantGot(d)) } }) } @@ -133,7 +134,7 @@ func TestArrayOrString_ApplyReplacements(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tt.args.input.ApplyReplacements(tt.args.stringReplacements, tt.args.arrayReplacements) if d := cmp.Diff(tt.expectedOutput, tt.args.input); d != "" { - t.Errorf("ApplyReplacements() output did not match expected value %s", d) + t.Errorf("ApplyReplacements() output did not match expected value %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/pipeline_conversion_test.go b/pkg/apis/pipeline/v1alpha1/pipeline_conversion_test.go index c6f23e6ff44..1a38d6e3dab 100644 --- a/pkg/apis/pipeline/v1alpha1/pipeline_conversion_test.go +++ b/pkg/apis/pipeline/v1alpha1/pipeline_conversion_test.go @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -170,8 +171,8 @@ func TestPipelineConversion(t *testing.T) { t.Errorf("ConvertFrom() = %v", err) } t.Logf("ConvertFrom() = %#v", got) - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) + if d := cmp.Diff(test.in, got); d != "" { + t.Errorf("roundtrip %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/pipelinerun_conversion_test.go b/pkg/apis/pipeline/v1alpha1/pipelinerun_conversion_test.go index e9648becb6f..0737dcab82c 100644 --- a/pkg/apis/pipeline/v1alpha1/pipelinerun_conversion_test.go +++ b/pkg/apis/pipeline/v1alpha1/pipelinerun_conversion_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -172,8 +173,8 @@ func TestPipelineRunConversion(t *testing.T) { t.Errorf("ConvertFrom() = %v", err) } t.Logf("ConvertFrom() = %#v", got) - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) + if d := cmp.Diff(test.in, got); d != "" { + t.Errorf("roundtrip %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/pipelinerun_defaults_test.go b/pkg/apis/pipeline/v1alpha1/pipelinerun_defaults_test.go index 5ebe831ac7e..718d24eb0fe 100644 --- a/pkg/apis/pipeline/v1alpha1/pipelinerun_defaults_test.go +++ b/pkg/apis/pipeline/v1alpha1/pipelinerun_defaults_test.go @@ -26,6 +26,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/contexts" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" logtesting "knative.dev/pkg/logging/testing" @@ -88,8 +89,8 @@ func TestPipelineRunSpec_SetDefaults(t *testing.T) { ctx := context.Background() tc.prs.SetDefaults(ctx) - if diff := cmp.Diff(tc.want, tc.prs); diff != "" { - t.Errorf("Mismatch of PipelineRunSpec: %s", diff) + if d := cmp.Diff(tc.want, tc.prs); d != "" { + t.Errorf("Mismatch of PipelineRunSpec %s", diff.PrintWantGot(d)) } }) } @@ -257,8 +258,8 @@ func TestPipelineRunDefaulting(t *testing.T) { } got.SetDefaults(ctx) if !cmp.Equal(got, tc.want, ignoreUnexportedResources) { - t.Errorf("SetDefaults (-want, +got) = %v", - cmp.Diff(got, tc.want, ignoreUnexportedResources)) + d := cmp.Diff(got, tc.want, ignoreUnexportedResources) + t.Errorf("SetDefaults %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go b/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go index 7067e4c3665..3f43b877856 100644 --- a/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/pipelinerun_types_test.go @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -49,7 +50,7 @@ func TestPipelineRunStatusConditions(t *testing.T) { fooStatus := p.Status.GetCondition(foo.Type) if d := cmp.Diff(fooStatus, foo, ignoreVolatileTime); d != "" { - t.Errorf("Unexpected pipeline run condition type; want %v got %v; diff %v", fooStatus, foo, d) + t.Errorf("Unexpected pipeline run condition type; diff %s", diff.PrintWantGot(d)) } // Add a second condition. @@ -58,7 +59,7 @@ func TestPipelineRunStatusConditions(t *testing.T) { barStatus := p.Status.GetCondition(bar.Type) if d := cmp.Diff(barStatus, bar, ignoreVolatileTime); d != "" { - t.Fatalf("Unexpected pipeline run condition type; want %v got %v; diff %s", barStatus, bar, d) + t.Fatalf("Unexpected pipeline run condition type; diff %s", diff.PrintWantGot(d)) } } @@ -78,7 +79,7 @@ func TestPipelineRun_TaskRunref(t *testing.T) { } if d := cmp.Diff(p.GetTaskRunRef(), expectTaskRunRef); d != "" { - t.Fatalf("Taskrun reference mismatch; want %v got %v; diff %s", expectTaskRunRef, p.GetTaskRunRef(), d) + t.Fatalf("Taskrun reference mismatch; diff %s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/pipeline/v1alpha1/pipelinerun_validation_test.go b/pkg/apis/pipeline/v1alpha1/pipelinerun_validation_test.go index 29bccf68797..3ce98a0e69c 100644 --- a/pkg/apis/pipeline/v1alpha1/pipelinerun_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/pipelinerun_validation_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -86,7 +87,7 @@ func TestPipelineRun_Invalidate(t *testing.T) { t.Run(ps.name, func(t *testing.T) { err := ps.pr.Validate(context.Background()) if d := cmp.Diff(err.Error(), ps.want.Error()); d != "" { - t.Errorf("PipelineRun.Validate/%s (-want, +got) = %v", ps.name, d) + t.Errorf("PipelineRun.Validate/%s %s", ps.name, diff.PrintWantGot(d)) } }) } @@ -187,7 +188,7 @@ func TestPipelineRunSpec_Invalidate(t *testing.T) { t.Run(ps.name, func(t *testing.T) { err := ps.spec.Validate(context.Background()) if d := cmp.Diff(ps.wantErr.Error(), err.Error()); d != "" { - t.Errorf("PipelineRunSpec.Validate/%s (-want, +got) = %v", ps.name, d) + t.Errorf("PipelineRunSpec.Validate/%s %s", ps.name, diff.PrintWantGot(d)) } }) } @@ -213,7 +214,7 @@ func TestPipelineRunSpec_Validate(t *testing.T) { for _, ps := range tests { t.Run(ps.name, func(t *testing.T) { if err := ps.spec.Validate(context.Background()); err != nil { - t.Errorf("PipelineRunSpec.Validate/%s (-want, +got) = %v", ps.name, err) + t.Errorf("PipelineRunSpec.Validate/%s %v", ps.name, err) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/resource_types_test.go b/pkg/apis/pipeline/v1alpha1/resource_types_test.go index c16b94a55d4..52a55c2ee18 100644 --- a/pkg/apis/pipeline/v1alpha1/resource_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/resource_types_test.go @@ -19,6 +19,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" ) @@ -94,7 +95,7 @@ func TestApplyTaskModifier(t *testing.T) { }} if d := cmp.Diff(expectedTaskSpec, tc.ts); d != "" { - t.Errorf("TaskSpec was not modified as expected (-want, +got): %s", d) + t.Errorf("TaskSpec was not modified as expected %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/step_replacements_test.go b/pkg/apis/pipeline/v1alpha1/step_replacements_test.go index 9ee6dc40caa..70618685b50 100644 --- a/pkg/apis/pipeline/v1alpha1/step_replacements_test.go +++ b/pkg/apis/pipeline/v1alpha1/step_replacements_test.go @@ -21,6 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" ) @@ -126,6 +127,6 @@ func TestApplyStepReplacements(t *testing.T) { } v1alpha1.ApplyStepReplacements(&s, replacements, arrayReplacements) if d := cmp.Diff(s, expected); d != "" { - t.Errorf("Container replacements failed: %s", d) + t.Errorf("Container replacements failed: %s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/pipeline/v1alpha1/task_conversion_test.go b/pkg/apis/pipeline/v1alpha1/task_conversion_test.go index 4e6078add35..f771d44dd33 100644 --- a/pkg/apis/pipeline/v1alpha1/task_conversion_test.go +++ b/pkg/apis/pipeline/v1alpha1/task_conversion_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -176,8 +177,8 @@ func TestTaskConversion(t *testing.T) { t.Errorf("ConvertFrom() = %v", err) } t.Logf("ConvertFrom() = %#v", got) - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) + if d := cmp.Diff(test.in, got); d != "" { + t.Errorf("roundtrip %s", diff.PrintWantGot(d)) } }) } @@ -313,8 +314,8 @@ func TestTaskConversionFromDeprecated(t *testing.T) { t.Errorf("ConvertFrom() = %v", err) } t.Logf("ConvertFrom() = %#v", got) - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) + if d := cmp.Diff(test.want, got); d != "" { + t.Errorf("roundtrip %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/task_validation_test.go b/pkg/apis/pipeline/v1alpha1/task_validation_test.go index be4278d8389..dcaa8f7806b 100644 --- a/pkg/apis/pipeline/v1alpha1/task_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/task_validation_test.go @@ -26,6 +26,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" ) @@ -1015,7 +1016,7 @@ func TestTaskSpecValidateError(t *testing.T) { t.Fatalf("Expected an error, got nothing for %v", ts) } if d := cmp.Diff(tt.expectedError, *err, cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" { - t.Errorf("TaskSpec.Validate() errors diff -want, +got: %v", d) + t.Errorf("TaskSpec.Validate() errors diff %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_conversion_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_conversion_test.go index c16ba7a31fe..a42d7edffbc 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_conversion_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_conversion_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -290,8 +291,8 @@ func TestTaskRunConversion(t *testing.T) { t.Errorf("ConvertFrom() = %v", err) } t.Logf("ConvertFrom() = %#v", got) - if diff := cmp.Diff(test.in, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) + if d := cmp.Diff(test.in, got); d != "" { + t.Errorf("roundtrip %s", diff.PrintWantGot(d)) } }) } @@ -431,8 +432,8 @@ func TestTaskRunConversionFromDeprecated(t *testing.T) { t.Errorf("ConvertFrom() = %v", err) } t.Logf("ConvertFrom() = %#v", got) - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("roundtrip (-want, +got) = %v", diff) + if d := cmp.Diff(test.want, got); d != "" { + t.Errorf("roundtrip %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go index 84086f99d56..7964845c1f0 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go @@ -25,6 +25,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/contexts" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" logtesting "knative.dev/pkg/logging/testing" @@ -115,8 +116,8 @@ func TestTaskRunSpec_SetDefaults(t *testing.T) { ctx := context.Background() tc.trs.SetDefaults(ctx) - if diff := cmp.Diff(tc.want, tc.trs); diff != "" { - t.Errorf("Mismatch of TaskRunSpec: %s", diff) + if d := cmp.Diff(tc.want, tc.trs); d != "" { + t.Errorf("Mismatch of TaskRunSpec %s", diff.PrintWantGot(d)) } }) } @@ -378,7 +379,7 @@ func TestTaskRunDefaulting(t *testing.T) { } got.SetDefaults(ctx) if d := cmp.Diff(tc.want, got, ignoreUnexportedResources); d != "" { - t.Errorf("SetDefaults (-want, +got) = %v", d) + t.Errorf("SetDefaults %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go index 155a78d753a..d430ebf205c 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_types_test.go @@ -25,6 +25,7 @@ import ( tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -38,7 +39,7 @@ func TestTaskRun_GetBuildPodRef(t *testing.T) { Namespace: "testns", Name: "taskrunname", }); d != "" { - t.Fatalf("taskrun build pod ref mismatch: %s", d) + t.Fatalf("taskrun build pod ref mismatch %s", diff.PrintWantGot(d)) } } @@ -247,7 +248,7 @@ func TestHasTimedOut(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.taskRun.HasTimedOut() if d := cmp.Diff(result, tc.expectedStatus); d != "" { - t.Fatalf("-want, +got: %v", d) + t.Fatalf(diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go b/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go index 5f13a0e2ff1..648fdaa7b73 100644 --- a/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go +++ b/pkg/apis/pipeline/v1alpha1/taskrun_validation_test.go @@ -25,6 +25,7 @@ import ( tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -51,7 +52,7 @@ func TestTaskRun_Invalid(t *testing.T) { t.Run(ts.name, func(t *testing.T) { err := ts.task.Validate(context.Background()) if d := cmp.Diff(err.Error(), ts.want.Error()); d != "" { - t.Errorf("TaskRun.Validate/%s (-want, +got) = %v", ts.name, d) + t.Errorf("TaskRun.Validate/%s %s", ts.name, diff.PrintWantGot(d)) } }) } @@ -95,7 +96,7 @@ func TestTaskRun_Workspaces_Invalid(t *testing.T) { t.Errorf("Expected error for invalid TaskRun but got none") } if d := cmp.Diff(ts.wantErr.Error(), err.Error()); d != "" { - t.Errorf("TaskRunSpec.Validate/%s (-want, +got) = %v", ts.name, d) + t.Errorf("TaskRunSpec.Validate/%s %s", ts.name, diff.PrintWantGot(d)) } }) } @@ -159,7 +160,7 @@ func TestTaskRunSpec_Invalid(t *testing.T) { t.Run(ts.name, func(t *testing.T) { err := ts.spec.Validate(context.Background()) if d := cmp.Diff(ts.wantErr.Error(), err.Error()); d != "" { - t.Errorf("TaskRunSpec.Validate/%s (-want, +got) = %v", ts.name, d) + t.Errorf("TaskRunSpec.Validate/%s %s", ts.name, diff.PrintWantGot(d)) } }) } @@ -322,7 +323,7 @@ func TestInput_Invalid(t *testing.T) { t.Run(ts.name, func(t *testing.T) { err := ts.inputs.Validate(context.Background(), "spec.Inputs") if d := cmp.Diff(err.Error(), ts.wantErr.Error()); d != "" { - t.Errorf("TaskRunInputs.Validate/%s (-want, +got) = %v", ts.name, d) + t.Errorf("TaskRunInputs.Validate/%s %s", ts.name, diff.PrintWantGot(d)) } }) } @@ -383,7 +384,7 @@ func TestOutput_Invalid(t *testing.T) { t.Run(ts.name, func(t *testing.T) { err := ts.outputs.Validate(context.Background(), "spec.Outputs") if d := cmp.Diff(err.Error(), ts.wantErr.Error()); d != "" { - t.Errorf("TaskRunOutputs.Validate/%s (-want, +got) = %v", ts.name, d) + t.Errorf("TaskRunOutputs.Validate/%s %s", ts.name, diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/merge_test.go b/pkg/apis/pipeline/v1beta1/merge_test.go index a2fd97ff644..30d0b75d79d 100644 --- a/pkg/apis/pipeline/v1beta1/merge_test.go +++ b/pkg/apis/pipeline/v1beta1/merge_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) @@ -108,7 +109,7 @@ func TestMergeStepsWithStepTemplate(t *testing.T) { } if d := cmp.Diff(tc.expected, result, resourceQuantityCmp); d != "" { - t.Errorf("merged steps don't match, diff: %s", d) + t.Errorf("merged steps don't match, diff: %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/param_types_test.go b/pkg/apis/pipeline/v1beta1/param_types_test.go index c23d5e61cad..94310678d4f 100644 --- a/pkg/apis/pipeline/v1beta1/param_types_test.go +++ b/pkg/apis/pipeline/v1beta1/param_types_test.go @@ -25,6 +25,7 @@ import ( "github.com/google/go-cmp/cmp" tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" ) func TestParamSpec_SetDefaults(t *testing.T) { @@ -72,7 +73,7 @@ func TestParamSpec_SetDefaults(t *testing.T) { ctx := context.Background() tc.before.SetDefaults(ctx) if d := cmp.Diff(tc.before, tc.defaultsApplied); d != "" { - t.Errorf("ParamSpec.SetDefaults/%s (-want, +got) = %v", tc.name, d) + t.Errorf("ParamSpec.SetDefaults/%s %s", tc.name, diff.PrintWantGot(d)) } }) } @@ -133,7 +134,7 @@ func TestArrayOrString_ApplyReplacements(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tt.args.input.ApplyReplacements(tt.args.stringReplacements, tt.args.arrayReplacements) if d := cmp.Diff(tt.expectedOutput, tt.args.input); d != "" { - t.Errorf("ApplyReplacements() output did not match expected value %s", d) + t.Errorf("ApplyReplacements() output did not match expected value %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go b/pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go index 95b4139edcb..4761b1bd1ba 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go @@ -25,6 +25,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/contexts" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" logtesting "knative.dev/pkg/logging/testing" @@ -83,8 +84,8 @@ func TestPipelineRunSpec_SetDefaults(t *testing.T) { ctx := context.Background() tc.prs.SetDefaults(ctx) - if diff := cmp.Diff(tc.want, tc.prs); diff != "" { - t.Errorf("Mismatch of PipelineRunSpec: %s", diff) + if d := cmp.Diff(tc.want, tc.prs); d != "" { + t.Errorf("Mismatch of PipelineRunSpec %s", diff.PrintWantGot(d)) } }) } @@ -275,8 +276,8 @@ func TestPipelineRunDefaulting(t *testing.T) { } got.SetDefaults(ctx) if !cmp.Equal(got, tc.want, ignoreUnexportedResources) { - t.Errorf("SetDefaults (-want, +got) = %v", - cmp.Diff(got, tc.want, ignoreUnexportedResources)) + d := cmp.Diff(got, tc.want, ignoreUnexportedResources) + t.Errorf("SetDefaults %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go b/pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go index 9651b89a35b..f2844ca3e1e 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_types_test.go @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -49,7 +50,7 @@ func TestPipelineRunStatusConditions(t *testing.T) { fooStatus := p.Status.GetCondition(foo.Type) if d := cmp.Diff(fooStatus, foo, ignoreVolatileTime); d != "" { - t.Errorf("Unexpected pipeline run condition type; want %v got %v; diff %v", fooStatus, foo, d) + t.Errorf("Unexpected pipeline run condition type; diff %v", diff.PrintWantGot(d)) } // Add a second condition. @@ -58,7 +59,7 @@ func TestPipelineRunStatusConditions(t *testing.T) { barStatus := p.Status.GetCondition(bar.Type) if d := cmp.Diff(barStatus, bar, ignoreVolatileTime); d != "" { - t.Fatalf("Unexpected pipeline run condition type; want %v got %v; diff %s", barStatus, bar, d) + t.Fatalf("Unexpected pipeline run condition type; diff %s", diff.PrintWantGot(d)) } } @@ -78,7 +79,7 @@ func TestPipelineRun_TaskRunref(t *testing.T) { } if d := cmp.Diff(p.GetTaskRunRef(), expectTaskRunRef); d != "" { - t.Fatalf("Taskrun reference mismatch; want %v got %v; diff %s", expectTaskRunRef, p.GetTaskRunRef(), d) + t.Fatalf("Taskrun reference mismatch; diff %s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go b/pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go index 3d0927077f9..039017b19d6 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -100,7 +101,7 @@ func TestPipelineRun_Invalidate(t *testing.T) { t.Run(ps.name, func(t *testing.T) { err := ps.pr.Validate(context.Background()) if d := cmp.Diff(err.Error(), ps.want.Error()); d != "" { - t.Errorf("PipelineRun.Validate/%s (-want, +got) = %v", ps.name, d) + t.Errorf("PipelineRun.Validate/%s %s", ps.name, diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/resource_types_test.go b/pkg/apis/pipeline/v1beta1/resource_types_test.go index fe155a71b33..ac232d7f5f2 100644 --- a/pkg/apis/pipeline/v1beta1/resource_types_test.go +++ b/pkg/apis/pipeline/v1beta1/resource_types_test.go @@ -18,6 +18,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" ) @@ -93,7 +94,7 @@ func TestApplyTaskModifier(t *testing.T) { } if d := cmp.Diff(expectedTaskSpec, tc.ts); d != "" { - t.Errorf("TaskSpec was not modified as expected (-want, +got): %s", d) + t.Errorf("TaskSpec was not modified as expected %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/resultref_test.go b/pkg/apis/pipeline/v1beta1/resultref_test.go index 57d25d29a01..a01a3b1f6b4 100644 --- a/pkg/apis/pipeline/v1beta1/resultref_test.go +++ b/pkg/apis/pipeline/v1beta1/resultref_test.go @@ -22,6 +22,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" ) func TestNewResultReference(t *testing.T) { @@ -170,7 +171,7 @@ func TestNewResultReference(t *testing.T) { } else { got := v1beta1.NewResultRefs(expressions) if d := cmp.Diff(tt.want, got); d != "" { - t.Errorf("TestNewResultReference/%s (-want, +got) = %v", tt.name, d) + t.Errorf("TestNewResultReference/%s %s", tt.name, diff.PrintWantGot(d)) } } }) @@ -306,7 +307,7 @@ func TestHasResultReference(t *testing.T) { return true }) if d := cmp.Diff(tt.wantRef, got); d != "" { - t.Errorf("TestHasResultReference/%s (-want, +got) = %v", tt.name, d) + t.Errorf("TestHasResultReference/%s %s", tt.name, diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/task_validation_test.go b/pkg/apis/pipeline/v1beta1/task_validation_test.go index ecdeb9596cf..cb05269c61f 100644 --- a/pkg/apis/pipeline/v1beta1/task_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/task_validation_test.go @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" ) @@ -870,7 +871,7 @@ func TestTaskSpecValidateError(t *testing.T) { t.Fatalf("Expected an error, got nothing for %v", ts) } if d := cmp.Diff(tt.expectedError, *err, cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" { - t.Errorf("TaskSpec.Validate() errors diff -want, +got: %v", d) + t.Errorf("TaskSpec.Validate() errors diff %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go b/pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go index e4a4f0e0b2e..7b53c0086c2 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go @@ -26,6 +26,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/contexts" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" logtesting "knative.dev/pkg/logging/testing" @@ -116,8 +117,8 @@ func TestTaskRunSpec_SetDefaults(t *testing.T) { ctx := context.Background() tc.trs.SetDefaults(ctx) - if diff := cmp.Diff(tc.want, tc.trs); diff != "" { - t.Errorf("Mismatch of TaskRunSpec: %s", diff) + if d := cmp.Diff(tc.want, tc.trs); d != "" { + t.Errorf("Mismatch of TaskRunSpec: %s", diff.PrintWantGot(d)) } }) } @@ -226,8 +227,8 @@ func TestTaskRunDefaulting(t *testing.T) { } got.SetDefaults(ctx) if !cmp.Equal(got, tc.want, ignoreUnexportedResources) { - t.Errorf("SetDefaults (-want, +got) = %v", - cmp.Diff(got, tc.want, ignoreUnexportedResources)) + d := cmp.Diff(got, tc.want, ignoreUnexportedResources) + t.Errorf("SetDefaults %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/taskrun_types_test.go b/pkg/apis/pipeline/v1beta1/taskrun_types_test.go index 17e0e2d6cac..5bc932521a8 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_types_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_types_test.go @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -43,7 +44,7 @@ func TestTaskRun_GetBuildPodRef(t *testing.T) { Namespace: "testns", Name: "taskrunname", }); d != "" { - t.Fatalf("taskrun build pod ref mismatch: %s", d) + t.Fatalf("taskrun build pod ref mismatch: %s", diff.PrintWantGot(d)) } } @@ -334,7 +335,7 @@ func TestHasTimedOut(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.taskRun.HasTimedOut() if d := cmp.Diff(result, tc.expectedStatus); d != "" { - t.Fatalf("-want, +got: %v", d) + t.Fatalf(diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go b/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go index ded5c83216b..77c709e3cc7 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go @@ -26,6 +26,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -56,7 +57,7 @@ func TestTaskRun_Invalidate(t *testing.T) { t.Run(ts.name, func(t *testing.T) { err := ts.task.Validate(context.Background()) if d := cmp.Diff(err.Error(), ts.want.Error()); d != "" { - t.Errorf("TaskRun.Validate/%s (-want, +got) = %v", ts.name, d) + t.Errorf("TaskRun.Validate/%s %s", ts.name, diff.PrintWantGot(d)) } }) } @@ -118,7 +119,7 @@ func TestTaskRun_Workspaces_Invalid(t *testing.T) { t.Errorf("Expected error for invalid TaskRun but got none") } if d := cmp.Diff(ts.wantErr.Error(), err.Error()); d != "" { - t.Errorf("TaskRunSpec.Validate/%s (-want, +got) = %v", ts.name, d) + t.Errorf("TaskRunSpec.Validate/%s %s", ts.name, diff.PrintWantGot(d)) } }) } @@ -204,7 +205,7 @@ func TestTaskRunSpec_Invalidate(t *testing.T) { t.Run(ts.name, func(t *testing.T) { err := ts.spec.Validate(context.Background()) if d := cmp.Diff(ts.wantErr.Error(), err.Error()); d != "" { - t.Errorf("TaskRunSpec.Validate/%s (-want, +got) = %v", ts.name, d) + t.Errorf("TaskRunSpec.Validate/%s %s", ts.name, diff.PrintWantGot(d)) } }) } @@ -500,7 +501,7 @@ func TestResources_Invalidate(t *testing.T) { t.Run(ts.name, func(t *testing.T) { err := ts.resources.Validate(context.Background()) if d := cmp.Diff(err.Error(), ts.wantErr.Error()); d != "" { - t.Errorf("TaskRunInputs.Validate/%s (-want, +got) = %v", ts.name, d) + t.Errorf("TaskRunInputs.Validate/%s %s", ts.name, diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource_test.go b/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource_test.go index 129cfb844ee..be9f38a0d59 100644 --- a/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource_test.go +++ b/pkg/apis/resource/v1alpha1/cloudevent/cloud_event_resource_test.go @@ -24,6 +24,7 @@ import ( pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/cloudevent" + "github.com/tektoncd/pipeline/test/diff" ) func TestNewResource_Invalid(t *testing.T) { @@ -69,7 +70,7 @@ func TestNewResource_Valid(t *testing.T) { t.Fatalf("Unexpected error creating CloudEvent resource: %s", err) } if d := cmp.Diff(expectedResource, r); d != "" { - t.Errorf("Mismatch of CloudEvent resource: %s", d) + t.Errorf("Mismatch of CloudEvent resource %s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/resource/v1alpha1/cluster/cluster_resource_test.go b/pkg/apis/resource/v1alpha1/cluster/cluster_resource_test.go index bfd755b3cd6..9fd5b6dc252 100644 --- a/pkg/apis/resource/v1alpha1/cluster/cluster_resource_test.go +++ b/pkg/apis/resource/v1alpha1/cluster/cluster_resource_test.go @@ -24,6 +24,7 @@ import ( pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/cluster" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" ) @@ -150,7 +151,7 @@ func TestNewClusterResource(t *testing.T) { t.Errorf("Test: %q; TestNewClusterResource() error = %v", c.desc, err) } if d := cmp.Diff(got, c.want); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } }) } @@ -194,6 +195,6 @@ func TestClusterResource_GetInputTaskModifier(t *testing.T) { t.Fatalf("GetDownloadSteps: %v", err) } if d := cmp.Diff(got.GetStepsToPrepend(), wantSteps); d != "" { - t.Errorf("Error mismatch between download steps: %s", d) + t.Errorf("Error mismatch between download steps: %s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/resource/v1alpha1/git/git_resource_test.go b/pkg/apis/resource/v1alpha1/git/git_resource_test.go index 87590867cdc..14764c1ef62 100644 --- a/pkg/apis/resource/v1alpha1/git/git_resource_test.go +++ b/pkg/apis/resource/v1alpha1/git/git_resource_test.go @@ -24,6 +24,7 @@ import ( pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/git" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" ) @@ -319,8 +320,8 @@ func TestNewGitResource_Valid(t *testing.T) { t.Fatalf("Unexpected error creating Git resource: %s", err) } - if diff := cmp.Diff(tc.want, got); diff != "" { - t.Errorf("Mismatch of Git resource: %s", diff) + if d := cmp.Diff(tc.want, got); d != "" { + t.Errorf("Mismatch of Git resource %s", diff.PrintWantGot(d)) } }) } @@ -357,8 +358,8 @@ func TestGitResource_Replacements(t *testing.T) { got := r.Replacements() - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("Mismatch of GitResource Replacements: %s", diff) + if d := cmp.Diff(want, got); d != "" { + t.Errorf("Mismatch of GitResource Replacements %s", diff.PrintWantGot(d)) } } @@ -673,8 +674,8 @@ func TestGitResource_GetDownloadTaskModifier(t *testing.T) { t.Fatalf("Unexpected error getting GetDownloadTaskModifier: %s", err) } - if diff := cmp.Diff([]pipelinev1alpha1.Step{{Container: tc.want}}, modifier.GetStepsToPrepend()); diff != "" { - t.Errorf("Mismatch of GitResource DownloadContainerSpec: %s", diff) + if d := cmp.Diff([]pipelinev1alpha1.Step{{Container: tc.want}}, modifier.GetStepsToPrepend()); d != "" { + t.Errorf("Mismatch of GitResource DownloadContainerSpec %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/resource/v1alpha1/image/image_resource_test.go b/pkg/apis/resource/v1alpha1/image/image_resource_test.go index d120233b49e..81a755ff19d 100644 --- a/pkg/apis/resource/v1alpha1/image/image_resource_test.go +++ b/pkg/apis/resource/v1alpha1/image/image_resource_test.go @@ -24,6 +24,7 @@ import ( tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/image" + "github.com/tektoncd/pipeline/test/diff" ) func TestNewImageResource_Invalid(t *testing.T) { @@ -57,8 +58,8 @@ func TestNewImageResource_Valid(t *testing.T) { t.Fatalf("Unexpected error creating Image resource: %s", err) } - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("Mismatch of Image resource: %s", diff) + if d := cmp.Diff(want, got); d != "" { + t.Errorf("Mismatch of Image resource: %s", diff.PrintWantGot(d)) } } @@ -79,7 +80,7 @@ func TestImageResource_Replacements(t *testing.T) { got := ir.Replacements() - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("Mismatch of ImageResource Replacements: %s", diff) + if d := cmp.Diff(want, got); d != "" { + t.Errorf("Mismatch of ImageResource Replacements %s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go b/pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go index 1ea448c76d7..33bd84b6399 100644 --- a/pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go +++ b/pkg/apis/resource/v1alpha1/pipelineresource_validation_test.go @@ -22,6 +22,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" "knative.dev/pkg/apis" ) @@ -160,7 +161,7 @@ func TestResourceValidation_Invalid(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.res.Validate(context.Background()) if d := cmp.Diff(tt.want.Error(), err.Error()); d != "" { - t.Errorf("Didn't get expected error for %s (-want, +got) = %v", tt.name, d) + t.Errorf("Didn't get expected error for %s %s", tt.name, diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource_test.go b/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource_test.go index f95f87b8778..883ea894ff8 100644 --- a/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource_test.go +++ b/pkg/apis/resource/v1alpha1/pullrequest/pull_request_resource_test.go @@ -25,6 +25,7 @@ import ( pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/pullrequest" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" ) @@ -51,8 +52,8 @@ func TestPullRequest_NewResource(t *testing.T) { PRImage: "override-with-pr:latest", InsecureSkipTLSVerify: false, } - if diff := cmp.Diff(want, got); diff != "" { - t.Error(diff) + if d := cmp.Diff(want, got); d != "" { + t.Error(diff.PrintWantGot(d)) } } @@ -145,8 +146,8 @@ func TestPullRequest_GetDownloadSteps(t *testing.T) { if err != nil { t.Fatal(err) } - if diff := cmp.Diff(tc.out, got.GetStepsToPrepend()); diff != "" { - t.Error(diff) + if d := cmp.Diff(tc.out, got.GetStepsToPrepend()); d != "" { + t.Error(diff.PrintWantGot(d)) } }) } @@ -162,8 +163,8 @@ func TestPullRequest_GetOutputSteps(t *testing.T) { if err != nil { t.Fatal(err) } - if diff := cmp.Diff(tc.out, got.GetStepsToAppend()); diff != "" { - t.Error(diff) + if d := cmp.Diff(tc.out, got.GetStepsToAppend()); d != "" { + t.Error(diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/resource/v1alpha1/storage/artifact_bucket_test.go b/pkg/apis/resource/v1alpha1/storage/artifact_bucket_test.go index 3c1a836225c..8d4cf6ce850 100644 --- a/pkg/apis/resource/v1alpha1/storage/artifact_bucket_test.go +++ b/pkg/apis/resource/v1alpha1/storage/artifact_bucket_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" ) @@ -64,7 +65,7 @@ func TestBucketGetCopyFromContainerSpec(t *testing.T) { got := bucket.GetCopyFromStorageToSteps("workspace", "src-path", "/workspace/destination") if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } @@ -81,7 +82,7 @@ func TestBucketGetCopyToContainerSpec(t *testing.T) { got := bucket.GetCopyToStorageFromSteps("workspace", "src-path", "workspace/destination") if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } @@ -97,6 +98,6 @@ func TestGetSecretsVolumes(t *testing.T) { }} got := bucket.GetSecretsVolumes() if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go b/pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go index ba2c0f652f9..b7f25211171 100644 --- a/pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go +++ b/pkg/apis/resource/v1alpha1/storage/artifact_pvc_test.go @@ -22,6 +22,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -43,7 +44,7 @@ func TestPVCGetCopyFromContainerSpec(t *testing.T) { got := pvc.GetCopyFromStorageToSteps("workspace", "src-path", "/workspace/destination") if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } @@ -68,7 +69,7 @@ func TestPVCGetCopyToContainerSpec(t *testing.T) { got := pvc.GetCopyToStorageFromSteps("workspace", "src-path", "/workspace/destination") if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } @@ -83,7 +84,7 @@ func TestPVCGetPvcMount(t *testing.T) { } got := storage.GetPvcMount(name) if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } @@ -97,7 +98,7 @@ func TestPVCGetMakeStep(t *testing.T) { }} got := storage.CreateDirStep("busybox", "workspace", "/workspace/destination") if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } @@ -113,6 +114,6 @@ func TestStorageBasePath(t *testing.T) { } got := pvc.StorageBasePath(pipelinerun) if d := cmp.Diff(got, "/pvc"); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } diff --git a/pkg/apis/resource/v1alpha1/storage/build_gcs_test.go b/pkg/apis/resource/v1alpha1/storage/build_gcs_test.go index 591303bc234..f872094c20f 100644 --- a/pkg/apis/resource/v1alpha1/storage/build_gcs_test.go +++ b/pkg/apis/resource/v1alpha1/storage/build_gcs_test.go @@ -24,6 +24,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" ) @@ -122,7 +123,7 @@ func TestNewBuildGCSResource_Valid(t *testing.T) { t.Fatalf("Unexpected error creating BuildGCS resource: %s", err) } if d := cmp.Diff(expectedGCSResource, r); d != "" { - t.Errorf("Mismatch of BuildGCS resource: %s", d) + t.Errorf("Mismatch of BuildGCS resource: %s", diff.PrintWantGot(d)) } } @@ -138,7 +139,7 @@ func TestBuildGCS_GetReplacements(t *testing.T) { "location": "gs://fake-bucket", } if d := cmp.Diff(r.Replacements(), expectedReplacementMap); d != "" { - t.Errorf("BuildGCS Replacement map mismatch: %s", d) + t.Errorf("BuildGCS Replacement map mismatch: %s", diff.PrintWantGot(d)) } } @@ -175,7 +176,7 @@ func TestBuildGCS_GetInputSteps(t *testing.T) { t.Fatalf("GetDownloadSteps: %v", err) } if d := cmp.Diff(got.GetStepsToPrepend(), wantSteps); d != "" { - t.Errorf("Error mismatch between download steps: %s", d) + t.Errorf("Error mismatch between download steps: %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/resource/v1alpha1/storage/gcs_test.go b/pkg/apis/resource/v1alpha1/storage/gcs_test.go index cc872d57bda..14d3519ac55 100644 --- a/pkg/apis/resource/v1alpha1/storage/gcs_test.go +++ b/pkg/apis/resource/v1alpha1/storage/gcs_test.go @@ -23,6 +23,7 @@ import ( tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" ) @@ -104,7 +105,7 @@ func TestValidNewGCSResource(t *testing.T) { t.Fatalf("Unexpected error creating GCS resource: %s", err) } if d := cmp.Diff(expectedGCSResource, gcsRes); d != "" { - t.Errorf("Mismatch of GCS resource: %s", d) + t.Errorf("Mismatch of GCS resource %s", diff.PrintWantGot(d)) } } @@ -120,7 +121,7 @@ func TestGCSGetReplacements(t *testing.T) { "location": "gs://fake-bucket", } if d := cmp.Diff(gcsResource.Replacements(), expectedReplacementMap); d != "" { - t.Errorf("GCS Replacement map mismatch: %s", d) + t.Errorf("GCS Replacement map mismatch %s", diff.PrintWantGot(d)) } } @@ -141,7 +142,7 @@ func TestGetParams(t *testing.T) { FieldName: "test-field-name", }} if d := cmp.Diff(gcsResource.GetSecretParams(), expectedSp); d != "" { - t.Errorf("Error mismatch on storage secret params: %s", d) + t.Errorf("Error mismatch on storage secret params %s", diff.PrintWantGot(d)) } } @@ -242,7 +243,7 @@ gsutil cp gs://some-bucket /workspace t.Fatalf("Expected error to be %t but got %v:", tc.wantErr, err) } if d := cmp.Diff(tc.wantSteps, gotSpec.GetStepsToPrepend()); d != "" { - t.Errorf("Diff(-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } }) } @@ -332,7 +333,7 @@ func TestGetOutputTaskModifier(t *testing.T) { } if d := cmp.Diff(got.GetStepsToAppend(), tc.wantSteps); d != "" { - t.Errorf("Error mismatch between upload containers spec: %s", d) + t.Errorf("Error mismatch between upload containers spec %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/artifacts/artifact_storage_test.go b/pkg/artifacts/artifact_storage_test.go index 0bafe09b6f3..2f5dd999067 100644 --- a/pkg/artifacts/artifact_storage_test.go +++ b/pkg/artifacts/artifact_storage_test.go @@ -25,6 +25,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1/storage" "github.com/tektoncd/pipeline/pkg/system" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" @@ -373,11 +374,11 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) { if err := CleanupArtifactStorage(pipelinerun, fakekubeclient, logger); err != nil { t.Fatalf("Error cleaning up artifact storage: %s", err) } - if diff := cmp.Diff(artifactStorage.GetType(), c.storagetype); diff != "" { - t.Fatalf("-want +got: %s", diff) + if d := cmp.Diff(artifactStorage.GetType(), c.storagetype); d != "" { + t.Fatalf(diff.PrintWantGot(d)) } - if diff := cmp.Diff(artifactStorage, c.expectedArtifactStorage, quantityComparer); diff != "" { - t.Fatalf("-want +got: %s", diff) + if d := cmp.Diff(artifactStorage, c.expectedArtifactStorage, quantityComparer); d != "" { + t.Fatalf(diff.PrintWantGot(d)) } }) } @@ -579,8 +580,8 @@ func TestInitializeArtifactStorageWithoutConfigMap(t *testing.T) { ShellImage: "busybox", } - if diff := cmp.Diff(pvc, expectedArtifactPVC, cmpopts.IgnoreUnexported(resource.Quantity{})); diff != "" { - t.Fatalf("-want +got: %s", diff) + if d := cmp.Diff(pvc, expectedArtifactPVC, cmpopts.IgnoreUnexported(resource.Quantity{})); d != "" { + t.Fatalf(diff.PrintWantGot(d)) } } @@ -673,8 +674,8 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) { t.Fatalf("Somehow had error initializing artifact storage run out of fake client: %s", err) } - if diff := cmp.Diff(artifactStorage, c.expectedArtifactStorage); diff != "" { - t.Fatalf("-want +got: %s", diff) + if d := cmp.Diff(artifactStorage, c.expectedArtifactStorage); d != "" { + t.Fatalf(diff.PrintWantGot(d)) } }) } @@ -693,8 +694,8 @@ func TestGetArtifactStorageWithoutConfigMap(t *testing.T) { ShellImage: "busybox", } - if diff := cmp.Diff(pvc, expectedArtifactPVC); diff != "" { - t.Fatalf("-want +got: %s", diff) + if d := cmp.Diff(pvc, expectedArtifactPVC); d != "" { + t.Fatalf(diff.PrintWantGot(d)) } } @@ -729,8 +730,8 @@ func TestGetArtifactStorageWithPVCConfigMap(t *testing.T) { t.Fatalf("Somehow had error initializing artifact storage run out of fake client: %s", err) } - if diff := cmp.Diff(artifactStorage, c.expectedArtifactStorage); diff != "" { - t.Fatalf("-want +got: %s", diff) + if d := cmp.Diff(artifactStorage, c.expectedArtifactStorage); d != "" { + t.Fatalf(diff.PrintWantGot(d)) } }) } diff --git a/pkg/credentials/gitcreds/creds_test.go b/pkg/credentials/gitcreds/creds_test.go index 551d5728afe..9f19a9905a5 100644 --- a/pkg/credentials/gitcreds/creds_test.go +++ b/pkg/credentials/gitcreds/creds_test.go @@ -26,6 +26,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/credentials" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -224,7 +225,7 @@ func TestSSHFlagHandling(t *testing.T) { IdentityFile %s/.ssh/id_foo `, credentials.VolumePath) if d := cmp.Diff(expectedSSHConfig, string(b)); d != "" { - t.Errorf("ssh_config diff: %s", d) + t.Errorf("ssh_config diff %s", diff.PrintWantGot(d)) } b, err = ioutil.ReadFile(filepath.Join(credentials.VolumePath, ".ssh", "known_hosts")) @@ -314,7 +315,7 @@ Host gitlab.example.com IdentityFile %s/.ssh/id_baz `, credentials.VolumePath, credentials.VolumePath, credentials.VolumePath) if d := cmp.Diff(expectedSSHConfig, string(b)); d != "" { - t.Errorf("ssh_config diff: %s", d) + t.Errorf("ssh_config diff %s", diff.PrintWantGot(d)) } b, err = ioutil.ReadFile(filepath.Join(credentials.VolumePath, ".ssh", "known_hosts")) @@ -325,7 +326,7 @@ Host gitlab.example.com ssh-rsa bbbb ssh-rsa cccc` if d := cmp.Diff(expectedSSHKnownHosts, string(b)); d != "" { - t.Errorf("known_hosts diff: %s", d) + t.Errorf("known_hosts diff %s", diff.PrintWantGot(d)) } b, err = ioutil.ReadFile(filepath.Join(credentials.VolumePath, ".ssh", "id_foo")) diff --git a/pkg/entrypoint/entrypointer_test.go b/pkg/entrypoint/entrypointer_test.go index faba1fe6b24..bff9821a4bb 100644 --- a/pkg/entrypoint/entrypointer_test.go +++ b/pkg/entrypoint/entrypointer_test.go @@ -26,6 +26,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" ) func TestEntrypointerFailures(t *testing.T) { @@ -80,7 +81,7 @@ func TestEntrypointerFailures(t *testing.T) { t.Fatalf("Entrypointer didn't fail") } if d := cmp.Diff(c.expectedError, err.Error()); d != "" { - t.Errorf("Entrypointer error diff -want, +got: %v", d) + t.Errorf("Entrypointer error diff %s", diff.PrintWantGot(d)) } if c.postFile != "" { diff --git a/pkg/pod/creds_init_test.go b/pkg/pod/creds_init_test.go index 5ff16d60c8e..8d49272b02e 100644 --- a/pkg/pod/creds_init_test.go +++ b/pkg/pod/creds_init_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -180,7 +181,7 @@ func TestCredsInit(t *testing.T) { t.Errorf("Got nil creds-init container, with non-empty volumes: %v", volumes) } if d := cmp.Diff(c.want, got); d != "" { - t.Fatalf("Diff(-want, +got): %s", d) + t.Fatalf("Diff %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/pod/entrypoint_lookup_test.go b/pkg/pod/entrypoint_lookup_test.go index 19e61143389..aeb9468077f 100644 --- a/pkg/pod/entrypoint_lookup_test.go +++ b/pkg/pod/entrypoint_lookup_test.go @@ -25,6 +25,7 @@ import ( v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/mutate" "github.com/google/go-containerregistry/pkg/v1/random" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" ) @@ -99,7 +100,7 @@ func TestResolveEntrypoints(t *testing.T) { Command: []string{"my", "entrypoint"}, }} if d := cmp.Diff(want, got); d != "" { - t.Fatalf("Diff (-want, +got): %s", d) + t.Fatalf("Diff %s", diff.PrintWantGot(d)) } } diff --git a/pkg/pod/entrypoint_test.go b/pkg/pod/entrypoint_test.go index 8a3a54f5a9b..fb5c8dd49bb 100644 --- a/pkg/pod/entrypoint_test.go +++ b/pkg/pod/entrypoint_test.go @@ -22,6 +22,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" fakek8s "k8s.io/client-go/kubernetes/fake" @@ -91,7 +92,7 @@ func TestOrderContainers(t *testing.T) { t.Fatalf("orderContainers: %v", err) } if d := cmp.Diff(want, got); d != "" { - t.Errorf("Diff (-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } wantInit := corev1.Container{ @@ -101,7 +102,7 @@ func TestOrderContainers(t *testing.T) { VolumeMounts: []corev1.VolumeMount{toolsMount}, } if d := cmp.Diff(wantInit, gotInit); d != "" { - t.Errorf("Init Container Diff (-want, +got): %s", d) + t.Errorf("Init Container Diff %s", diff.PrintWantGot(d)) } } @@ -175,7 +176,7 @@ func TestEntryPointResults(t *testing.T) { t.Fatalf("orderContainers: %v", err) } if d := cmp.Diff(want, got); d != "" { - t.Errorf("Diff (-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } } @@ -213,7 +214,7 @@ func TestEntryPointResultsSingleStep(t *testing.T) { t.Fatalf("orderContainers: %v", err) } if d := cmp.Diff(want, got); d != "" { - t.Errorf("Diff (-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } } func TestEntryPointSingleResultsSingleStep(t *testing.T) { @@ -247,7 +248,7 @@ func TestEntryPointSingleResultsSingleStep(t *testing.T) { t.Fatalf("orderContainers: %v", err) } if d := cmp.Diff(want, got); d != "" { - t.Errorf("Diff (-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } } func TestUpdateReady(t *testing.T) { @@ -304,7 +305,7 @@ func TestUpdateReady(t *testing.T) { if err != nil { t.Errorf("Getting pod %q after update: %v", c.pod.Name, err) } else if d := cmp.Diff(c.wantAnnotations, got.Annotations); d != "" { - t.Errorf("Annotations Diff(-want, +got): %s", d) + t.Errorf("Annotations Diff %s", diff.PrintWantGot(d)) } }) } @@ -419,7 +420,7 @@ func TestStopSidecars(t *testing.T) { if err != nil { t.Errorf("Getting pod %q after update: %v", c.pod.Name, err) } else if d := cmp.Diff(c.wantContainers, got.Spec.Containers); d != "" { - t.Errorf("Containers Diff(-want, +got): %s", d) + t.Errorf("Containers Diff %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index fca9b2dae5b..f47f2af9ea1 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -28,6 +28,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/system" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -827,7 +828,7 @@ script-heredoc-randomly-generated-78c5n } if d := cmp.Diff(c.want, &got.Spec, resourceQuantityCmp); d != "" { - t.Errorf("Diff(-want, +got):\n%s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } }) } @@ -850,7 +851,7 @@ func TestMakeLabels(t *testing.T) { }, }) if d := cmp.Diff(got, want); d != "" { - t.Errorf("Diff labels:\n%s", d) + t.Errorf("Diff labels %s", diff.PrintWantGot(d)) } } diff --git a/pkg/pod/resource_request_test.go b/pkg/pod/resource_request_test.go index 78168080af7..2a7d5ce6c7e 100644 --- a/pkg/pod/resource_request_test.go +++ b/pkg/pod/resource_request_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) @@ -208,7 +209,7 @@ func TestResolveResourceRequests_No_LimitRange(t *testing.T) { t.Run(c.desc, func(t *testing.T) { got := resolveResourceRequests(c.in, allZeroQty()) if d := cmp.Diff(c.want, got, resourceQuantityCmp); d != "" { - t.Errorf("Diff(-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } }) } @@ -338,7 +339,7 @@ func TestResolveResourceRequests_LimitRange(t *testing.T) { }, ) if d := cmp.Diff(c.want, got, resourceQuantityCmp); d != "" { - t.Errorf("Diff(-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/pod/script_test.go b/pkg/pod/script_test.go index e68fd9bdea0..065de4cfa74 100644 --- a/pkg/pod/script_test.go +++ b/pkg/pod/script_test.go @@ -21,6 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" ) @@ -41,7 +42,7 @@ func TestConvertScripts_NothingToConvert_EmptySidecars(t *testing.T) { Image: "step-2", }} if d := cmp.Diff(want, gotScripts); d != "" { - t.Errorf("Diff (-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } if gotInit != nil { t.Errorf("Wanted nil init container, got %v", gotInit) @@ -68,7 +69,7 @@ func TestConvertScripts_NothingToConvert_NilSidecars(t *testing.T) { Image: "step-2", }} if d := cmp.Diff(want, gotScripts); d != "" { - t.Errorf("Diff (-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } if gotInit != nil { t.Errorf("Wanted nil init container, got %v", gotInit) @@ -102,11 +103,11 @@ func TestConvertScripts_NothingToConvert_WithSidecar(t *testing.T) { Image: "sidecar-1", }} if d := cmp.Diff(want, gotScripts); d != "" { - t.Errorf("Diff (-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } if d := cmp.Diff(wantSidecar, gotSidecars); d != "" { - t.Errorf("Diff (-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } if gotInit != nil { @@ -203,10 +204,10 @@ script-heredoc-randomly-generated-j2tds }, }} if d := cmp.Diff(wantInit, gotInit); d != "" { - t.Errorf("Init Container Diff (-want, +got): %s", d) + t.Errorf("Init Container Diff %s", diff.PrintWantGot(d)) } if d := cmp.Diff(want, gotSteps); d != "" { - t.Errorf("Containers Diff (-want, +got): %s", d) + t.Errorf("Containers Diff %s", diff.PrintWantGot(d)) } if len(gotSidecars) != 0 { @@ -294,13 +295,13 @@ sidecar-script-heredoc-randomly-generated-j2tds VolumeMounts: []corev1.VolumeMount{scriptsVolumeMount}, }} if d := cmp.Diff(wantInit, gotInit); d != "" { - t.Errorf("Init Container Diff (-want, +got): %s", d) + t.Errorf("Init Container Diff %s", diff.PrintWantGot(d)) } if d := cmp.Diff(want, gotSteps); d != "" { - t.Errorf("Step Containers Diff (-want, +got): %s", d) + t.Errorf("Step Containers Diff %s", diff.PrintWantGot(d)) } if d := cmp.Diff(wantSidecars, gotSidecars); d != "" { - t.Errorf("Sidecar Containers Diff (-want, +got): %s", d) + t.Errorf("Sidecar Containers Diff %s", diff.PrintWantGot(d)) } if len(gotSidecars) != 1 { diff --git a/pkg/pod/status_test.go b/pkg/pod/status_test.go index 333517f8f74..e14cdbed81a 100644 --- a/pkg/pod/status_test.go +++ b/pkg/pod/status_test.go @@ -24,6 +24,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/logging" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -729,7 +730,7 @@ func TestMakeTaskRunStatus(t *testing.T) { return y != nil }) if d := cmp.Diff(c.want, got, ignoreVolatileTime, ensureTimeNotNil); d != "" { - t.Errorf("Diff(-want, +got): %s", d) + t.Errorf("Diff %s", diff.PrintWantGot(d)) } if tr.Status.StartTime.Time != c.want.StartTime.Time { t.Errorf("Expected TaskRun startTime to be unchanged but was %s", tr.Status.StartTime) @@ -879,7 +880,7 @@ func TestSortTaskRunStepOrder(t *testing.T) { want := []string{"hello", "exit", "world", "nop"} if d := cmp.Diff(want, gotNames); d != "" { - t.Errorf("Unexpected step order (-want, +got): %s", d) + t.Errorf("Unexpected step order %s", diff.PrintWantGot(d)) } } @@ -918,7 +919,7 @@ func TestSortContainerStatuses(t *testing.T) { want := []string{"my", "world", "hello"} if d := cmp.Diff(want, gotNames); d != "" { - t.Errorf("Unexpected step order (-want, +got): %s", d) + t.Errorf("Unexpected step order %s", diff.PrintWantGot(d)) } } diff --git a/pkg/pod/workingdir_init_test.go b/pkg/pod/workingdir_init_test.go index 7752b8aea9a..6e68ac0097a 100644 --- a/pkg/pod/workingdir_init_test.go +++ b/pkg/pod/workingdir_init_test.go @@ -21,6 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" ) @@ -66,7 +67,7 @@ func TestWorkingDirInit(t *testing.T) { t.Run(c.desc, func(t *testing.T) { got := workingDirInit(images.ShellImage, c.stepContainers) if d := cmp.Diff(c.want, got); d != "" { - t.Fatalf("Diff (-want, +got): %s", d) + t.Fatalf("Diff %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/pullrequest/api_test.go b/pkg/pullrequest/api_test.go index db869ed089a..828691569f2 100644 --- a/pkg/pullrequest/api_test.go +++ b/pkg/pullrequest/api_test.go @@ -25,6 +25,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/fake" + "github.com/tektoncd/pipeline/test/diff" "github.com/google/go-cmp/cmp" "go.uber.org/zap" @@ -112,8 +113,8 @@ func TestDownload(t *testing.T) { } populateManifest(want) - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("Get PullRequest: -want +got: %s", diff) + if d := cmp.Diff(want, got); d != "" { + t.Errorf("Get PullRequest: %s", diff.PrintWantGot(d)) } } @@ -163,8 +164,8 @@ func TestUpload_NewComment(t *testing.T) { // Only compare comments since the resource manifest will change between // downloads. - if diff := cmp.Diff(r.Comments, got.Comments); diff != "" { - t.Errorf("-want +got: %s", diff) + if d := cmp.Diff(r.Comments, got.Comments); d != "" { + t.Errorf(diff.PrintWantGot(d)) } } @@ -184,8 +185,8 @@ func TestUpload_DeleteComment(t *testing.T) { t.Fatal(err) } - if diff := cmp.Diff(r.Comments, got.Comments); diff != "" { - t.Errorf("-want +got: %s", diff) + if d := cmp.Diff(r.Comments, got.Comments); d != "" { + t.Errorf(diff.PrintWantGot(d)) } } @@ -218,8 +219,8 @@ func TestUpload_ManifestComment(t *testing.T) { Author: scm.User{Login: "k8s-ci-robot"}, }} - if diff := cmp.Diff(r.Comments, got.Comments); diff != "" { - t.Errorf("-want +got: %s", diff) + if d := cmp.Diff(r.Comments, got.Comments); d != "" { + t.Errorf(diff.PrintWantGot(d)) } } @@ -243,8 +244,8 @@ func TestUpload_NewStatus(t *testing.T) { t.Fatal(err) } - if diff := cmp.Diff(r, got); diff != "" { - t.Errorf("-want +got: %s", diff) + if d := cmp.Diff(r, got); d != "" { + t.Errorf(diff.PrintWantGot(d)) } } @@ -264,8 +265,8 @@ func TestUpload_UpdateStatus(t *testing.T) { t.Fatal(err) } - if diff := cmp.Diff(r, got); diff != "" { - t.Errorf("-want +got: %s", diff) + if d := cmp.Diff(r, got); d != "" { + t.Errorf(diff.PrintWantGot(d)) } } @@ -304,7 +305,7 @@ func TestUpload_Invalid_Status(t *testing.T) { } for i, err := range merr.Errors { if d := cmp.Diff(expectedErrors[i], err.Error()); d != "" { - t.Errorf("Upload status error diff -want, +got: %v", d) + t.Errorf("Upload status error diff %s", diff.PrintWantGot(d)) } } } @@ -325,8 +326,8 @@ func TestUpload_NewLabel(t *testing.T) { t.Fatal(err) } - if diff := cmp.Diff(r.PR, got.PR); diff != "" { - t.Errorf("-want +got: %s", diff) + if d := cmp.Diff(r.PR, got.PR); d != "" { + t.Errorf(diff.PrintWantGot(d)) } } @@ -346,8 +347,8 @@ func TestUpload_DeleteLabel(t *testing.T) { t.Fatal(err) } - if diff := cmp.Diff(r.PR, got.PR); diff != "" { - t.Errorf("-want +got: %s", diff) + if d := cmp.Diff(r.PR, got.PR); d != "" { + t.Errorf(diff.PrintWantGot(d)) } } @@ -373,7 +374,7 @@ func TestUpload_ManifestLabel(t *testing.T) { } r.PR.Labels = append(r.PR.Labels, &scm.Label{Name: "z"}) - if diff := cmp.Diff(r.PR, got.PR); diff != "" { - t.Errorf("-want +got: %s", diff) + if d := cmp.Diff(r.PR, got.PR); d != "" { + t.Errorf(diff.PrintWantGot(d)) } } diff --git a/pkg/pullrequest/disk_test.go b/pkg/pullrequest/disk_test.go index a3086ad2474..f93fe5eeaf2 100644 --- a/pkg/pullrequest/disk_test.go +++ b/pkg/pullrequest/disk_test.go @@ -29,6 +29,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/jenkins-x/go-scm/scm" + "github.com/tektoncd/pipeline/test/diff" ) func TestToDisk(t *testing.T) { @@ -86,16 +87,16 @@ func TestToDisk(t *testing.T) { if err != nil { t.Fatal(err) } - if diff := cmp.Diff(pr, rsrc.PR); diff != "" { - t.Errorf("PullRequest: -want +got: %s", diff) + if d := cmp.Diff(pr, rsrc.PR); d != "" { + t.Errorf("PullRequest %s", diff.PrintWantGot(d)) } // Check the refs checkRef := func(name string, r scm.PullRequestBranch) { actualRef := scm.PullRequestBranch{} readAndUnmarshal(t, filepath.Join(d, name), &actualRef) - if diff := cmp.Diff(actualRef, r); diff != "" { - t.Errorf("Get PullRequest: -want +got: %s", diff) + if d := cmp.Diff(actualRef, r); d != "" { + t.Errorf("Get PullRequest %s", diff.PrintWantGot(d)) } } checkRef("head.json", rsrc.PR.Head) @@ -118,8 +119,8 @@ func TestToDisk(t *testing.T) { if !ok { t.Errorf("Expected status with ID: %s, not found: %v", s.Target, statuses) } - if diff := cmp.Diff(actualStatus, *s); diff != "" { - t.Errorf("Get Status: -want +got: %s", diff) + if d := cmp.Diff(actualStatus, *s); d != "" { + t.Errorf("Get Status %s", diff.PrintWantGot(d)) } } // Check the labels @@ -182,8 +183,8 @@ func TestToDisk(t *testing.T) { if !ok { t.Errorf("Expected comment with ID: %d, not found: %v", c.ID, comments) } - if diff := cmp.Diff(actualComment, *c); diff != "" { - t.Errorf("Get Comment: -want +got: %s", diff) + if d := cmp.Diff(actualComment, *c); d != "" { + t.Errorf("Get Comment %s", diff.PrintWantGot(d)) } } gotManifest, err = manifestFromDisk(filepath.Join(d, "comments", manifestPath)) @@ -237,11 +238,11 @@ func TestFromDiskWithoutComments(t *testing.T) { } // Check the refs - if diff := cmp.Diff(rsrc.PR.Base, base); diff != "" { - t.Errorf("Get Base: -want +got: %s", diff) + if d := cmp.Diff(rsrc.PR.Base, base); d != "" { + t.Errorf("Get Base %s", diff.PrintWantGot(d)) } - if diff := cmp.Diff(rsrc.PR.Head, head); diff != "" { - t.Errorf("Get Head: -want +got: %s", diff) + if d := cmp.Diff(rsrc.PR.Head, head); d != "" { + t.Errorf("Get Head %s", diff.PrintWantGot(d)) } } @@ -346,14 +347,14 @@ func TestFromDisk(t *testing.T) { } // Check the refs - if diff := cmp.Diff(rsrc.PR.Base, base); diff != "" { - t.Errorf("Get Base: -want +got: %s", diff) + if d := cmp.Diff(rsrc.PR.Base, base); d != "" { + t.Errorf("Get Base %s", diff.PrintWantGot(d)) } - if diff := cmp.Diff(rsrc.PR.Head, head); diff != "" { - t.Errorf("Get Head: -want +got: %s", diff) + if d := cmp.Diff(rsrc.PR.Head, head); d != "" { + t.Errorf("Get Head %s", diff.PrintWantGot(d)) } - if diff := cmp.Diff(rsrc.PR.Sha, head.Sha); diff != "" { - t.Errorf("Get Sha: -want +got: %s", diff) + if d := cmp.Diff(rsrc.PR.Sha, head.Sha); d != "" { + t.Errorf("Get Sha %s", diff.PrintWantGot(d)) } // Check the comments @@ -365,16 +366,16 @@ func TestFromDisk(t *testing.T) { Body: "plaincomment", } for _, c := range rsrc.Comments { - if diff := cmp.Diff(commentMap[c.ID], *c); diff != "" { - t.Errorf("Get comments: -want +got: %s", diff) + if d := cmp.Diff(commentMap[c.ID], *c); d != "" { + t.Errorf("Get comments %s", diff.PrintWantGot(d)) } } commentManifest := Manifest{} for _, c := range comments { commentManifest[strconv.Itoa(c.ID)] = true } - if diff := cmp.Diff(commentManifest, rsrc.Manifests["comments"]); diff != "" { - t.Errorf("Comment manifest: -want + got: %s", diff) + if d := cmp.Diff(commentManifest, rsrc.Manifests["comments"]); d != "" { + t.Errorf("Comment manifest %s", diff.PrintWantGot(d)) } // Check the labels @@ -384,16 +385,16 @@ func TestFromDisk(t *testing.T) { } for _, l := range rsrc.PR.Labels { key := url.QueryEscape(l.Name) - if diff := cmp.Diff(labelsMap[key], &l); diff != "" { - t.Errorf("Get labels: -want +got: %s", diff) + if d := cmp.Diff(labelsMap[key], &l); d != "" { + t.Errorf("Get labels %s", diff.PrintWantGot(d)) } } labelManifest := Manifest{} for _, l := range labels { labelManifest[l] = true } - if diff := cmp.Diff(labelManifest, rsrc.Manifests["labels"]); diff != "" { - t.Errorf("Label manifest: -want + got: %s", diff) + if d := cmp.Diff(labelManifest, rsrc.Manifests["labels"]); d != "" { + t.Errorf("Label manifest %s", diff.PrintWantGot(d)) } // Check the statuses @@ -402,8 +403,8 @@ func TestFromDisk(t *testing.T) { statusMap[s.Label] = s } for _, s := range rsrc.Statuses { - if diff := cmp.Diff(statusMap[s.Label], *s); diff != "" { - t.Errorf("Get status: -want +got: %s", diff) + if d := cmp.Diff(statusMap[s.Label], *s); d != "" { + t.Errorf("Get status %s", diff.PrintWantGot(d)) } } } diff --git a/pkg/reconciler/pipeline/dag/dag_test.go b/pkg/reconciler/pipeline/dag/dag_test.go index e99fffea76e..f9b6e88e7b2 100644 --- a/pkg/reconciler/pipeline/dag/dag_test.go +++ b/pkg/reconciler/pipeline/dag/dag_test.go @@ -25,6 +25,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/list" "github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" + "github.com/tektoncd/pipeline/test/diff" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -144,7 +145,7 @@ func TestGetSchedulable(t *testing.T) { 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(v1alpha1.PipelineTask{}, "RunAfter")); d != "" { - t.Errorf("expected that with %v done, %v would be ready to schedule but was different: %s", tc.finished, tc.expectedTasks, 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)) } }) } diff --git a/pkg/reconciler/pipeline/dag/dagv1beta1_test.go b/pkg/reconciler/pipeline/dag/dagv1beta1_test.go index a49066ff017..8a4519667d8 100644 --- a/pkg/reconciler/pipeline/dag/dagv1beta1_test.go +++ b/pkg/reconciler/pipeline/dag/dagv1beta1_test.go @@ -28,6 +28,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" + "github.com/tektoncd/pipeline/test/diff" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -147,7 +148,7 @@ func TestGetSchedulable_v1beta1(t *testing.T) { 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(v1beta1.PipelineTask{}, "RunAfter")); d != "" { - t.Errorf("expected that with %v done, %v would be ready to schedule but was different: %s", tc.finished, tc.expectedTasks, 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)) } }) } diff --git a/pkg/reconciler/pipelinerun/config/store_test.go b/pkg/reconciler/pipelinerun/config/store_test.go index 42458a1cd27..101e3b2991b 100644 --- a/pkg/reconciler/pipelinerun/config/store_test.go +++ b/pkg/reconciler/pipelinerun/config/store_test.go @@ -24,6 +24,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/artifacts" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" + "github.com/tektoncd/pipeline/test/diff" test "github.com/tektoncd/pipeline/pkg/reconciler/testing" ) @@ -36,8 +37,8 @@ func TestStoreLoadWithContext(t *testing.T) { config := FromContext(store.ToContext(context.Background())) expected, _ := artifacts.NewArtifactBucketConfigFromConfigMap(pipeline.Images{})(bucketConfig) - if diff := cmp.Diff(expected, config.ArtifactBucket); diff != "" { - t.Errorf("Unexpected controller config (-want, +got): %v", diff) + if d := cmp.Diff(expected, config.ArtifactBucket); d != "" { + t.Errorf("Unexpected controller config %s", diff.PrintWantGot(d)) } } func TestStoreImmutableConfig(t *testing.T) { diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 23a553014a1..2d127ab3ef5 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -33,6 +33,7 @@ import ( taskrunresources "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" "github.com/tektoncd/pipeline/pkg/system" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" test "github.com/tektoncd/pipeline/test/v1alpha1" corev1 "k8s.io/api/core/v1" @@ -258,7 +259,7 @@ func TestReconcile(t *testing.T) { // ignore IgnoreUnexported ignore both after and before steps fields if d := cmp.Diff(expectedTaskRun, actual, cmpopts.SortSlices(func(x, y v1alpha1.TaskResourceBinding) bool { return x.Name < y.Name })); d != "" { - t.Errorf("expected to see TaskRun %v created. Diff (-want, +got): %s", expectedTaskRun, d) + t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, diff.PrintWantGot(d)) } // test taskrun is able to recreate correct pipeline-pvc-name if expectedTaskRun.GetPipelineRunPVCName() != "test-pipeline-run-success-pvc" { @@ -355,7 +356,7 @@ func TestReconcile_PipelineSpecTaskSpec(t *testing.T) { // ignore IgnoreUnexported ignore both after and before steps fields if d := cmp.Diff(expectedTaskRun, actual, cmpopts.SortSlices(func(x, y v1alpha1.TaskSpec) bool { return len(x.Steps) == len(y.Steps) })); d != "" { - t.Errorf("expected to see TaskRun %v created. Diff (-want, +got): %s", expectedTaskRun, d) + t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, diff.PrintWantGot(d)) } // test taskrun is able to recreate correct pipeline-pvc-name @@ -616,7 +617,7 @@ func TestUpdateTaskRunsState(t *testing.T) { pr.Status.InitializeConditions() status := getTaskRunsStatus(pr, state) if d := cmp.Diff(status, expectedPipelineRunStatus.TaskRuns); d != "" { - t.Fatalf("Expected PipelineRun status to match TaskRun(s) status, but got a mismatch: %s", d) + t.Fatalf("Expected PipelineRun status to match TaskRun(s) status, but got a mismatch: %s", diff.PrintWantGot(d)) } } @@ -756,7 +757,7 @@ func TestUpdateTaskRunStateWithConditionChecks(t *testing.T) { taskrunName: &tc.expectedStatus, } if d := cmp.Diff(status, expected, ignoreLastTransitionTime); d != "" { - t.Fatalf("Did not get expected status for %s : %s", tc.name, d) + t.Fatalf("Did not get expected status for %s %s", tc.name, diff.PrintWantGot(d)) } }) } @@ -853,7 +854,7 @@ func TestReconcileOnCompletedPipelineRun(t *testing.T) { } if d := cmp.Diff(reconciledRun.Status.TaskRuns, expectedTaskRunsStatus); d != "" { - t.Fatalf("Expected PipelineRun status to match TaskRun(s) status, but got a mismatch: %s", d) + t.Fatalf("Expected PipelineRun status to match TaskRun(s) status, but got a mismatch %s", diff.PrintWantGot(d)) } } @@ -1128,7 +1129,7 @@ func TestReconcilePropagateLabels(t *testing.T) { } if d := cmp.Diff(actual, expected); d != "" { - t.Errorf("expected to see TaskRun %v created. Diff %s", expected, d) + t.Errorf("expected to see TaskRun %v created. Diff %s", expected, diff.PrintWantGot(d)) } } @@ -1210,7 +1211,7 @@ func TestReconcileWithDifferentServiceAccounts(t *testing.T) { t.Fatalf("Expected a TaskRun to be created, but it wasn't: %s", err) } if d := cmp.Diff(actual, expectedTaskRuns[i]); d != "" { - t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRuns[i], d) + t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRuns[i], diff.PrintWantGot(d)) } } @@ -1374,7 +1375,7 @@ func TestReconcilePropagateAnnotations(t *testing.T) { ) if d := cmp.Diff(actual, expectedTaskRun); d != "" { - t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, d) + t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, diff.PrintWantGot(d)) } } @@ -1464,7 +1465,7 @@ func TestGetTaskRunTimeout(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { if d := cmp.Diff(getTaskRunTimeout(tc.pr, tc.rprt), tc.expected); d != "" { - t.Errorf("Unexpected task run timeout. Diff %s", d) + t.Errorf("Unexpected task run timeout. Diff %s", diff.PrintWantGot(d)) } }) } @@ -1549,7 +1550,7 @@ func TestReconcileWithConditionChecks(t *testing.T) { actual := []*v1alpha1.TaskRun{condCheck0, condCheck1} if d := cmp.Diff(actual, expectedConditionChecks); d != "" { - t.Errorf("expected to see 2 ConditionCheck TaskRuns created. Diff %s", d) + t.Errorf("expected to see 2 ConditionCheck TaskRuns created. Diff %s", diff.PrintWantGot(d)) } } @@ -1668,7 +1669,7 @@ func TestReconcileWithFailingConditionChecks(t *testing.T) { ) if d := cmp.Diff(actual, expectedTaskRun); d != "" { - t.Errorf("expected to see ConditionCheck TaskRun %v created. Diff %s", expectedTaskRun, d) + t.Errorf("expected to see ConditionCheck TaskRun %v created. Diff %s", expectedTaskRun, diff.PrintWantGot(d)) } } @@ -2002,7 +2003,7 @@ func TestReconcileWithTaskResults(t *testing.T) { } actualTaskRun := actual.Items[0] if d := cmp.Diff(&actualTaskRun, expectedTaskRun); d != "" { - t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRunName, d) + t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRunName, diff.PrintWantGot(d)) } } @@ -2081,7 +2082,7 @@ func TestReconcileWithTaskResultsEmbeddedNoneStarted(t *testing.T) { } actualTaskRun := actual.Items[0] if d := cmp.Diff(expectedTaskRun, &actualTaskRun); d != "" { - t.Errorf("expected to see TaskRun %v created. Diff (-want, +got): %s", expectedTaskRun, d) + t.Errorf("expected to see TaskRun %v created. Diff %s", expectedTaskRun, diff.PrintWantGot(d)) } } @@ -2154,7 +2155,7 @@ func TestReconcileWithPipelineResults(t *testing.T) { t.Fatalf("Somehow had error getting completed reconciled run out of fake client: %s", err) } if d := cmp.Diff(&pipelineRun, &prs[0]); d != "" { - t.Errorf("expected to see pipeline run results created. -want, +got: Diff %s", d) + t.Errorf("expected to see pipeline run results created. Diff %s", diff.PrintWantGot(d)) } } @@ -2173,7 +2174,7 @@ func Test_storePipelineSpec(t *testing.T) { t.Errorf("storePipelineSpec() error = %v", err) } if d := cmp.Diff(pr.Status.PipelineSpec, want); d != "" { - t.Fatalf("-want, +got: %v", d) + t.Fatalf(diff.PrintWantGot(d)) } ps.Description = "new-pipeline" @@ -2182,6 +2183,6 @@ func Test_storePipelineSpec(t *testing.T) { t.Errorf("storePipelineSpec() error = %v", err) } if d := cmp.Diff(pr.Status.PipelineSpec, want); d != "" { - t.Fatalf("-want, +got: %v", d) + t.Fatalf(diff.PrintWantGot(d)) } } diff --git a/pkg/reconciler/pipelinerun/resources/apply_test.go b/pkg/reconciler/pipelinerun/resources/apply_test.go index 608f8f07838..7fd80b1f6b1 100644 --- a/pkg/reconciler/pipelinerun/resources/apply_test.go +++ b/pkg/reconciler/pipelinerun/resources/apply_test.go @@ -26,6 +26,7 @@ import ( tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" ) func TestApplyParameters(t *testing.T) { @@ -137,7 +138,7 @@ func TestApplyParameters(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got := ApplyParameters(&tt.original.Spec, tt.run) if d := cmp.Diff(got, &tt.expected.Spec); d != "" { - t.Errorf("ApplyParameters() got diff %s", d) + t.Errorf("ApplyParameters() got diff %s", diff.PrintWantGot(d)) } }) } @@ -210,7 +211,7 @@ func TestApplyTaskResults_MinimalExpression(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ApplyTaskResults(tt.args.targets, tt.args.resolvedResultRefs) if d := cmp.Diff(tt.args.targets, tt.want); d != "" { - t.Fatalf("ApplyTaskResults() -want, +got: %v", d) + t.Fatalf("ApplyTaskResults() %s", diff.PrintWantGot(d)) } }) } @@ -283,7 +284,7 @@ func TestApplyTaskResults_EmbeddedExpression(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ApplyTaskResults(tt.args.targets, tt.args.resolvedResultRefs) if d := cmp.Diff(tt.args.targets, tt.want); d != "" { - t.Fatalf("ApplyTaskResults() -want, +got: %v", d) + t.Fatalf("ApplyTaskResults() %s", diff.PrintWantGot(d)) } }) } @@ -377,7 +378,7 @@ func TestApplyTaskResults_Conditions(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ApplyTaskResults(tt.args.targets, tt.args.resolvedResultRefs) if d := cmp.Diff(tt.args.targets[0].ResolvedConditionChecks, tt.want[0].ResolvedConditionChecks, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{}, ResolvedConditionCheck{})); d != "" { - t.Fatalf("ApplyTaskResults() -want, +got: %v", d) + t.Fatalf("ApplyTaskResults() %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go b/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go index 4fd79f2ffa2..803c83bd4ee 100644 --- a/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/conditionresolution_test.go @@ -24,6 +24,7 @@ import ( tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" @@ -284,7 +285,7 @@ func TestResolvedConditionCheck_ConditionToTaskSpec(t *testing.T) { } if d := cmp.Diff(&tc.want, got); d != "" { - t.Errorf("TaskSpec generated from Condition is unexpected -want, +got: %v", d) + t.Errorf("TaskSpec generated from Condition is unexpected %s", diff.PrintWantGot(d)) } }) } @@ -304,6 +305,6 @@ func TestResolvedConditionCheck_ToTaskResourceBindings(t *testing.T) { }} if d := cmp.Diff(expected, rcc.ToTaskResourceBindings()); d != "" { - t.Errorf("Did not get expected task resouce binding from condition: %s", d) + t.Errorf("Did not get expected task resouce binding from condition %s", diff.PrintWantGot(d)) } } diff --git a/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go b/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go index 13d6eac458f..8257c84e8b6 100644 --- a/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go +++ b/pkg/reconciler/pipelinerun/resources/input_output_steps_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources" + "github.com/tektoncd/pipeline/test/diff" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -124,7 +125,7 @@ func TestGetOutputSteps(t *testing.T) { postTasks := resources.GetOutputSteps(tc.outputs, tc.pipelineTaskName, pvcDir) sort.SliceStable(postTasks, func(i, j int) bool { return postTasks[i].Name < postTasks[j].Name }) if d := cmp.Diff(postTasks, tc.expectedtaskOuputResources); d != "" { - t.Errorf("error comparing post steps: %s", d) + t.Errorf("error comparing post steps %s", diff.PrintWantGot(d)) } }) } @@ -266,7 +267,7 @@ func TestGetInputSteps(t *testing.T) { taskInputResources := resources.GetInputSteps(tc.inputs, tc.pipelineTask.Resources.Inputs, pvcDir) sort.SliceStable(taskInputResources, func(i, j int) bool { return taskInputResources[i].Name < taskInputResources[j].Name }) if d := cmp.Diff(tc.expectedtaskInputResources, taskInputResources); d != "" { - t.Errorf("error comparing task resource inputs: %s", d) + t.Errorf("error comparing task resource inputs %s", diff.PrintWantGot(d)) } }) @@ -348,9 +349,9 @@ func TestWrapSteps(t *testing.T) { sort.SliceStable(expectedtaskOuputResources, func(i, j int) bool { return expectedtaskOuputResources[i].Name < expectedtaskOuputResources[j].Name }) if d := cmp.Diff(taskRunSpec.Resources.Inputs, expectedtaskInputResources, cmpopts.SortSlices(func(x, y v1alpha1.TaskResourceBinding) bool { return x.Name < y.Name })); d != "" { - t.Errorf("error comparing input resources: %s", d) + t.Errorf("error comparing input resources %s", diff.PrintWantGot(d)) } if d := cmp.Diff(taskRunSpec.Resources.Outputs, expectedtaskOuputResources, cmpopts.SortSlices(func(x, y v1alpha1.TaskResourceBinding) bool { return x.Name < y.Name })); d != "" { - t.Errorf("error comparing output resources: %s", d) + t.Errorf("error comparing output resources %s", diff.PrintWantGot(d)) } } diff --git a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go index 097188259d7..7617f13ada5 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go @@ -24,6 +24,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/fake" "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources" + "github.com/tektoncd/pipeline/test/diff" "k8s.io/apimachinery/pkg/runtime" ) @@ -74,8 +75,8 @@ func TestPipelineRef(t *testing.T) { t.Fatalf("Received unexpected error ( %#v )", err) } - if diff := cmp.Diff(task, tc.expected); tc.expected != nil && diff != "" { - t.Error(diff) + if d := cmp.Diff(task, tc.expected); tc.expected != nil && d != "" { + t.Error(diff.PrintWantGot(d)) } }) } diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go index c91f6f82d57..333cb30ea1a 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go @@ -29,6 +29,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/reconciler/pipeline/dag" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -677,7 +678,7 @@ func TestGetNextTasks(t *testing.T) { t.Run(tc.name, func(t *testing.T) { next := tc.state.GetNextTasks(tc.candidates) if d := cmp.Diff(next, tc.expectedNext); d != "" { - t.Errorf("Didn't get expected next Tasks: %v", d) + t.Errorf("Didn't get expected next Tasks %s", diff.PrintWantGot(d)) } }) } @@ -795,7 +796,7 @@ func TestGetNextTaskWithRetries(t *testing.T) { t.Run(tc.name, func(t *testing.T) { next := tc.state.GetNextTasks(tc.candidates) if d := cmp.Diff(next, tc.expectedNext); d != "" { - t.Errorf("Didn't get expected next Tasks: %v", d) + t.Errorf("Didn't get expected next Tasks %s", diff.PrintWantGot(d)) } }) } @@ -927,12 +928,12 @@ func TestIsDone(t *testing.T) { isDone := tc.state.IsDone() if d := cmp.Diff(isDone, tc.expected); d != "" { - t.Errorf("Didn't get expected IsDone: %v", d) + t.Errorf("Didn't get expected IsDone %s", diff.PrintWantGot(d)) } for i, pt := range tc.state { isDone = pt.IsDone() if d := cmp.Diff(isDone, tc.ptExpected[i]); d != "" { - t.Errorf("Didn't get expected (ResolvedPipelineRunTask) IsDone: %v", d) + t.Errorf("Didn't get expected (ResolvedPipelineRunTask) IsDone %s", diff.PrintWantGot(d)) } } @@ -970,7 +971,7 @@ func TestSuccessfulPipelineTaskNames(t *testing.T) { t.Run(tc.name, func(t *testing.T) { names := tc.state.SuccessfulPipelineTaskNames() if d := cmp.Diff(names, tc.expectedNames); d != "" { - t.Errorf("Expected to get completed names %v but got something different: %v", tc.expectedNames, d) + t.Errorf("Expected to get completed names %v but got something different %s", tc.expectedNames, diff.PrintWantGot(d)) } }) } @@ -1124,7 +1125,7 @@ func TestGetResourcesFromBindings(t *testing.T) { if !ok { t.Errorf("Missing expected resource git-resource: %v", m) } else if d := cmp.Diff(r, r1); d != "" { - t.Errorf("Expected resources didn't match actual -want, +got: %v", d) + t.Errorf("Expected resources didn't match actual %s", diff.PrintWantGot(d)) } r2, ok := m["image-resource"] @@ -1264,7 +1265,7 @@ func TestResolvePipelineRun(t *testing.T) { }} if d := cmp.Diff(expectedState, pipelineState, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{})); d != "" { - t.Errorf("Expected to get current pipeline state %v, but actual differed (-want, +got): %s", expectedState, d) + t.Errorf("Expected to get current pipeline state %v, but actual differed %s", expectedState, diff.PrintWantGot(d)) } } @@ -1304,10 +1305,10 @@ func TestResolvePipelineRun_PipelineTaskHasNoResources(t *testing.T) { Outputs: map[string]*v1alpha1.PipelineResource{}, } if d := cmp.Diff(pipelineState[0].ResolvedTaskResources, expectedTaskResources, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{})); d != "" { - t.Fatalf("Expected resources where only Tasks were resolved but but actual differed: %s", d) + t.Fatalf("Expected resources where only Tasks were resolved but but actual differed %s", diff.PrintWantGot(d)) } if d := cmp.Diff(pipelineState[1].ResolvedTaskResources, expectedTaskResources, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{})); d != "" { - t.Fatalf("Expected resources where only Tasks were resolved but but actual differed: %s", d) + t.Fatalf("Expected resources where only Tasks were resolved but but actual differed %s", diff.PrintWantGot(d)) } } @@ -1452,7 +1453,7 @@ func TestResolvePipelineRun_withExistingTaskRuns(t *testing.T) { }} if d := cmp.Diff(pipelineState, expectedState, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{})); d != "" { - t.Fatalf("Expected to get current pipeline state %v, but actual differed: %s", expectedState, d) + t.Fatalf("Expected to get current pipeline state %v, but actual differed %s", expectedState, diff.PrintWantGot(d)) } } @@ -1507,7 +1508,7 @@ func TestResolvedPipelineRun_PipelineTaskHasOptionalResources(t *testing.T) { }} if d := cmp.Diff(expectedState, pipelineState, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{})); d != "" { - t.Errorf("Expected to get current pipeline state %v, but actual differed (-want, +got): %s", expectedState, d) + t.Errorf("Expected to get current pipeline state %v, but actual differed %s", expectedState, diff.PrintWantGot(d)) } } @@ -1595,7 +1596,7 @@ func TestResolveConditionChecks(t *testing.T) { } if d := cmp.Diff(tc.expectedConditionCheck, pipelineState[0].ResolvedConditionChecks, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{}, ResolvedConditionCheck{})); d != "" { - t.Fatalf("ConditionChecks did not resolve as expected for case %s (-want, +got) : %s", tc.name, d) + t.Fatalf("ConditionChecks did not resolve as expected for case %s %s", tc.name, diff.PrintWantGot(d)) } }) } @@ -1688,7 +1689,7 @@ func TestResolveConditionChecks_MultipleConditions(t *testing.T) { } if d := cmp.Diff(tc.expectedConditionCheck, pipelineState[0].ResolvedConditionChecks, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{}, ResolvedConditionCheck{})); d != "" { - t.Fatalf("ConditionChecks did not resolve as expected for case %s (-want, +got) : %s", tc.name, d) + t.Fatalf("ConditionChecks did not resolve as expected for case %s %s", tc.name, diff.PrintWantGot(d)) } }) } @@ -1809,7 +1810,7 @@ func TestResolveConditionCheck_UseExistingConditionCheckName(t *testing.T) { }} if d := cmp.Diff(expectedConditionChecks, pipelineState[0].ResolvedConditionChecks, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{}, ResolvedConditionCheck{})); d != "" { - t.Fatalf("ConditionChecks did not resolve as expected (-want, +got): %s", d) + t.Fatalf("ConditionChecks did not resolve as expected %s", diff.PrintWantGot(d)) } } @@ -1889,7 +1890,7 @@ func TestResolvedConditionCheck_WithResources(t *testing.T) { ResolvedResources: tc.expected, }} if d := cmp.Diff(expectedConditionChecks, pipelineState[0].ResolvedConditionChecks, cmpopts.IgnoreUnexported(v1alpha1.TaskRunSpec{}, ResolvedConditionCheck{})); d != "" { - t.Fatalf("ConditionChecks did not resolve as expected (-want, +got): %s", d) + t.Fatalf("ConditionChecks did not resolve as expected %s", diff.PrintWantGot(d)) } } }) diff --git a/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go b/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go index 410564ebe2a..612556404a0 100644 --- a/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/resultrefresolution_test.go @@ -10,6 +10,7 @@ import ( tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" "knative.dev/pkg/apis" ) @@ -377,7 +378,7 @@ func TestResolveResultRefs(t *testing.T) { return } if d := cmp.Diff(tt.want, got); d != "" { - t.Fatalf("ResolveResultRef -want, +got: %v", d) + t.Fatalf("ResolveResultRef %s", diff.PrintWantGot(d)) } }) } @@ -492,7 +493,7 @@ func TestResolvePipelineResultRefs(t *testing.T) { return strings.Compare(got[i].FromTaskRun, got[j].FromTaskRun) < 0 }) if d := cmp.Diff(tt.want, got); d != "" { - t.Fatalf("ResolveResultRef -want, +got: %v", d) + t.Fatalf("ResolveResultRef %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/reconciler/taskrun/resources/apply_test.go b/pkg/reconciler/taskrun/resources/apply_test.go index a460d4773e1..c6706cf9f1a 100644 --- a/pkg/reconciler/taskrun/resources/apply_test.go +++ b/pkg/reconciler/taskrun/resources/apply_test.go @@ -26,6 +26,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/apis/resource" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -463,7 +464,7 @@ func TestApplyArrayParameters(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got := resources.ApplyParameters(tt.args.ts, tt.args.tr, tt.args.dp...) if d := cmp.Diff(got, tt.want); d != "" { - t.Errorf("ApplyParameters() got diff %s", d) + t.Errorf("ApplyParameters() got diff %s", diff.PrintWantGot(d)) } }) } @@ -524,7 +525,7 @@ func TestApplyParameters(t *testing.T) { }) got := resources.ApplyParameters(simpleTaskSpec, tr, dp...) if d := cmp.Diff(got, want); d != "" { - t.Errorf("ApplyParameters() got diff %s", d) + t.Errorf("ApplyParameters() got diff %s", diff.PrintWantGot(d)) } } @@ -596,7 +597,7 @@ func TestApplyResources(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got := resources.ApplyResources(tt.args.ts, tt.args.r, tt.args.rStr) if d := cmp.Diff(got, tt.want); d != "" { - t.Errorf("ApplyResources() -want, +got: %v", d) + t.Errorf("ApplyResources() %s", diff.PrintWantGot(d)) } }) } @@ -717,7 +718,7 @@ func TestApplyWorkspaces(t *testing.T) { }} got := resources.ApplyWorkspaces(ts, w, wb) if d := cmp.Diff(got, want); d != "" { - t.Errorf("TestApplyWorkspaces() got diff %s", d) + t.Errorf("TestApplyWorkspaces() got diff %s", diff.PrintWantGot(d)) } } @@ -753,7 +754,7 @@ func TestTaskResults(t *testing.T) { }) got := resources.ApplyTaskResults(ts) if d := cmp.Diff(got, want); d != "" { - t.Errorf("ApplyTaskResults() got diff %s", d) + t.Errorf("ApplyTaskResults() got diff %s", diff.PrintWantGot(d)) } } @@ -798,8 +799,8 @@ func TestApplyCredentialsPath(t *testing.T) { }} { t.Run(tc.description, func(t *testing.T) { got := resources.ApplyCredentialsPath(&tc.spec, tc.path) - if diff := cmp.Diff(&tc.want, got); diff != "" { - t.Errorf("(-want, +got): %s", diff) + if d := cmp.Diff(&tc.want, got); d != "" { + t.Errorf(diff.PrintWantGot(d)) } }) } diff --git a/pkg/reconciler/taskrun/resources/cloudevent/cloud_event_controller_test.go b/pkg/reconciler/taskrun/resources/cloudevent/cloud_event_controller_test.go index 4b1afd1c6aa..05f3bab7d10 100644 --- a/pkg/reconciler/taskrun/resources/cloudevent/cloud_event_controller_test.go +++ b/pkg/reconciler/taskrun/resources/cloudevent/cloud_event_controller_test.go @@ -23,6 +23,7 @@ import ( tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/logging" + "github.com/tektoncd/pipeline/test/diff" ) func TestCloudEventDeliveryFromTargets(t *testing.T) { @@ -65,8 +66,8 @@ func TestCloudEventDeliveryFromTargets(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { gotCloudEvents := cloudEventDeliveryFromTargets(tc.targets) - if diff := cmp.Diff(tc.wantCloudEvents, gotCloudEvents); diff != "" { - t.Errorf("Wrong Cloud Events (-want +got) = %s", diff) + if d := cmp.Diff(tc.wantCloudEvents, gotCloudEvents); d != "" { + t.Errorf("Wrong Cloud Events %s", diff.PrintWantGot(d)) } }) } @@ -120,8 +121,8 @@ func TestSendCloudEvents(t *testing.T) { t.Fatalf("Unexpected error sending cloud events: %v", err) } opts := GetCloudEventDeliveryCompareOptions() - if diff := cmp.Diff(tc.wantTaskRun.Status, tc.taskRun.Status, opts...); diff != "" { - t.Errorf("Wrong Cloud Events Status (-want +got) = %s", diff) + if d := cmp.Diff(tc.wantTaskRun.Status, tc.taskRun.Status, opts...); d != "" { + t.Errorf("Wrong Cloud Events Status %s", diff.PrintWantGot(d)) } }) } @@ -168,8 +169,8 @@ func TestSendCloudEventsErrors(t *testing.T) { t.Fatalf("Unexpected success sending cloud events: %v", err) } opts := GetCloudEventDeliveryCompareOptions() - if diff := cmp.Diff(tc.wantTaskRun.Status, tc.taskRun.Status, opts...); diff != "" { - t.Errorf("Wrong Cloud Events Status (-want +got) = %s", diff) + if d := cmp.Diff(tc.wantTaskRun.Status, tc.taskRun.Status, opts...); d != "" { + t.Errorf("Wrong Cloud Events Status %s", diff.PrintWantGot(d)) } }) } @@ -249,8 +250,8 @@ func TestInitializeCloudEvents(t *testing.T) { t.Run(tc.name, func(t *testing.T) { InitializeCloudEvents(tc.taskRun, tc.pipelineResources) opts := GetCloudEventDeliveryCompareOptions() - if diff := cmp.Diff(tc.wantTaskRun.Status, tc.taskRun.Status, opts...); diff != "" { - t.Errorf("Wrong Cloud Events Status (-want +got) = %s", diff) + if d := cmp.Diff(tc.wantTaskRun.Status, tc.taskRun.Status, opts...); d != "" { + t.Errorf("Wrong Cloud Events Status %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/reconciler/taskrun/resources/cloudevent/cloudevent_test.go b/pkg/reconciler/taskrun/resources/cloudevent/cloudevent_test.go index 17d122bd469..7920f4299a7 100644 --- a/pkg/reconciler/taskrun/resources/cloudevent/cloudevent_test.go +++ b/pkg/reconciler/taskrun/resources/cloudevent/cloudevent_test.go @@ -21,6 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -78,19 +79,19 @@ func TestEventForTaskRun(t *testing.T) { t.Fatalf("I did not expect an error but I got %s", err) } else { wantSubject := taskRunName - if diff := cmp.Diff(wantSubject, got.Subject()); diff != "" { - t.Errorf("Wrong Event ID (-want +got) = %s", diff) + if d := cmp.Diff(wantSubject, got.Subject()); d != "" { + t.Errorf("Wrong Event ID %s", diff.PrintWantGot(d)) } - if diff := cmp.Diff(string(c.wantEventType), got.Type()); diff != "" { - t.Errorf("Wrong Event Type (-want +got) = %s", diff) + if d := cmp.Diff(string(c.wantEventType), got.Type()); d != "" { + t.Errorf("Wrong Event Type %s", diff.PrintWantGot(d)) } wantData := NewTektonCloudEventData(c.taskRun) gotData := TektonCloudEventData{} if err := got.DataAs(&gotData); err != nil { t.Errorf("Unexpected error from DataAsl; %s", err) } - if diff := cmp.Diff(wantData, gotData); diff != "" { - t.Errorf("Wrong Event data (-want +got) = %s", diff) + if d := cmp.Diff(wantData, gotData); d != "" { + t.Errorf("Wrong Event data %s", diff.PrintWantGot(d)) } if err := got.Validate(); err != nil { diff --git a/pkg/reconciler/taskrun/resources/image_exporter_test.go b/pkg/reconciler/taskrun/resources/image_exporter_test.go index 5ea20c61593..ab609f4a4ce 100644 --- a/pkg/reconciler/taskrun/resources/image_exporter_test.go +++ b/pkg/reconciler/taskrun/resources/image_exporter_test.go @@ -22,6 +22,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -193,7 +194,7 @@ func TestAddOutputImageDigestExporter(t *testing.T) { } if d := cmp.Diff(c.task.Spec.Steps, c.wantSteps); d != "" { - t.Fatalf("post build steps mismatch: %s", d) + t.Fatalf("post build steps mismatch %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/reconciler/taskrun/resources/input_resource_test.go b/pkg/reconciler/taskrun/resources/input_resource_test.go index 36cbb8697b9..14f04b14a5b 100644 --- a/pkg/reconciler/taskrun/resources/input_resource_test.go +++ b/pkg/reconciler/taskrun/resources/input_resource_test.go @@ -26,6 +26,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/resource" "github.com/tektoncd/pipeline/pkg/artifacts" "github.com/tektoncd/pipeline/pkg/logging" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -962,7 +963,7 @@ gsutil cp gs://fake-bucket/rules.zip /workspace/gcs-dir } if got != nil { if d := cmp.Diff(got, c.want); d != "" { - t.Errorf("Diff:\n%s", d) + t.Errorf("Diff:\n%s", diff.PrintWantGot(d)) } } }) @@ -1203,7 +1204,7 @@ gsutil rsync -d -r gs://fake-bucket/rules.zip /workspace/gcs-input-resource t.Errorf("Test: %q; AddInputResource() error = %v, WantErr %v", c.desc, err, c.wantErr) } if d := cmp.Diff(c.want, got); d != "" { - t.Errorf("Didn't get expected Task spec (-want, +got): %s", d) + t.Errorf("Didn't get expected Task spec %s", diff.PrintWantGot(d)) } }) } @@ -1445,7 +1446,7 @@ func TestAddStepsToTaskWithBucketFromConfigMap(t *testing.T) { t.Errorf("Test: %q; AddInputResource() error = %v", c.desc, err) } if d := cmp.Diff(c.want, got); d != "" { - t.Errorf("Didn't get expected TaskSpec (-want, +got): %s", d) + t.Errorf("Didn't get expected TaskSpec %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/reconciler/taskrun/resources/output_resource_test.go b/pkg/reconciler/taskrun/resources/output_resource_test.go index 9bc00820f49..6f2f590e444 100644 --- a/pkg/reconciler/taskrun/resources/output_resource_test.go +++ b/pkg/reconciler/taskrun/resources/output_resource_test.go @@ -25,6 +25,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/resource" "github.com/tektoncd/pipeline/pkg/artifacts" "github.com/tektoncd/pipeline/pkg/logging" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -947,10 +948,10 @@ func TestValidOutputResources(t *testing.T) { if got != nil { if d := cmp.Diff(c.wantSteps, got.Steps); d != "" { - t.Fatalf("post build steps mismatch (-want, +got): %s", d) + t.Fatalf("post build steps mismatch %s", diff.PrintWantGot(d)) } if d := cmp.Diff(c.wantVolumes, got.Volumes); d != "" { - t.Fatalf("post build steps volumes mismatch (-want, +got): %s", d) + t.Fatalf("post build steps volumes mismatch %s", diff.PrintWantGot(d)) } } }) @@ -1147,7 +1148,7 @@ func TestValidOutputResourcesWithBucketStorage(t *testing.T) { } if got != nil { if d := cmp.Diff(c.wantSteps, got.Steps); d != "" { - t.Fatalf("post build steps mismatch (-want, got): %s", d) + t.Fatalf("post build steps mismatch %s", diff.PrintWantGot(d)) } } }) @@ -1779,10 +1780,10 @@ func TestInputOutputBucketResources(t *testing.T) { if got != nil { if d := cmp.Diff(c.wantSteps, got.Steps); d != "" { - t.Fatalf("post build steps mismatch (-want, +got): %s", d) + t.Fatalf("post build steps mismatch %s", diff.PrintWantGot(d)) } if d := cmp.Diff(c.wantVolumes, got.Volumes); d != "" { - t.Fatalf("post build steps volumes mismatch (-want, +got): %s", d) + t.Fatalf("post build steps volumes mismatch %s", diff.PrintWantGot(d)) } } }) diff --git a/pkg/reconciler/taskrun/resources/taskref_test.go b/pkg/reconciler/taskrun/resources/taskref_test.go index 07468d38d79..3cce137adb4 100644 --- a/pkg/reconciler/taskrun/resources/taskref_test.go +++ b/pkg/reconciler/taskrun/resources/taskref_test.go @@ -26,6 +26,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/fake" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" + "github.com/tektoncd/pipeline/test/diff" ) func TestTaskRef(t *testing.T) { @@ -89,8 +90,8 @@ func TestTaskRef(t *testing.T) { t.Fatalf("Received unexpected error ( %#v )", err) } - if diff := cmp.Diff(task, tc.expected); tc.expected != nil && diff != "" { - t.Error(diff) + if d := cmp.Diff(task, tc.expected); tc.expected != nil && d != "" { + t.Error(diff.PrintWantGot(d)) } }) } diff --git a/pkg/reconciler/taskrun/resources/volume_test.go b/pkg/reconciler/taskrun/resources/volume_test.go index 124499f98cd..aa5e65961d0 100644 --- a/pkg/reconciler/taskrun/resources/volume_test.go +++ b/pkg/reconciler/taskrun/resources/volume_test.go @@ -21,6 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" + "github.com/tektoncd/pipeline/test/diff" corev1 "k8s.io/api/core/v1" ) @@ -32,6 +33,6 @@ func TestGetPVCVolume(t *testing.T) { }, } if d := cmp.Diff(expectedVolume, resources.GetPVCVolume("test-pvc")); d != "" { - t.Fatalf("PVC volume mismatch: %s", d) + t.Fatalf("PVC volume mismatch: %s", diff.PrintWantGot(d)) } } diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 14f017c3eee..92f8461e8ff 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -36,6 +36,7 @@ import ( "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources/cloudevent" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" "github.com/tektoncd/pipeline/pkg/system" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" test "github.com/tektoncd/pipeline/test/v1alpha1" corev1 "k8s.io/api/core/v1" @@ -465,11 +466,11 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) { } if d := cmp.Diff(tc.wantPod.ObjectMeta, pod.ObjectMeta, ignoreRandomPodNameSuffix); d != "" { - t.Errorf("Pod metadata doesn't match (-want, +got): %s", d) + t.Errorf("Pod metadata doesn't match %s", diff.PrintWantGot(d)) } if d := cmp.Diff(tc.wantPod.Spec, pod.Spec, resourceQuantityCmp); d != "" { - t.Errorf("Pod spec doesn't match, (-want, +got): %s", d) + t.Errorf("Pod spec doesn't match, %s", diff.PrintWantGot(d)) } if len(clients.Kube.Actions()) == 0 { t.Fatalf("Expected actions to be logged in the kubeclient, got none") @@ -1086,12 +1087,12 @@ func TestReconcile(t *testing.T) { } if d := cmp.Diff(tc.wantPod.ObjectMeta, pod.ObjectMeta, ignoreRandomPodNameSuffix); d != "" { - t.Errorf("Pod metadata doesn't match (-want, +got): %s", d) + t.Errorf("Pod metadata doesn't match %s", diff.PrintWantGot(d)) } pod.Name = tc.wantPod.Name // Ignore pod name differences, the pod name is generated and tested in pod_test.go if d := cmp.Diff(tc.wantPod.Spec, pod.Spec, resourceQuantityCmp); d != "" { - t.Errorf("Pod spec doesn't match (-want, +got): %s", d) + t.Errorf("Pod spec doesn't match %s", diff.PrintWantGot(d)) } if len(clients.Kube.Actions()) == 0 { t.Fatalf("Expected actions to be logged in the kubeclient, got none") @@ -1198,7 +1199,7 @@ func verifyTaskRunStatusStep(t *testing.T, taskRun *v1alpha1.TaskRun) { // Add a nop in the end. This may be removed in future. expectedStepOrder = append(expectedStepOrder, "nop") if d := cmp.Diff(expectedStepOrder, actualStepOrder); d != "" { - t.Errorf("The status steps in TaksRun doesn't match the spec steps in Task (-want, +got): %s", d) + t.Errorf("The status steps in TaksRun doesn't match the spec steps in Task %s", diff.PrintWantGot(d)) } } @@ -1396,7 +1397,7 @@ func TestReconcilePodUpdateStatus(t *testing.T) { Reason: "Running", Message: "Not all Steps in the Task have finished executing", }, newTr.Status.GetCondition(apis.ConditionSucceeded), ignoreLastTransitionTime); d != "" { - t.Fatalf("Did not get expected condition (-want, +got): %v", d) + t.Fatalf("Did not get expected condition %s", diff.PrintWantGot(d)) } // update pod status and trigger reconcile : build is completed @@ -1420,7 +1421,7 @@ func TestReconcilePodUpdateStatus(t *testing.T) { Reason: podconvert.ReasonSucceeded, Message: "All Steps have completed executing", }, newTr.Status.GetCondition(apis.ConditionSucceeded), ignoreLastTransitionTime); d != "" { - t.Errorf("Did not get expected condition (-want, +got): %v", d) + t.Errorf("Did not get expected condition %s", diff.PrintWantGot(d)) } wantEvents := []string{ @@ -1464,7 +1465,7 @@ func TestReconcileOnCompletedTaskRun(t *testing.T) { t.Fatalf("Expected completed TaskRun %s to exist but instead got error when getting it: %v", taskRun.Name, err) } if d := cmp.Diff(taskSt, newTr.Status.GetCondition(apis.ConditionSucceeded), ignoreLastTransitionTime); d != "" { - t.Fatalf("Did not get expected condition (-want, +got): %v", d) + t.Fatalf("Did not get expected condition %s", diff.PrintWantGot(d)) } } @@ -1505,7 +1506,7 @@ func TestReconcileOnCancelledTaskRun(t *testing.T) { Message: `TaskRun "test-taskrun-run-cancelled" was cancelled`, } if d := cmp.Diff(expectedStatus, newTr.Status.GetCondition(apis.ConditionSucceeded), ignoreLastTransitionTime); d != "" { - t.Fatalf("Did not get expected condition (-want, +got): %v", d) + t.Fatalf("Did not get expected condition %s", diff.PrintWantGot(d)) } wantEvents := []string{ @@ -1611,7 +1612,7 @@ func TestReconcileTimeouts(t *testing.T) { } condition := newTr.Status.GetCondition(apis.ConditionSucceeded) if d := cmp.Diff(tc.expectedStatus, condition, ignoreLastTransitionTime); d != "" { - t.Fatalf("Did not get expected condition (-want, +got): %v", d) + t.Fatalf("Did not get expected condition %s", diff.PrintWantGot(d)) } err = checkEvents(fr, tc.taskRun.Name, tc.wantEvents) if !(err == nil) { @@ -1859,8 +1860,8 @@ func TestReconcileCloudEvents(t *testing.T) { } opts := cloudevent.GetCloudEventDeliveryCompareOptions() t.Log(tr.Status.CloudEvents) - if diff := cmp.Diff(tc.wantCloudEvents, tr.Status.CloudEvents, opts...); diff != "" { - t.Errorf("Unexpected status of cloud events (-want +got) = %s", diff) + if d := cmp.Diff(tc.wantCloudEvents, tr.Status.CloudEvents, opts...); d != "" { + t.Errorf("Unexpected status of cloud events %s", diff.PrintWantGot(d)) } }) } @@ -1900,7 +1901,7 @@ func TestUpdateTaskRunResourceResult(t *testing.T) { t.Errorf("updateTaskRunResourceResult: %s", err) } if d := cmp.Diff(c.want, tr.Status.ResourcesResult); d != "" { - t.Errorf("updateTaskRunResourceResult (-want, +got): %s", d) + t.Errorf("updateTaskRunResourceResult %s", diff.PrintWantGot(d)) } }) } @@ -1946,10 +1947,10 @@ func TestUpdateTaskRunResult(t *testing.T) { t.Errorf("updateTaskRunResourceResult: %s", err) } if d := cmp.Diff(c.wantResults, tr.Status.TaskRunResults); d != "" { - t.Errorf("updateTaskRunResourceResult TaskRunResults (-want, +got): %s", d) + t.Errorf("updateTaskRunResourceResult TaskRunResults %s", diff.PrintWantGot(d)) } if d := cmp.Diff(c.want, tr.Status.ResourcesResult); d != "" { - t.Errorf("updateTaskRunResourceResult ResourcesResult (-want, +got): %s", d) + t.Errorf("updateTaskRunResourceResult ResourcesResult %s", diff.PrintWantGot(d)) } }) } @@ -1994,10 +1995,10 @@ func TestUpdateTaskRunResult2(t *testing.T) { t.Errorf("updateTaskRunResourceResult: %s", err) } if d := cmp.Diff(c.wantResults, tr.Status.TaskRunResults); d != "" { - t.Errorf("updateTaskRunResourceResult (-want, +got): %s", d) + t.Errorf("updateTaskRunResourceResult %s", diff.PrintWantGot(d)) } if d := cmp.Diff(c.want, tr.Status.ResourcesResult); d != "" { - t.Errorf("updateTaskRunResourceResult (-want, +got): %s", d) + t.Errorf("updateTaskRunResourceResult %s", diff.PrintWantGot(d)) } }) } @@ -2039,7 +2040,7 @@ func TestUpdateTaskRunResultTwoResults(t *testing.T) { t.Errorf("updateTaskRunResourceResult: %s", err) } if d := cmp.Diff(c.want, tr.Status.TaskRunResults); d != "" { - t.Errorf("updateTaskRunResourceResult (-want, +got): %s", d) + t.Errorf("updateTaskRunResourceResult %s", diff.PrintWantGot(d)) } }) } @@ -2075,10 +2076,10 @@ func TestUpdateTaskRunResultWhenTaskFailed(t *testing.T) { t.Run(c.desc, func(t *testing.T) { names.TestingSeed() if d := cmp.Diff(c.want, c.taskRunStatus.ResourcesResult); d != "" { - t.Errorf("updateTaskRunResourceResult resources (-want, +got): %s", d) + t.Errorf("updateTaskRunResourceResult resources %s", diff.PrintWantGot(d)) } if d := cmp.Diff(c.wantResults, c.taskRunStatus.TaskRunResults); d != "" { - t.Errorf("updateTaskRunResourceResult results (-want, +got): %s", d) + t.Errorf("updateTaskRunResourceResult results %s", diff.PrintWantGot(d)) } }) } @@ -2115,7 +2116,7 @@ func TestUpdateTaskRunResourceResult_Errors(t *testing.T) { t.Error("Expected error, got nil") } if d := cmp.Diff(c.want, c.taskRunStatus.ResourcesResult); d != "" { - t.Errorf("updateTaskRunResourceResult (-want, +got): %s", d) + t.Errorf("updateTaskRunResourceResult %s", diff.PrintWantGot(d)) } }) } @@ -2165,7 +2166,7 @@ func TestReconcile_Single_SidecarState(t *testing.T) { } if c := cmp.Diff(expected, getTaskRun.Status.Sidecars[0]); c != "" { - t.Errorf("TestReconcile_Single_SidecarState (-want, +got): %s", c) + t.Errorf("TestReconcile_Single_SidecarState %s", diff.PrintWantGot(c)) } } @@ -2233,7 +2234,7 @@ func TestReconcile_Multiple_SidecarStates(t *testing.T) { for i, sc := range getTaskRun.Status.Sidecars { if c := cmp.Diff(expected[i], sc); c != "" { - t.Errorf("TestReconcile_Multiple_SidecarStates sidecar%d (-want, +got): %s", i+1, c) + t.Errorf("TestReconcile_Multiple_SidecarStates sidecar%d %s", i+1, diff.PrintWantGot(c)) } } } @@ -2484,7 +2485,7 @@ func TestFailTaskRun(t *testing.T) { t.Fatal(err) } if d := cmp.Diff(tc.taskRun.Status.GetCondition(apis.ConditionSucceeded), &tc.expectedStatus, ignoreLastTransitionTime); d != "" { - t.Fatalf("-want, +got: %v", d) + t.Fatalf(diff.PrintWantGot(d)) } }) } @@ -2506,7 +2507,7 @@ func Test_storeTaskSpec(t *testing.T) { t.Errorf("storeTaskSpec() error = %v", err) } if d := cmp.Diff(tr.Status.TaskSpec, want); d != "" { - t.Fatalf("-want, +got: %v", d) + t.Fatalf(diff.PrintWantGot(d)) } ts.Description = "new-task" @@ -2515,6 +2516,6 @@ func Test_storeTaskSpec(t *testing.T) { t.Errorf("storeTaskSpec() error = %v", err) } if d := cmp.Diff(tr.Status.TaskSpec, want); d != "" { - t.Fatalf("-want, +got: %v", d) + t.Fatalf(diff.PrintWantGot(d)) } } diff --git a/pkg/remote/oci/resolver_test.go b/pkg/remote/oci/resolver_test.go index 6e001122f2d..95d7284d308 100644 --- a/pkg/remote/oci/resolver_test.go +++ b/pkg/remote/oci/resolver_test.go @@ -30,6 +30,7 @@ import ( tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1" "github.com/tektoncd/pipeline/pkg/remote" "github.com/tektoncd/pipeline/test" + "github.com/tektoncd/pipeline/test/diff" "k8s.io/apimachinery/pkg/runtime" ) @@ -94,8 +95,8 @@ func TestOCIResolver(t *testing.T) { // The contents of the image are in a specific order so we can expect this iteration to be consistent. for idx, actual := range listActual { - if diff := cmp.Diff(actual, tc.listExpected[idx]); diff != "" { - t.Error(diff) + if d := cmp.Diff(actual, tc.listExpected[idx]); d != "" { + t.Error(diff.PrintWantGot(d)) } } @@ -105,8 +106,8 @@ func TestOCIResolver(t *testing.T) { t.Fatalf("could not retrieve object from image: %#v", err) } - if diff := cmp.Diff(actual, obj); diff != "" { - t.Error(diff) + if d := cmp.Diff(actual, obj); d != "" { + t.Error(diff.PrintWantGot(d)) } } }) diff --git a/pkg/substitution/substitution_test.go b/pkg/substitution/substitution_test.go index 7e8f489d885..3b61e0e73e2 100644 --- a/pkg/substitution/substitution_test.go +++ b/pkg/substitution/substitution_test.go @@ -22,6 +22,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/substitution" + "github.com/tektoncd/pipeline/test/diff" "knative.dev/pkg/apis" ) @@ -109,7 +110,7 @@ func TestValidateVariables(t *testing.T) { got := substitution.ValidateVariable("somefield", tc.args.input, tc.args.prefix, tc.args.locationName, tc.args.path, tc.args.vars) if d := cmp.Diff(got, tc.expectedError, cmp.AllowUnexported(apis.FieldError{})); d != "" { - t.Errorf("ValidateVariable() error did not match expected error %s", d) + t.Errorf("ValidateVariable() error did not match expected error %s", diff.PrintWantGot(d)) } }) } @@ -170,7 +171,7 @@ func TestApplyReplacements(t *testing.T) { t.Run(tt.name, func(t *testing.T) { actualOutput := substitution.ApplyReplacements(tt.args.input, tt.args.replacements) if d := cmp.Diff(actualOutput, tt.expectedOutput); d != "" { - t.Errorf("ApplyReplacements() output did not match expected value %s", d) + t.Errorf("ApplyReplacements() output did not match expected value %s", diff.PrintWantGot(d)) } }) } @@ -230,7 +231,7 @@ func TestApplyArrayReplacements(t *testing.T) { t.Run(tc.name, func(t *testing.T) { actualOutput := substitution.ApplyArrayReplacements(tc.args.input, tc.args.stringReplacements, tc.args.arrayReplacements) if d := cmp.Diff(actualOutput, tc.expectedOutput); d != "" { - t.Errorf("ApplyArrayReplacements() output did not match expected value %s", d) + t.Errorf("ApplyArrayReplacements() output did not match expected value %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/termination/parse_test.go b/pkg/termination/parse_test.go index 57169f21cbc..5e577841f36 100644 --- a/pkg/termination/parse_test.go +++ b/pkg/termination/parse_test.go @@ -20,6 +20,7 @@ import ( "github.com/google/go-cmp/cmp" v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" + "github.com/tektoncd/pipeline/test/diff" ) func TestParseMessage(t *testing.T) { @@ -73,7 +74,7 @@ func TestParseMessage(t *testing.T) { t.Fatalf("ParseMessage: %v", err) } if d := cmp.Diff(c.want, got); d != "" { - t.Fatalf("ParseMessage(-want,+got): %s", d) + t.Fatalf("ParseMessage %s", diff.PrintWantGot(d)) } }) } diff --git a/pkg/termination/write_test.go b/pkg/termination/write_test.go index c6165fc272e..a4c83abe09b 100644 --- a/pkg/termination/write_test.go +++ b/pkg/termination/write_test.go @@ -24,6 +24,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/logging" + "github.com/tektoncd/pipeline/test/diff" ) func TestExistingFile(t *testing.T) { @@ -61,7 +62,7 @@ func TestExistingFile(t *testing.T) { } else { want := `[{"key":"key1","value":"hello","resourceRef":{}},{"key":"key2","value":"world","resourceRef":{}}]` if d := cmp.Diff(want, string(fileContents)); d != "" { - t.Fatalf("Diff(-want, got): %s", d) + t.Fatalf("Diff %s", diff.PrintWantGot(d)) } } } diff --git a/pkg/workspace/apply_test.go b/pkg/workspace/apply_test.go index 88204440925..a5d281f0ebd 100644 --- a/pkg/workspace/apply_test.go +++ b/pkg/workspace/apply_test.go @@ -7,6 +7,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/workspace" + "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" ) @@ -187,7 +188,7 @@ func TestGetVolumes(t *testing.T) { t.Run(tc.name, func(t *testing.T) { v := workspace.GetVolumes(tc.workspaces) if d := cmp.Diff(tc.expectedVolumes, v); d != "" { - t.Errorf("Didn't get expected volumes from bindings (-want, +got): %s", d) + t.Errorf("Didn't get expected volumes from bindings %s", diff.PrintWantGot(d)) } }) } @@ -516,7 +517,7 @@ func TestApply(t *testing.T) { t.Fatalf("Did not expect error but got %v", err) } if d := cmp.Diff(tc.expectedTaskSpec, *ts); d != "" { - t.Errorf("Didn't get expected TaskSpec modifications (-want, +got): %s", d) + t.Errorf("Didn't get expected TaskSpec modifications %s", diff.PrintWantGot(d)) } }) } diff --git a/test/diff/print.go b/test/diff/print.go new file mode 100644 index 00000000000..f38803c348a --- /dev/null +++ b/test/diff/print.go @@ -0,0 +1,27 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package diff + +import "fmt" + +// PrintWantGot takes a diff string generated by cmp.Diff and returns it +// in a consistent format for reuse across all of our tests. This +// func assumes that the order of arguments passed to cmp.Diff was +// (want, got) or, in other words, the expectedResult then the actualResult. +func PrintWantGot(diff string) string { + return fmt.Sprintf("(-want, +got): %s", diff) +}