Skip to content

Commit 8bac7f3

Browse files
Scotttekton-robot
authored andcommitted
Replace varying (-want, +got) test messages with diff.PrintWantGot()
In the previous commit a new func for printing consistent diff messages was added as a test helper. This commit updates all locations which use cmp.Diff to also use diff.PrintWantGot when displaying the diff.
1 parent a3ff201 commit 8bac7f3

File tree

79 files changed

+398
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+398
-319
lines changed

pkg/apis/config/default_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/google/go-cmp/cmp"
2323
"github.com/tektoncd/pipeline/pkg/apis/pipeline/pod"
2424
test "github.com/tektoncd/pipeline/pkg/reconciler/testing"
25+
"github.com/tektoncd/pipeline/test/diff"
2526
)
2627

2728
func TestNewDefaultsFromConfigMap(t *testing.T) {
@@ -186,7 +187,7 @@ func verifyConfigFileWithExpectedConfig(t *testing.T, fileName string, expectedC
186187
cm := test.ConfigMapFromTestFile(t, fileName)
187188
if Defaults, err := NewDefaultsFromConfigMap(cm); err == nil {
188189
if d := cmp.Diff(Defaults, expectedConfig); d != "" {
189-
t.Errorf("Diff:\n%s", d)
190+
t.Errorf("Diff:\n%s", diff.PrintWantGot(d))
190191
}
191192
} else {
192193
t.Errorf("NewDefaultsFromConfigMap(actual) = %v", err)

pkg/apis/config/store_test.go

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

2323
"github.com/google/go-cmp/cmp"
2424
test "github.com/tektoncd/pipeline/pkg/reconciler/testing"
25+
"github.com/tektoncd/pipeline/test/diff"
2526
logtesting "knative.dev/pkg/logging/testing"
2627
)
2728

@@ -33,7 +34,7 @@ func TestStoreLoadWithContext(t *testing.T) {
3334
config := FromContext(store.ToContext(context.Background()))
3435

3536
expected, _ := NewDefaultsFromConfigMap(defaultConfig)
36-
if diff := cmp.Diff(config.Defaults, expected); diff != "" {
37-
t.Errorf("Unexpected default config (-want, +got): %v", diff)
37+
if d := cmp.Diff(config.Defaults, expected); d != "" {
38+
t.Errorf("Unexpected default config %s", diff.PrintWantGot(d))
3839
}
3940
}

pkg/apis/pipeline/v1alpha1/cluster_task_conversion_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/google/go-cmp/cmp"
2424
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
2525
resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
26+
"github.com/tektoncd/pipeline/test/diff"
2627
corev1 "k8s.io/api/core/v1"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
"knative.dev/pkg/apis"
@@ -175,8 +176,8 @@ func TestClusterTaskConversion(t *testing.T) {
175176
t.Errorf("ConvertFrom() = %v", err)
176177
}
177178
t.Logf("ConvertFrom() = %#v", got)
178-
if diff := cmp.Diff(test.in, got); diff != "" {
179-
t.Errorf("roundtrip (-want, +got) = %v", diff)
179+
if d := cmp.Diff(test.in, got); d != "" {
180+
t.Errorf("roundtrip %s", diff.PrintWantGot(d))
180181
}
181182
})
182183
}
@@ -312,8 +313,8 @@ func TestClusterTaskConversionFromDeprecated(t *testing.T) {
312313
t.Errorf("ConvertFrom() = %v", err)
313314
}
314315
t.Logf("ConvertFrom() = %#v", got)
315-
if diff := cmp.Diff(test.want, got); diff != "" {
316-
t.Errorf("roundtrip (-want, +got) = %v", diff)
316+
if d := cmp.Diff(test.want, got); d != "" {
317+
t.Errorf("roundtrip %s", diff.PrintWantGot(d))
317318
}
318319
})
319320
}

pkg/apis/pipeline/v1alpha1/condition_defaults_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/google/go-cmp/cmp"
2424
tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1"
2525
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
26+
"github.com/tektoncd/pipeline/test/diff"
2627
)
2728

2829
func TestConditionSpec_SetDefaults(t *testing.T) {
@@ -90,8 +91,8 @@ func TestConditionSpec_SetDefaults(t *testing.T) {
9091
t.Run(tc.name, func(t *testing.T) {
9192
ctx := context.Background()
9293
tc.input.SetDefaults(ctx)
93-
if diff := cmp.Diff(tc.output, tc.input); diff != "" {
94-
t.Errorf("Mismatch of PipelineRunSpec: %s", diff)
94+
if d := cmp.Diff(tc.output, tc.input); d != "" {
95+
t.Errorf("Mismatch of PipelineRunSpec: %s", diff.PrintWantGot(d))
9596
}
9697
})
9798
}

pkg/apis/pipeline/v1alpha1/condition_validation_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/google/go-cmp/cmp/cmpopts"
2525
tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1"
2626
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
27+
"github.com/tektoncd/pipeline/test/diff"
2728
"knative.dev/pkg/apis"
2829
)
2930

@@ -92,7 +93,7 @@ func TestCondition_Invalidate(t *testing.T) {
9293
t.Fatalf("Expected an Error, got nothing for %v", tc)
9394
}
9495
if d := cmp.Diff(tc.expectedError, *err, cmpopts.IgnoreUnexported(apis.FieldError{})); d != "" {
95-
t.Errorf("Condition.Validate() errors diff -want, +got: %v", d)
96+
t.Errorf("Condition.Validate() errors diff %s", diff.PrintWantGot(d))
9697
}
9798
})
9899
}

pkg/apis/pipeline/v1alpha1/container_replacements_test.go

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

2222
"github.com/google/go-cmp/cmp"
2323
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
24+
"github.com/tektoncd/pipeline/test/diff"
2425
corev1 "k8s.io/api/core/v1"
2526
)
2627

@@ -121,7 +122,7 @@ func TestApplyContainerReplacements(t *testing.T) {
121122

122123
v1alpha1.ApplyContainerReplacements(&s, replacements, arrayReplacements)
123124
if d := cmp.Diff(s, expected); d != "" {
124-
t.Errorf("Container replacements failed: %s", d)
125+
t.Errorf("Container replacements failed: %s", diff.PrintWantGot(d))
125126
}
126127
}
127128

@@ -142,6 +143,6 @@ func TestApplyContainerReplacements_NotDefined(t *testing.T) {
142143
}
143144
v1alpha1.ApplyContainerReplacements(&s, replacements, arrayReplacements)
144145
if d := cmp.Diff(s, expected); d != "" {
145-
t.Errorf("Unexpected container replacement: %s", d)
146+
t.Errorf("Unexpected container replacement: %s", diff.PrintWantGot(d))
146147
}
147148
}

pkg/apis/pipeline/v1alpha1/merge_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"testing"
2121

2222
"github.com/google/go-cmp/cmp"
23+
"github.com/tektoncd/pipeline/test/diff"
2324
corev1 "k8s.io/api/core/v1"
2425
"k8s.io/apimachinery/pkg/api/resource"
2526
)
@@ -130,7 +131,7 @@ func TestMergeStepsWithStepTemplate(t *testing.T) {
130131
}
131132

132133
if d := cmp.Diff(tc.expected, result, resourceQuantityCmp); d != "" {
133-
t.Errorf("merged steps don't match, diff: %s", d)
134+
t.Errorf("merged steps don't match, diff: %s", diff.PrintWantGot(d))
134135
}
135136
})
136137
}

pkg/apis/pipeline/v1alpha1/param_types_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/google/go-cmp/cmp"
2626
tb "github.com/tektoncd/pipeline/internal/builder/v1alpha1"
2727
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
28+
"github.com/tektoncd/pipeline/test/diff"
2829
)
2930

3031
func TestParamSpec_SetDefaults(t *testing.T) {
@@ -72,7 +73,7 @@ func TestParamSpec_SetDefaults(t *testing.T) {
7273
ctx := context.Background()
7374
tc.before.SetDefaults(ctx)
7475
if d := cmp.Diff(tc.before, tc.defaultsApplied); d != "" {
75-
t.Errorf("ParamSpec.SetDefaults/%s (-want, +got) = %v", tc.name, d)
76+
t.Errorf("ParamSpec.SetDefaults/%s %s", tc.name, diff.PrintWantGot(d))
7677
}
7778
})
7879
}
@@ -133,7 +134,7 @@ func TestArrayOrString_ApplyReplacements(t *testing.T) {
133134
t.Run(tt.name, func(t *testing.T) {
134135
tt.args.input.ApplyReplacements(tt.args.stringReplacements, tt.args.arrayReplacements)
135136
if d := cmp.Diff(tt.expectedOutput, tt.args.input); d != "" {
136-
t.Errorf("ApplyReplacements() output did not match expected value %s", d)
137+
t.Errorf("ApplyReplacements() output did not match expected value %s", diff.PrintWantGot(d))
137138
}
138139
})
139140
}

pkg/apis/pipeline/v1alpha1/pipeline_conversion_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/google/go-cmp/cmp"
2525
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
2626
resource "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
27+
"github.com/tektoncd/pipeline/test/diff"
2728
corev1 "k8s.io/api/core/v1"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"knative.dev/pkg/apis"
@@ -170,8 +171,8 @@ func TestPipelineConversion(t *testing.T) {
170171
t.Errorf("ConvertFrom() = %v", err)
171172
}
172173
t.Logf("ConvertFrom() = %#v", got)
173-
if diff := cmp.Diff(test.in, got); diff != "" {
174-
t.Errorf("roundtrip (-want, +got) = %v", diff)
174+
if d := cmp.Diff(test.in, got); d != "" {
175+
t.Errorf("roundtrip %s", diff.PrintWantGot(d))
175176
}
176177
})
177178
}

pkg/apis/pipeline/v1alpha1/pipelinerun_conversion_test.go

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

2424
"github.com/google/go-cmp/cmp"
2525
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
26+
"github.com/tektoncd/pipeline/test/diff"
2627
corev1 "k8s.io/api/core/v1"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
"knative.dev/pkg/apis"
@@ -172,8 +173,8 @@ func TestPipelineRunConversion(t *testing.T) {
172173
t.Errorf("ConvertFrom() = %v", err)
173174
}
174175
t.Logf("ConvertFrom() = %#v", got)
175-
if diff := cmp.Diff(test.in, got); diff != "" {
176-
t.Errorf("roundtrip (-want, +got) = %v", diff)
176+
if d := cmp.Diff(test.in, got); d != "" {
177+
t.Errorf("roundtrip %s", diff.PrintWantGot(d))
177178
}
178179
})
179180
}

0 commit comments

Comments
 (0)