From 81b5c40e77436b141f7e3a8cc167bc07e377eaf1 Mon Sep 17 00:00:00 2001 From: shuheiktgw Date: Thu, 22 Oct 2020 12:06:41 +0900 Subject: [PATCH] Fix unit test failures with go 1.15 --- pkg/cmd/clustertask/start_test.go | 11 +++++++++-- pkg/cmd/pipeline/start_test.go | 11 +++++++++-- pkg/cmd/task/start_test.go | 11 +++++++++-- pkg/formatted/color_test.go | 4 +++- pkg/test/helpers.go | 17 +++++++++++++++++ 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/clustertask/start_test.go b/pkg/cmd/clustertask/start_test.go index a4766ea44..6d211c851 100644 --- a/pkg/cmd/clustertask/start_test.go +++ b/pkg/cmd/clustertask/start_test.go @@ -1248,6 +1248,7 @@ func Test_ClusterTask_Start_v1beta1(t *testing.T) { input pipelinev1beta1test.Clients inputStream io.Reader wantError bool + hasPrefix bool want string goldenFile bool }{ @@ -1479,7 +1480,8 @@ func Test_ClusterTask_Start_v1beta1(t *testing.T) { input: seeds[4].pipelineClient, inputStream: nil, wantError: true, - want: "time: unknown unit d in duration 5d", + hasPrefix: true, + want: `time: unknown unit`, }, { name: "Dry run with PodTemplate", @@ -1623,7 +1625,12 @@ func Test_ClusterTask_Start_v1beta1(t *testing.T) { if err == nil { t.Errorf("Error expected here") } - test.AssertOutput(t, tp.want, err.Error()) + + if tp.hasPrefix { + test.AssertOutputPrefix(t, tp.want, err.Error()) + } else { + test.AssertOutput(t, tp.want, err.Error()) + } } else { if err != nil { t.Errorf("Unexpected error") diff --git a/pkg/cmd/pipeline/start_test.go b/pkg/cmd/pipeline/start_test.go index dca122f45..a30519279 100644 --- a/pkg/cmd/pipeline/start_test.go +++ b/pkg/cmd/pipeline/start_test.go @@ -969,6 +969,7 @@ func TestPipelineV1beta1Start_ExecuteCommand(t *testing.T) { namespace string input *test.Params wantError bool + hasPrefix bool want string goldenFile bool }{ @@ -1347,7 +1348,8 @@ func TestPipelineV1beta1Start_ExecuteCommand(t *testing.T) { namespace: "", input: c2, wantError: true, - want: "time: unknown unit d in duration 5d", + hasPrefix: true, + want: `time: unknown unit`, }, { name: "Dry Run with PodTemplate", @@ -1379,7 +1381,12 @@ func TestPipelineV1beta1Start_ExecuteCommand(t *testing.T) { if err == nil { t.Errorf("error expected here") } - test.AssertOutput(t, tp.want, err.Error()) + + if tp.hasPrefix { + test.AssertOutputPrefix(t, tp.want, err.Error()) + } else { + test.AssertOutput(t, tp.want, err.Error()) + } } else { if err != nil { t.Errorf("unexpected Error") diff --git a/pkg/cmd/task/start_test.go b/pkg/cmd/task/start_test.go index 1007884cf..01704bf19 100644 --- a/pkg/cmd/task/start_test.go +++ b/pkg/cmd/task/start_test.go @@ -4358,6 +4358,7 @@ func TestTaskStart_ExecuteCommand_v1beta1(t *testing.T) { dynamic dynamic.Interface input pipelinev1beta1test.Clients wantError bool + hasPrefix bool want string goldenFile bool }{ @@ -4518,7 +4519,8 @@ func TestTaskStart_ExecuteCommand_v1beta1(t *testing.T) { dynamic: dc, input: cs, wantError: true, - want: "time: unknown unit d in duration 5d", + hasPrefix: true, + want: `time: unknown unit`, }, { name: "Dry Run with output=json -f v1beta1", @@ -4583,7 +4585,12 @@ func TestTaskStart_ExecuteCommand_v1beta1(t *testing.T) { if err == nil { t.Errorf("error expected here") } - test.AssertOutput(t, tp.want, err.Error()) + + if tp.hasPrefix { + test.AssertOutputPrefix(t, tp.want, err.Error()) + } else { + test.AssertOutput(t, tp.want, err.Error()) + } } else { if err != nil { t.Errorf("unexpected Error") diff --git a/pkg/formatted/color_test.go b/pkg/formatted/color_test.go index a6932f5d5..fe572297e 100644 --- a/pkg/formatted/color_test.go +++ b/pkg/formatted/color_test.go @@ -16,6 +16,7 @@ package formatted import ( "bytes" "html/template" + "strconv" "testing" @@ -39,7 +40,8 @@ func TestRainbowsColours(t *testing.T) { rb = newRainbow() for c := range palette { - rb.get(string(c)) + a := strconv.Itoa(c) + rb.get(a) } assert.Equal(t, rb.counter.value, uint32(0)) // Looped back to 0 } diff --git a/pkg/test/helpers.go b/pkg/test/helpers.go index b88af24e8..bffd8da0c 100644 --- a/pkg/test/helpers.go +++ b/pkg/test/helpers.go @@ -15,6 +15,7 @@ package test import ( + "strings" "testing" "github.com/google/go-cmp/cmp" @@ -57,3 +58,19 @@ Actual %s `, diff, expected, actual) } + +func AssertOutputPrefix(t *testing.T, expected, actual string) { + t.Helper() + + if !strings.HasPrefix(actual, expected) { + t.Errorf(` +Unexpected output: + +Expected prefix +%s + +Actual +%s +`, expected, actual) + } +}