diff --git a/cmd/entrypoint/subcommands/subcommands.go b/cmd/entrypoint/subcommands/subcommands.go index b9229546d8d..a4e7838192c 100644 --- a/cmd/entrypoint/subcommands/subcommands.go +++ b/cmd/entrypoint/subcommands/subcommands.go @@ -98,6 +98,7 @@ func Process(args []string) error { return OK{message: "Decoded script " + src} } case StepInitCommand: + //nolint: gosec if err := stepInit(args[1:]); err != nil { return SubcommandError{subcommand: StepInitCommand, message: err.Error()} } diff --git a/internal/sidecarlogresults/sidecarlogresults_test.go b/internal/sidecarlogresults/sidecarlogresults_test.go index bad265cb35d..ed3d7ba1dbf 100644 --- a/internal/sidecarlogresults/sidecarlogresults_test.go +++ b/internal/sidecarlogresults/sidecarlogresults_test.go @@ -80,7 +80,7 @@ func TestLookForResults_FanOutAndWait(t *testing.T) { sort.Slice(wantResults, func(i int, j int) bool { return wantResults[i] < wantResults[j] }) sort.Slice(got.Bytes(), func(i int, j int) bool { return got.Bytes()[i] < got.Bytes()[j] }) if d := cmp.Diff(wantResults, got.Bytes()); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -143,7 +143,7 @@ func TestLookForResults(t *testing.T) { t.Fatalf("Did not expect any error but got: %v", err) } if d := cmp.Diff(want, got.Bytes()); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -213,7 +213,7 @@ func TestLookForStepResults(t *testing.T) { t.Fatalf("Did not expect any error but got: %v", err) } if d := cmp.Diff(want, got.Bytes()); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -285,27 +285,33 @@ func TestParseResults(t *testing.T) { Name: "result1", Value: "foo", Type: "task", - }, { + }, + { Name: "result2", Value: `{"IMAGE_URL":"ar.com", "IMAGE_DIGEST":"sha234"}`, Type: "task", - }, { + }, + { Name: "result3", Value: `["hello","world"]`, Type: "task", - }, { + }, + { Name: "step-foo.result1", Value: "foo", Type: "step", - }, { + }, + { Name: "step-foo.result2", Value: `{"IMAGE_URL":"ar.com", "IMAGE_DIGEST":"sha234"}`, Type: "step", - }, { + }, + { Name: "step-foo.result3", Value: `["hello","world"]`, Type: "step", - }, { + }, + { Name: "step-artifacts-result", Value: `{ "inputs":[ @@ -605,7 +611,7 @@ func TestExtractStepAndResultFromSidecarResultName_Error(t *testing.T) { func TestLookForArtifacts(t *testing.T) { base := basicArtifacts() - var modified = base.DeepCopy() + modified := base.DeepCopy() modified.Outputs[0].Name = "tests" type Arg struct { stepName string @@ -626,7 +632,8 @@ func TestLookForArtifacts(t *testing.T) { Type: stepArtifactType, Value: mustJSON(&base), }}, - }, { + }, + { desc: "two step produce artifacts, read success", args: []Arg{{stepName: "first", artifacts: &base}, {stepName: "second", artifacts: modified}}, expected: []SidecarLogResult{{ @@ -707,7 +714,7 @@ func TestLookForArtifacts(t *testing.T) { got := buf.String() if d := cmp.Diff(want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1/param_types_test.go b/pkg/apis/pipeline/v1/param_types_test.go index b383d0e4c24..7191439c7e3 100644 --- a/pkg/apis/pipeline/v1/param_types_test.go +++ b/pkg/apis/pipeline/v1/param_types_test.go @@ -452,7 +452,7 @@ func TestArrayReference(t *testing.T) { }} for _, tt := range tests { if d := cmp.Diff(tt.expectedResult, v1.ArrayReference(tt.p)); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } } @@ -499,7 +499,7 @@ func TestExtractNames(t *testing.T) { }} for _, tt := range tests { if d := cmp.Diff(tt.want, v1.Params.ExtractNames(tt.params)); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } } @@ -562,7 +562,7 @@ func TestParams_ReplaceVariables(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got := tt.ps.ReplaceVariables(tt.stringReplacements, tt.arrayReplacements, tt.objectReplacements) if d := cmp.Diff(tt.want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -682,10 +682,10 @@ func TestParseTaskandResultName(t *testing.T) { pipelineTaskName, resultName := tc.param.ParseTaskandResultName() if d := cmp.Diff(tc.pipelineTaskName, pipelineTaskName); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } if d := cmp.Diff(tc.resultName, resultName); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -709,7 +709,7 @@ func TestGetNames(t *testing.T) { t.Run(tc.name, func(t *testing.T) { got := tc.params.GetNames() if d := cmp.Diff(tc.want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -770,7 +770,7 @@ func TestSortByType(t *testing.T) { s, a, o := tc.params.SortByType() got := []v1.ParamSpecs{s, a, o} if d := cmp.Diff(tc.want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -804,7 +804,7 @@ func TestValidateNoDuplicateNames(t *testing.T) { t.Run(tc.name, func(t *testing.T) { got := tc.params.ValidateNoDuplicateNames() if d := cmp.Diff(tc.expectedError.Error(), got.Error()); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1/result_validation_test.go b/pkg/apis/pipeline/v1/result_validation_test.go index ed71596b90b..e927230f037 100644 --- a/pkg/apis/pipeline/v1/result_validation_test.go +++ b/pkg/apis/pipeline/v1/result_validation_test.go @@ -297,10 +297,10 @@ func TestExtractStepResultName(t *testing.T) { t.Errorf("Did not expect an error but got: %v", err) } if d := cmp.Diff(tt.wantStep, gotStep); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } if d := cmp.Diff(tt.wantResult, gotResult); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -320,7 +320,7 @@ func TestExtractStepResultNameError(t *testing.T) { t.Run(tt.name, func(t *testing.T) { gotStep, gotResult, err := v1.ExtractStepResultName(tt.value) if d := cmp.Diff(tt.wantErr.Error(), err.Error()); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } if gotStep != "" { t.Errorf("Expected an empty string but got: %v", gotStep) diff --git a/pkg/apis/pipeline/v1/resultref_test.go b/pkg/apis/pipeline/v1/resultref_test.go index a5790b290fb..914f4bff5a1 100644 --- a/pkg/apis/pipeline/v1/resultref_test.go +++ b/pkg/apis/pipeline/v1/resultref_test.go @@ -761,7 +761,7 @@ func TestHasResultReferenceWhenExpression(t *testing.T) { } got := v1.NewResultRefs(expressions) if d := cmp.Diff(tt.wantRef, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -870,7 +870,8 @@ func TestPipelineTaskResultRefs(t *testing.T) { Value: *v1.NewStructuredValues("$(tasks.pt5.results.r5)", "$(tasks.pt6.results.r6)"), }, { Value: *v1.NewStructuredValues("$(tasks.pt7.results.r7)", "$(tasks.pt8.results.r8)"), - }}}, + }}, + }, TaskSpec: &v1.EmbeddedTask{ TaskSpec: v1.TaskSpec{ Steps: []v1.Step{ @@ -950,11 +951,12 @@ func TestParseResultName(t *testing.T) { name string input string want []string - }{{ - name: "array indexing", - input: "anArrayResult[1]", - want: []string{"anArrayResult", "1"}, - }, + }{ + { + name: "array indexing", + input: "anArrayResult[1]", + want: []string{"anArrayResult", "1"}, + }, { name: "array star reference", input: "anArrayResult[*]", @@ -976,37 +978,38 @@ func TestGetVarSubstitutionExpressionsForPipelineResult(t *testing.T) { name string result v1.PipelineResult want []string - }{{ - name: "get string result expressions", - result: v1.PipelineResult{ - Name: "string result", - Type: v1.ResultsTypeString, - Value: *v1.NewStructuredValues("$(tasks.task1.results.result1) and $(tasks.task2.results.result2)"), - }, - want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2"}, - }, { - name: "get array result expressions", - result: v1.PipelineResult{ - Name: "array result", - Type: v1.ResultsTypeString, - Value: *v1.NewStructuredValues("$(tasks.task1.results.result1)", "$(tasks.task2.results.result2)"), - }, - want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2"}, - }, { - name: "get object result expressions", - result: v1.PipelineResult{ - Name: "object result", - Type: v1.ResultsTypeString, - Value: *v1.NewObject(map[string]string{ - "key1": "$(tasks.task1.results.result1)", - "key2": "$(tasks.task2.results.result2) and another one $(tasks.task3.results.result3)", - "key3": "no ref here", - }), + }{ + { + name: "get string result expressions", + result: v1.PipelineResult{ + Name: "string result", + Type: v1.ResultsTypeString, + Value: *v1.NewStructuredValues("$(tasks.task1.results.result1) and $(tasks.task2.results.result2)"), + }, + want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2"}, + }, { + name: "get array result expressions", + result: v1.PipelineResult{ + Name: "array result", + Type: v1.ResultsTypeString, + Value: *v1.NewStructuredValues("$(tasks.task1.results.result1)", "$(tasks.task2.results.result2)"), + }, + want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2"}, + }, { + name: "get object result expressions", + result: v1.PipelineResult{ + Name: "object result", + Type: v1.ResultsTypeString, + Value: *v1.NewObject(map[string]string{ + "key1": "$(tasks.task1.results.result1)", + "key2": "$(tasks.task2.results.result2) and another one $(tasks.task3.results.result3)", + "key3": "no ref here", + }), + }, + want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2", "tasks.task3.results.result3"}, }, - want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2", "tasks.task3.results.result3"}, - }, } - var sortStrings = func(x, y string) bool { + sortStrings := func(x, y string) bool { return x < y } for _, tt := range tests { diff --git a/pkg/apis/pipeline/v1/taskrun_types_test.go b/pkg/apis/pipeline/v1/taskrun_types_test.go index a43b8cb2f23..a4b84be3549 100644 --- a/pkg/apis/pipeline/v1/taskrun_types_test.go +++ b/pkg/apis/pipeline/v1/taskrun_types_test.go @@ -369,7 +369,7 @@ func TestHasTimedOut(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.taskRun.HasTimedOut(context.Background(), testClock) if d := cmp.Diff(tc.expectedStatus, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -454,7 +454,7 @@ func TestIsDebugBeforeStep(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.args.trd.NeedsDebugBeforeStep(tc.args.stepName) if d := cmp.Diff(result, tc.want); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -505,7 +505,7 @@ func TestIsStepNeedDebug(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.args.trd.StepNeedsDebug(tc.args.stepName) if d := cmp.Diff(tc.want, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -552,7 +552,7 @@ func TestIsNeedDebug(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.args.trd.NeedsDebug() if d := cmp.Diff(tc.want, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1alpha1/run_types_test.go b/pkg/apis/pipeline/v1alpha1/run_types_test.go index f805882352d..50d8cd59689 100644 --- a/pkg/apis/pipeline/v1alpha1/run_types_test.go +++ b/pkg/apis/pipeline/v1alpha1/run_types_test.go @@ -34,8 +34,10 @@ import ( duckv1 "knative.dev/pkg/apis/duck/v1" ) -var now = time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC) -var testClock = clock.NewFakePassiveClock(now) +var ( + now = time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC) + testClock = clock.NewFakePassiveClock(now) +) func TestGetParams(t *testing.T) { for _, c := range []struct { @@ -343,7 +345,7 @@ func TestRunGetTimeOut(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.run.GetTimeout() if d := cmp.Diff(tc.expectedValue, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -366,7 +368,8 @@ func TestRunHasTimedOut(t *testing.T) { RunStatusFields: v1alpha1.RunStatusFields{ StartTime: &metav1.Time{Time: now}, }, - }}, + }, + }, expectedValue: false, }, { name: "runWithStartTimeNoTimeout2", @@ -376,7 +379,8 @@ func TestRunHasTimedOut(t *testing.T) { RunStatusFields: v1alpha1.RunStatusFields{ StartTime: &metav1.Time{Time: now.Add(-1 * (apisconfig.DefaultTimeoutMinutes + 1) * time.Minute)}, }, - }}, + }, + }, expectedValue: true, }, { name: "runWithStartTimeAndTimeout", @@ -385,7 +389,8 @@ func TestRunHasTimedOut(t *testing.T) { Spec: v1alpha1.RunSpec{Timeout: &metav1.Duration{Duration: 10 * time.Second}}, Status: v1alpha1.RunStatus{RunStatusFields: v1alpha1.RunStatusFields{ StartTime: &metav1.Time{Time: now.Add(-1 * (apisconfig.DefaultTimeoutMinutes + 1) * time.Minute)}, - }}}, + }}, + }, expectedValue: true, }, { name: "runWithNoStartTimeAndTimeout", @@ -401,7 +406,8 @@ func TestRunHasTimedOut(t *testing.T) { Spec: v1alpha1.RunSpec{Timeout: &metav1.Duration{Duration: 10 * time.Second}}, Status: v1alpha1.RunStatus{RunStatusFields: v1alpha1.RunStatusFields{ StartTime: &metav1.Time{Time: now}, - }}}, + }}, + }, expectedValue: false, }} @@ -409,7 +415,7 @@ func TestRunHasTimedOut(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.run.HasTimedOut(testClock) if d := cmp.Diff(tc.expectedValue, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/customrun_types_test.go b/pkg/apis/pipeline/v1beta1/customrun_types_test.go index 39b66c008e6..011ce02264b 100644 --- a/pkg/apis/pipeline/v1beta1/customrun_types_test.go +++ b/pkg/apis/pipeline/v1beta1/customrun_types_test.go @@ -376,7 +376,7 @@ func TestRunGetTimeOut(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.customRun.GetTimeout() if d := cmp.Diff(tc.expectedValue, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -399,7 +399,8 @@ func TestRunHasTimedOut(t *testing.T) { CustomRunStatusFields: v1beta1.CustomRunStatusFields{ StartTime: &metav1.Time{Time: now}, }, - }}, + }, + }, expectedValue: false, }, { name: "runWithStartTimeNoTimeout2", @@ -409,7 +410,8 @@ func TestRunHasTimedOut(t *testing.T) { CustomRunStatusFields: v1beta1.CustomRunStatusFields{ StartTime: &metav1.Time{Time: now.Add(-1 * (apisconfig.DefaultTimeoutMinutes + 1) * time.Minute)}, }, - }}, + }, + }, expectedValue: true, }, { name: "runWithStartTimeAndTimeout", @@ -418,7 +420,8 @@ func TestRunHasTimedOut(t *testing.T) { Spec: v1beta1.CustomRunSpec{Timeout: &metav1.Duration{Duration: 10 * time.Second}}, Status: v1beta1.CustomRunStatus{CustomRunStatusFields: v1beta1.CustomRunStatusFields{ StartTime: &metav1.Time{Time: now.Add(-1 * (apisconfig.DefaultTimeoutMinutes + 1) * time.Minute)}, - }}}, + }}, + }, expectedValue: true, }, { name: "runWithNoStartTimeAndTimeout", @@ -434,7 +437,8 @@ func TestRunHasTimedOut(t *testing.T) { Spec: v1beta1.CustomRunSpec{Timeout: &metav1.Duration{Duration: 10 * time.Second}}, Status: v1beta1.CustomRunStatus{CustomRunStatusFields: v1beta1.CustomRunStatusFields{ StartTime: &metav1.Time{Time: now}, - }}}, + }}, + }, expectedValue: false, }} @@ -442,7 +446,7 @@ func TestRunHasTimedOut(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.customRun.HasTimedOut(testClock) if d := cmp.Diff(tc.expectedValue, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/param_types_test.go b/pkg/apis/pipeline/v1beta1/param_types_test.go index 8494a279281..244bd27249d 100644 --- a/pkg/apis/pipeline/v1beta1/param_types_test.go +++ b/pkg/apis/pipeline/v1beta1/param_types_test.go @@ -451,7 +451,7 @@ func TestArrayReference(t *testing.T) { }} for _, tt := range tests { if d := cmp.Diff(tt.expectedResult, v1beta1.ArrayReference(tt.p)); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } } @@ -482,7 +482,7 @@ func TestArrayOrString(t *testing.T) { } if d := cmp.Diff(tt.expected, expected); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } } @@ -529,7 +529,7 @@ func TestExtractNames(t *testing.T) { }} for _, tt := range tests { if d := cmp.Diff(tt.want, v1beta1.Params.ExtractNames(tt.params)); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } } @@ -592,7 +592,7 @@ func TestParams_ReplaceVariables(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got := tt.ps.ReplaceVariables(tt.stringReplacements, tt.arrayReplacements, tt.objectReplacements) if d := cmp.Diff(tt.want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } diff --git a/pkg/apis/pipeline/v1beta1/resultref_test.go b/pkg/apis/pipeline/v1beta1/resultref_test.go index aa46dd09a7f..628219a393b 100644 --- a/pkg/apis/pipeline/v1beta1/resultref_test.go +++ b/pkg/apis/pipeline/v1beta1/resultref_test.go @@ -542,7 +542,7 @@ func TestHasResultReferenceWhenExpression(t *testing.T) { } got := v1beta1.NewResultRefs(expressions) if d := cmp.Diff(tt.wantRef, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -651,7 +651,8 @@ func TestPipelineTaskResultRefs(t *testing.T) { Value: *v1beta1.NewStructuredValues("$(tasks.pt5.results.r5)", "$(tasks.pt6.results.r6)"), }, { Value: *v1beta1.NewStructuredValues("$(tasks.pt7.results.r7)", "$(tasks.pt8.results.r8)"), - }}}, + }}, + }, } refs := v1beta1.PipelineTaskResultRefs(&pt) expectedRefs := []*v1beta1.ResultRef{{ @@ -696,11 +697,12 @@ func TestParseResultName(t *testing.T) { name string input string want []string - }{{ - name: "array indexing", - input: "anArrayResult[1]", - want: []string{"anArrayResult", "1"}, - }, + }{ + { + name: "array indexing", + input: "anArrayResult[1]", + want: []string{"anArrayResult", "1"}, + }, { name: "array star reference", input: "anArrayResult[*]", @@ -722,37 +724,38 @@ func TestGetVarSubstitutionExpressionsForPipelineResult(t *testing.T) { name string result v1beta1.PipelineResult want []string - }{{ - name: "get string result expressions", - result: v1beta1.PipelineResult{ - Name: "string result", - Type: v1beta1.ResultsTypeString, - Value: *v1beta1.NewStructuredValues("$(tasks.task1.results.result1) and $(tasks.task2.results.result2)"), - }, - want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2"}, - }, { - name: "get array result expressions", - result: v1beta1.PipelineResult{ - Name: "array result", - Type: v1beta1.ResultsTypeString, - Value: *v1beta1.NewStructuredValues("$(tasks.task1.results.result1)", "$(tasks.task2.results.result2)"), - }, - want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2"}, - }, { - name: "get object result expressions", - result: v1beta1.PipelineResult{ - Name: "object result", - Type: v1beta1.ResultsTypeString, - Value: *v1beta1.NewObject(map[string]string{ - "key1": "$(tasks.task1.results.result1)", - "key2": "$(tasks.task2.results.result2) and another one $(tasks.task3.results.result3)", - "key3": "no ref here", - }), + }{ + { + name: "get string result expressions", + result: v1beta1.PipelineResult{ + Name: "string result", + Type: v1beta1.ResultsTypeString, + Value: *v1beta1.NewStructuredValues("$(tasks.task1.results.result1) and $(tasks.task2.results.result2)"), + }, + want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2"}, + }, { + name: "get array result expressions", + result: v1beta1.PipelineResult{ + Name: "array result", + Type: v1beta1.ResultsTypeString, + Value: *v1beta1.NewStructuredValues("$(tasks.task1.results.result1)", "$(tasks.task2.results.result2)"), + }, + want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2"}, + }, { + name: "get object result expressions", + result: v1beta1.PipelineResult{ + Name: "object result", + Type: v1beta1.ResultsTypeString, + Value: *v1beta1.NewObject(map[string]string{ + "key1": "$(tasks.task1.results.result1)", + "key2": "$(tasks.task2.results.result2) and another one $(tasks.task3.results.result3)", + "key3": "no ref here", + }), + }, + want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2", "tasks.task3.results.result3"}, }, - want: []string{"tasks.task1.results.result1", "tasks.task2.results.result2", "tasks.task3.results.result3"}, - }, } - var sortStrings = func(x, y string) bool { + sortStrings := func(x, y string) bool { return x < y } for _, tt := range tests { diff --git a/pkg/apis/pipeline/v1beta1/taskrun_types_test.go b/pkg/apis/pipeline/v1beta1/taskrun_types_test.go index debe675868c..e9c61e4bfb1 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_types_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_types_test.go @@ -427,7 +427,7 @@ func TestHasTimedOut(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.taskRun.HasTimedOut(context.Background(), testClock) if d := cmp.Diff(tc.expectedStatus, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -512,7 +512,7 @@ func TestIsDebugBeforeStep(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.args.trd.NeedsDebugBeforeStep(tc.args.stepName) if d := cmp.Diff(result, tc.want); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -563,7 +563,7 @@ func TestIsStepNeedDebug(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.args.trd.StepNeedsDebug(tc.args.stepName) if d := cmp.Diff(tc.want, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -610,7 +610,7 @@ func TestIsNeedDebug(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.args.trd.NeedsDebug() if d := cmp.Diff(tc.want, result); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } diff --git a/pkg/pod/status.go b/pkg/pod/status.go index 523722d32c7..af3a8f984e7 100644 --- a/pkg/pod/status.go +++ b/pkg/pod/status.go @@ -571,6 +571,7 @@ func extractExitCodeFromResults(results []result.RunResult) (*int32, error) { if err != nil { return nil, fmt.Errorf("could not parse int value %q in ExitCode field: %w", result.Value, err) } + //nolint: gosec exitCode := int32(i) return &exitCode, nil } diff --git a/pkg/pod/status_test.go b/pkg/pod/status_test.go index 48af5fc344d..b5dfca8ce73 100644 --- a/pkg/pod/status_test.go +++ b/pkg/pod/status_test.go @@ -47,14 +47,15 @@ func TestSetTaskRunStatusBasedOnStepStatus(t *testing.T) { ContainerStatuses []corev1.ContainerStatus }{{ desc: "test result with large pipeline result", - ContainerStatuses: []corev1.ContainerStatus{{ - Name: "step-bar-0", - State: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultName","value":"resultValue", "type":1}, {"key":"digest","value":"sha256:1234","resourceName":"source-image"}]`, + ContainerStatuses: []corev1.ContainerStatus{ + { + Name: "step-bar-0", + State: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + Message: `[{"key":"resultName","value":"resultValue", "type":1}, {"key":"digest","value":"sha256:1234","resourceName":"source-image"}]`, + }, }, }, - }, { Name: "step-bar1", State: corev1.ContainerState{ @@ -70,7 +71,8 @@ func TestSetTaskRunStatusBasedOnStepStatus(t *testing.T) { Message: `[{"key":"resultName","value":"resultValue", "type":1}, {"key":"digest","value":"sha256:1234` + strings.Repeat("a", 3072) + `","resourceName":"source-image"}]`, }, }, - }}, + }, + }, }, { desc: "The ExitCode in the result cannot modify the original ExitCode", ContainerStatuses: []corev1.ContainerStatus{{ @@ -299,7 +301,8 @@ func TestMakeTaskRunStatus_StepResults(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"uri","value":"https://foo.bar\n","type":4}]`, - }}, + }, + }, Name: "one", Container: "step-one", Results: []v1.TaskRunStepResult{{ @@ -363,7 +366,8 @@ func TestMakeTaskRunStatus_StepResults(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"array","value":"[\"hello\",\"world\"]","type":4}]`, - }}, + }, + }, Name: "one", Container: "step-one", Results: []v1.TaskRunStepResult{{ @@ -430,7 +434,8 @@ func TestMakeTaskRunStatus_StepResults(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"digest","value":"sha256:1234","type":4},{"key":"resultName","value":"resultValue","type":4}]`, - }}, + }, + }, Name: "one", Container: "step-one", Results: []v1.TaskRunStepResult{{ @@ -702,29 +707,32 @@ func TestMakeTaskRunStatus_StepArtifacts(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"/tekton/run/0/status/artifacts/provenance.json","value":"{\n \"inputs\":[\n {\n \"name\":\"input-artifacts\",\n \"values\":[\n {\n \"uri\":\"git:jjjsss\",\n \"digest\":{\n \"sha256\":\"b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0\"\n }\n }\n ]\n }\n ],\n \"outputs\":[\n {\n \"name\":\"build-results\",\n \"values\":[\n {\n \"uri\":\"pkg:balba\",\n \"digest\":{\n \"sha256\":\"df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48\",\n \"sha1\":\"95588b8f34c31eb7d62c92aaa4e6506639b06ef2\"\n }\n }\n ]\n }\n ]\n}\n","type":5}]`, - }}, + }, + }, Name: "one", Container: "step-one", Inputs: []v1.Artifact{ { Name: "input-artifacts", - Values: []v1.ArtifactValue{{ - Digest: map[v1.Algorithm]string{"sha256": "b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0"}, - Uri: "git:jjjsss", - }, + Values: []v1.ArtifactValue{ + { + Digest: map[v1.Algorithm]string{"sha256": "b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0"}, + Uri: "git:jjjsss", + }, }, }, }, Outputs: []v1.Artifact{ { Name: "build-results", - Values: []v1.ArtifactValue{{ - Digest: map[v1.Algorithm]string{ - "sha1": "95588b8f34c31eb7d62c92aaa4e6506639b06ef2", - "sha256": "df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48", + Values: []v1.ArtifactValue{ + { + Digest: map[v1.Algorithm]string{ + "sha1": "95588b8f34c31eb7d62c92aaa4e6506639b06ef2", + "sha256": "df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48", + }, + Uri: "pkg:balba", }, - Uri: "pkg:balba", - }, }, }, }, @@ -734,23 +742,25 @@ func TestMakeTaskRunStatus_StepArtifacts(t *testing.T) { Inputs: []v1.Artifact{ { Name: "input-artifacts", - Values: []v1.ArtifactValue{{ - Digest: map[v1.Algorithm]string{"sha256": "b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0"}, - Uri: "git:jjjsss", - }, + Values: []v1.ArtifactValue{ + { + Digest: map[v1.Algorithm]string{"sha256": "b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0"}, + Uri: "git:jjjsss", + }, }, }, }, Outputs: []v1.Artifact{ { Name: "build-results", - Values: []v1.ArtifactValue{{ - Digest: map[v1.Algorithm]string{ - "sha1": "95588b8f34c31eb7d62c92aaa4e6506639b06ef2", - "sha256": "df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48", + Values: []v1.ArtifactValue{ + { + Digest: map[v1.Algorithm]string{ + "sha1": "95588b8f34c31eb7d62c92aaa4e6506639b06ef2", + "sha256": "df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48", + }, + Uri: "pkg:balba", }, - Uri: "pkg:balba", - }, }, }, }, @@ -838,7 +848,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ ExitCode: 123, - }}, + }, + }, Name: "state-name", Container: "step-state-name", }}, @@ -874,7 +885,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ ExitCode: 123, - }}, + }, + }, Name: "state-name", Container: "step-state-name", ImageID: "image-id", @@ -905,7 +917,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ ExitCode: 0, - }}, + }, + }, Name: "step-push", Container: "step-step-push", ImageID: "image-id", @@ -964,7 +977,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ ExitCode: 123, - }}, + }, + }, Name: "failure", Container: "step-failure", @@ -1012,7 +1026,8 @@ func TestMakeTaskRunStatus(t *testing.T) { Terminated: &corev1.ContainerStateTerminated{ Reason: "OOMKilled", ExitCode: 0, - }}, + }, + }, Name: "step-push", Container: "step-step-push", ImageID: "image-id", @@ -1288,7 +1303,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"digest","value":"sha256:12345","resourceName":"source-image"}]`, - }}, + }, + }, Name: "foo", Container: "step-foo", }}, @@ -1317,7 +1333,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"digest","value":"sha256:1234","resourceName":"source-image"},{"key":"resultName","value":"resultValue","type":1}]`, - }}, + }, + }, Name: "bar", Container: "step-bar", }}, @@ -1351,7 +1368,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"digest","value":"sha256:1234","resourceName":"source-image"},{"key":"resultName","value":"resultValue","type":1}]`, - }}, + }, + }, Name: "banana", Container: "step-banana", }}, @@ -1392,14 +1410,16 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"resultNameOne","value":"resultValueOne","type":1},{"key":"resultNameTwo","value":"resultValueTwo","type":1}]`, - }}, + }, + }, Name: "one", Container: "step-one", }, { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"resultNameOne","value":"resultValueThree","type":1},{"key":"resultNameTwo","value":"resultValueTwo","type":1}]`, - }}, + }, + }, Name: "two", Container: "step-two", }}, @@ -1467,7 +1487,8 @@ func TestMakeTaskRunStatus(t *testing.T) { TaskRunStatusFields: v1.TaskRunStatusFields{ Steps: []v1.StepState{{ ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{}}, + Terminated: &corev1.ContainerStateTerminated{}, + }, Name: "mango", Container: "step-mango", }}, @@ -1494,7 +1515,8 @@ func TestMakeTaskRunStatus(t *testing.T) { TaskRunStatusFields: v1.TaskRunStatusFields{ Steps: []v1.StepState{{ ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{}}, + Terminated: &corev1.ContainerStateTerminated{}, + }, Name: "pineapple", Container: "step-pineapple", }}, @@ -1511,7 +1533,8 @@ func TestMakeTaskRunStatus(t *testing.T) { Name: "step-pear", State: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultNameOne","value":"","type":3}, {"key":"resultNameThree","value":"","type":1}]`}, + Message: `[{"key":"resultNameOne","value":"","type":3}, {"key":"resultNameThree","value":"","type":1}]`, + }, }, }}, }, @@ -1522,7 +1545,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"resultNameThree","value":"","type":1}]`, - }}, + }, + }, Name: "pear", Container: "step-pear", }}, @@ -1556,7 +1580,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"resultNameThree","value":"","type":1}]`, - }}, + }, + }, Name: "pear", Container: "step-pear", }}, @@ -1630,22 +1655,26 @@ func TestMakeTaskRunStatus(t *testing.T) { Container: "step-first", }, { ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{}}, + Terminated: &corev1.ContainerStateTerminated{}, + }, Name: "second", Container: "step-second", }, { ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{}}, + Terminated: &corev1.ContainerStateTerminated{}, + }, Name: "third", Container: "step-third", }, { ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{}}, + Terminated: &corev1.ContainerStateTerminated{}, + }, Name: "", Container: "step-", }, { ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{}}, + Terminated: &corev1.ContainerStateTerminated{}, + }, Name: "fourth", Container: "step-fourth", }}, @@ -1700,7 +1729,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ ExitCode: 0, - }}, + }, + }, Name: "second", Container: "step-second", }}, @@ -1772,7 +1802,8 @@ func TestMakeTaskRunStatus(t *testing.T) { State: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ ExitCode: 1, - }}, + }, + }, }}, ContainerStatuses: []corev1.ContainerStatus{{ Name: "step-A", @@ -1821,15 +1852,17 @@ func TestMakeTaskRunStatus(t *testing.T) { Phase: corev1.PodFailed, Reason: "Evicted", Message: `Usage of EmptyDir volume "ws-b6dfk" exceeds the limit "10Gi".`, - ContainerStatuses: []corev1.ContainerStatus{{ - Name: "step-A", - State: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{ - ExitCode: 137, + ContainerStatuses: []corev1.ContainerStatus{ + { + Name: "step-A", + State: corev1.ContainerState{ + Terminated: &corev1.ContainerStateTerminated{ + ExitCode: 137, + }, }, }, }, - }}, + }, }, want: v1.TaskRunStatus{ Status: statusFailure(v1.TaskRunReasonFailed.String(), "Usage of EmptyDir volume \"ws-b6dfk\" exceeds the limit \"10Gi\"."), @@ -1838,7 +1871,8 @@ func TestMakeTaskRunStatus(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ ExitCode: 137, - }}, + }, + }, Name: "A", Container: "step-A", }}, @@ -2134,7 +2168,8 @@ func TestMakeTaskRunStatusAlpha(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"digest","value":"sha256:1234","resourceName":"source-image"},{"key":"resultName","value":"","type":1}]`, - }}, + }, + }, Name: "bar", Container: "step-bar", }}, @@ -2176,7 +2211,8 @@ func TestMakeTaskRunStatusAlpha(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"digest","value":"sha256:1234","resourceName":"source-image"},{"key":"resultName","value":"hello","type":1}]`, - }}, + }, + }, Name: "bar", Container: "step-bar", }}, @@ -2218,7 +2254,8 @@ func TestMakeTaskRunStatusAlpha(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"digest","value":"sha256:1234","resourceName":"source-image"},{"key":"resultName","value":"[\"hello\",\"world\"]","type":1}]`, - }}, + }, + }, Name: "bar", Container: "step-bar", }}, @@ -2260,7 +2297,8 @@ func TestMakeTaskRunStatusAlpha(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"digest","value":"sha256:1234","resourceName":"source-image"},{"key":"resultName","value":"{\"hello\":\"world\"}","type":1}]`, - }}, + }, + }, Name: "bar", Container: "step-bar", }}, @@ -2306,7 +2344,8 @@ func TestMakeTaskRunStatusAlpha(t *testing.T) { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ Message: `[{"key":"resultName","value":"{\"hello\":\"world\"}","type":1},{"key":"resultName2","value":"[\"hello\",\"world\"]","type":1}]`, - }}, + }, + }, Name: "bar", Container: "step-bar", }}, @@ -2440,28 +2479,32 @@ func TestMakeRunStatusJSONError(t *testing.T) { Terminated: &corev1.ContainerStateTerminated{ ExitCode: 1, Message: "this is a non-json termination message. dont panic!", - }}, + }, + }, Name: "non-json", Container: "step-non-json", Results: []v1.TaskRunResult{}, ImageID: "image", }, { ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{}}, + Terminated: &corev1.ContainerStateTerminated{}, + }, Name: "after-non-json", Container: "step-after-non-json", Results: []v1.TaskRunResult{}, ImageID: "image", }, { ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{}}, + Terminated: &corev1.ContainerStateTerminated{}, + }, Name: "this-step-might-panic", Container: "step-this-step-might-panic", Results: []v1.TaskRunResult{}, ImageID: "image", }, { ContainerState: corev1.ContainerState{ - Terminated: &corev1.ContainerStateTerminated{}}, + Terminated: &corev1.ContainerStateTerminated{}, + }, Name: "foo", Container: "step-foo", Results: []v1.TaskRunResult{}, @@ -2658,10 +2701,12 @@ func TestIsPodArchived(t *testing.T) { }, { name: "Pod is in the retriesStatus", podName: "pod", - retriesStatus: []v1.TaskRunStatus{{ - TaskRunStatusFields: v1.TaskRunStatusFields{ - PodName: "pod", - }}, + retriesStatus: []v1.TaskRunStatus{ + { + TaskRunStatusFields: v1.TaskRunStatusFields{ + PodName: "pod", + }, + }, }, want: true, }} { @@ -2810,7 +2855,7 @@ func TestGetStepResultsFromSidecarLogs(t *testing.T) { t.Errorf("did not expect an error but got: %v", err) } if d := cmp.Diff(want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } @@ -2825,7 +2870,7 @@ func TestGetStepResultsFromSidecarLogs_Error(t *testing.T) { _, err := getStepResultsFromSidecarLogs(sidecarLogResults, stepName) wantErr := fmt.Errorf("invalid string %s-%s : expected somtthing that looks like .", stepName, resultName) if d := cmp.Diff(wantErr.Error(), err.Error()); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } @@ -3049,6 +3094,6 @@ func TestGetTaskResultsFromSidecarLogs(t *testing.T) { }} got := getTaskResultsFromSidecarLogs(sidecarLogResults) if d := cmp.Diff(want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } diff --git a/pkg/reconciler/events/cloudevent/cloud_event_controller_test.go b/pkg/reconciler/events/cloudevent/cloud_event_controller_test.go index f44e0a7c96c..907e032601b 100644 --- a/pkg/reconciler/events/cloudevent/cloud_event_controller_test.go +++ b/pkg/reconciler/events/cloudevent/cloud_event_controller_test.go @@ -106,7 +106,7 @@ func TestSendCloudEventWithRetries(t *testing.T) { ceClient.CheckCloudEventsUnordered(t, tc.name, tc.wantCEvents) recorder := controller.GetEventRecorder(ctx).(*record.FakeRecorder) if err := k8sevent.CheckEventsOrdered(t, recorder.Events, tc.name, tc.wantEvents); err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } }) } @@ -223,7 +223,7 @@ func TestEmitCloudEvents(t *testing.T) { recorder := controller.GetEventRecorder(ctx).(*record.FakeRecorder) cloudevent.EmitCloudEvents(ctx, object) if err := k8sevent.CheckEventsOrdered(t, recorder.Events, tc.name, tc.wantEvents); err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } fakeClient.CheckCloudEventsUnordered(t, tc.name, tc.wantCloudEvents) } diff --git a/pkg/reconciler/events/event_test.go b/pkg/reconciler/events/event_test.go index 5e790d347cd..ca0135a4ae4 100644 --- a/pkg/reconciler/events/event_test.go +++ b/pkg/reconciler/events/event_test.go @@ -109,7 +109,7 @@ func TestEmit(t *testing.T) { recorder := controller.GetEventRecorder(ctx).(*record.FakeRecorder) events.Emit(ctx, nil, after, object) if err := k8sevent.CheckEventsOrdered(t, recorder.Events, tc.name, tc.wantEvents); err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } fakeClient.CheckCloudEventsUnordered(t, tc.name, tc.wantCloudEvents) } diff --git a/pkg/reconciler/events/k8sevent/event_test.go b/pkg/reconciler/events/k8sevent/event_test.go index 612c4177a31..db4f4fd2016 100644 --- a/pkg/reconciler/events/k8sevent/event_test.go +++ b/pkg/reconciler/events/k8sevent/event_test.go @@ -180,7 +180,7 @@ func TestEmitK8sEventsOnConditions(t *testing.T) { k8sevents.EmitK8sEvents(ctx, ts.before, ts.after, tr) err := k8sevents.CheckEventsOrdered(t, recorder.Events, ts.name, ts.wantEvents) if err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } } } @@ -237,7 +237,7 @@ func TestEmitK8sEvents(t *testing.T) { recorder := controller.GetEventRecorder(ctx).(*record.FakeRecorder) k8sevents.EmitK8sEvents(ctx, nil, after, object) if err := k8sevents.CheckEventsOrdered(t, recorder.Events, tc.name, tc.wantEvents); err != nil { - t.Fatalf(err.Error()) + t.Fatal(err.Error()) } } } @@ -263,7 +263,7 @@ func TestEmitError(t *testing.T) { k8sevents.EmitError(fr, ts.err, tr) err := k8sevents.CheckEventsOrdered(t, fr.Events, ts.name, ts.wantEvents) if err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } } } diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 6c6dfc37b64..aee6cbd07db 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -2780,7 +2780,7 @@ spec: prt.Test.Logf("Getting events") // Check generated events match what's expected if err := k8sevent.CheckEventsOrdered(prt.Test, prt.TestAssets.Recorder.Events, "test-pipeline-run-with-timeout", wantEvents); err != nil { - prt.Test.Errorf(err.Error()) + prt.Test.Error(err.Error()) } // The PipelineRun should be timed out. @@ -3563,7 +3563,7 @@ spec: } err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, prName, wantEvents) if err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } // Turn off failing reactor and retry reconciliation @@ -3681,7 +3681,7 @@ spec: } err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, prName, wantEvents) if err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } // Turn off failing reactor and retry reconciliation @@ -6908,7 +6908,7 @@ metadata: t.Errorf("storePipelineSpec() error = %v", err) } if d := cmp.Diff(tc.wantPipelineRun, pr); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } // mock second reconcile @@ -6916,7 +6916,7 @@ metadata: t.Errorf("storePipelineSpec() error = %v", err) } if d := cmp.Diff(tc.wantPipelineRun, pr); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -6940,10 +6940,10 @@ func Test_storePipelineSpec_metadata(t *testing.T) { t.Errorf("storePipelineSpecAndMergeMeta error = %v", err) } if d := cmp.Diff(wantedlabels, pr.ObjectMeta.Labels); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } if d := cmp.Diff(wantedannotations, pr.ObjectMeta.Annotations); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } } @@ -8443,7 +8443,7 @@ func (prt PipelineRunTest) reconcileRun(namespace, pipelineRunName string, wantE // Check generated events match what's expected if len(wantEvents) > 0 { if err := k8sevent.CheckEventsOrdered(prt.Test, prt.TestAssets.Recorder.Events, pipelineRunName, wantEvents); err != nil { - prt.Test.Errorf(err.Error()) + prt.Test.Error(err.Error()) } } diff --git a/pkg/reconciler/pipelinerun/resources/apply_test.go b/pkg/reconciler/pipelinerun/resources/apply_test.go index 507d53c17b3..60c69c10250 100644 --- a/pkg/reconciler/pipelinerun/resources/apply_test.go +++ b/pkg/reconciler/pipelinerun/resources/apply_test.go @@ -3387,19 +3387,19 @@ func TestContext(t *testing.T) { } got := resources.ApplyContexts(&orig.Spec, orig.Name, tc.pr) if d := cmp.Diff(tc.expected, got.Tasks[0].Params[0]); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } if d := cmp.Diff(tc.expected, got.Finally[0].Params[0]); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } if d := cmp.Diff(tc.expected, got.Tasks[0].Matrix.Params[0]); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } if d := cmp.Diff(tc.expectedDisplayName, got.Tasks[0].DisplayName); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } if d := cmp.Diff(tc.expectedDisplayName, got.Finally[0].DisplayName); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -3651,7 +3651,7 @@ func TestApplyPipelineTaskContexts(t *testing.T) { t.Run(tc.description, func(t *testing.T) { got := resources.ApplyPipelineTaskContexts(&tc.pt, tc.prstatus, tc.facts) if d := cmp.Diff(&tc.want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -3821,7 +3821,7 @@ func TestApplyFinallyResultsToPipelineResults(t *testing.T) { t.Run(tc.description, func(t *testing.T) { received, _ := resources.ApplyTaskResultsToPipelineResults(context.Background(), tc.results, tc.taskResults, tc.runResults, nil /* skippedTasks */) if d := cmp.Diff(tc.expected, received); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -4157,7 +4157,7 @@ func TestApplyTaskResultsToPipelineResults_Success(t *testing.T) { t.Errorf("Got unecpected error:%v", err) } if d := cmp.Diff(tc.expectedResults, received); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -4379,7 +4379,7 @@ func TestApplyTaskResultsToPipelineResults_Error(t *testing.T) { } if d := cmp.Diff(tc.expectedResults, received); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -4767,7 +4767,8 @@ func TestPropagateArtifacts(t *testing.T) { expectedResolvedTask: &resources.ResolvedPipelineTask{ ResolvedTask: nil, }, - }, { + }, + { name: "not propagate artifact when taskSpec is nil", resolvedTask: &resources.ResolvedPipelineTask{ ResolvedTask: &taskresources.ResolvedTask{ diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go index 4382901a9cb..b3696527310 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunresolution_test.go @@ -2567,7 +2567,7 @@ func TestResolvePipelineRun_VerificationFailed(t *testing.T) { for _, pt := range pts { rt, _ := ResolvePipelineTask(context.Background(), pr, getTask, getTaskRun, nopGetCustomRun, pt, nil) if d := cmp.Diff(verificationResult, rt.ResolvedTask.VerificationResult, cmpopts.EquateErrors()); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } } @@ -4819,50 +4819,56 @@ func TestGetReason(t *testing.T) { name string rpt ResolvedPipelineTask want string - }{{ - name: "taskrun created but the conditions were not initialized", - rpt: ResolvedPipelineTask{ - PipelineTask: &v1.PipelineTask{Name: "task"}, - TaskRuns: []*v1.TaskRun{{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "namespace", - Name: "taskRun", - }, - }}, + }{ + { + name: "taskrun created but the conditions were not initialized", + rpt: ResolvedPipelineTask{ + PipelineTask: &v1.PipelineTask{Name: "task"}, + TaskRuns: []*v1.TaskRun{{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "namespace", + Name: "taskRun", + }, + }}, + }, }, - }, { name: "taskrun not started", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, }, - }, { + }, + { name: "run not started", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, CustomTask: true, }, - }, { + }, + { name: "taskrun running", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, TaskRuns: []*v1.TaskRun{makeStarted(trs[0])}, }, - }, { + }, + { name: "run running", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, CustomTask: true, CustomRuns: []*v1beta1.CustomRun{makeCustomRunStarted(customRuns[0])}, }, - }, { + }, + { name: "taskrun succeeded", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, TaskRuns: []*v1.TaskRun{makeSucceeded(trs[0])}, }, want: "Succeeded", - }, { + }, + { name: "run succeeded", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, @@ -4870,14 +4876,16 @@ func TestGetReason(t *testing.T) { CustomRuns: []*v1beta1.CustomRun{makeCustomRunSucceeded(customRuns[0])}, }, want: "Succeeded", - }, { + }, + { name: "taskrun failed", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, TaskRuns: []*v1.TaskRun{makeFailed(trs[0])}, }, want: "Failed", - }, { + }, + { name: "run failed", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, @@ -4885,14 +4893,16 @@ func TestGetReason(t *testing.T) { CustomRuns: []*v1beta1.CustomRun{makeCustomRunFailed(customRuns[0])}, }, want: "Failed", - }, { + }, + { name: "taskrun failed: retried", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task", Retries: 1}, TaskRuns: []*v1.TaskRun{withRetries(makeFailed(trs[0]))}, }, want: "Failed", - }, { + }, + { name: "run failed: retried", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task", Retries: 1}, @@ -4900,21 +4910,24 @@ func TestGetReason(t *testing.T) { CustomRuns: []*v1beta1.CustomRun{withCustomRunRetries(makeCustomRunFailed(customRuns[0]))}, }, want: "Failed", - }, { + }, + { name: "taskrun cancelled", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, TaskRuns: []*v1.TaskRun{withCancelled(makeFailed(trs[0]))}, }, want: v1.TaskRunReasonCancelled.String(), - }, { + }, + { name: "taskrun cancelled but not failed", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, TaskRuns: []*v1.TaskRun{withCancelled(newTaskRun(trs[0]))}, }, want: v1.TaskRunReasonCancelled.String(), - }, { + }, + { name: "run cancelled", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, @@ -4922,7 +4935,8 @@ func TestGetReason(t *testing.T) { CustomTask: true, }, want: "CustomRunCancelled", - }, { + }, + { name: "run cancelled but not failed", rpt: ResolvedPipelineTask{ PipelineTask: &v1.PipelineTask{Name: "task"}, @@ -4930,14 +4944,16 @@ func TestGetReason(t *testing.T) { CustomTask: true, }, want: "CustomRunCancelled", - }, { + }, + { name: "matrixed taskruns succeeded", rpt: ResolvedPipelineTask{ PipelineTask: matrixedPipelineTask, TaskRuns: []*v1.TaskRun{makeSucceeded(trs[0]), makeSucceeded(trs[1])}, }, want: "Succeeded", - }, { + }, + { name: "matrixed runs succeeded", rpt: ResolvedPipelineTask{ CustomTask: true, @@ -4945,14 +4961,16 @@ func TestGetReason(t *testing.T) { CustomRuns: []*v1beta1.CustomRun{makeCustomRunSucceeded(customRuns[0]), makeCustomRunSucceeded(customRuns[1])}, }, want: "Succeeded", - }, { + }, + { name: "matrixed taskruns failed", rpt: ResolvedPipelineTask{ PipelineTask: matrixedPipelineTask, TaskRuns: []*v1.TaskRun{makeFailed(trs[0]), makeFailed(trs[1])}, }, want: "Failed", - }, { + }, + { name: "matrixed runs failed", rpt: ResolvedPipelineTask{ CustomTask: true, @@ -4960,14 +4978,16 @@ func TestGetReason(t *testing.T) { CustomRuns: []*v1beta1.CustomRun{makeCustomRunFailed(customRuns[0]), makeCustomRunFailed(customRuns[1])}, }, want: "Failed", - }, { + }, + { name: "matrixed taskruns cancelled", rpt: ResolvedPipelineTask{ PipelineTask: matrixedPipelineTask, TaskRuns: []*v1.TaskRun{withCancelled(makeFailed(trs[0])), withCancelled(makeFailed(trs[1]))}, }, want: v1.TaskRunReasonCancelled.String(), - }, { + }, + { name: "matrixed runs cancelled", rpt: ResolvedPipelineTask{ CustomTask: true, @@ -4975,7 +4995,8 @@ func TestGetReason(t *testing.T) { CustomRuns: []*v1beta1.CustomRun{withCustomRunCancelled(makeCustomRunFailed(customRuns[0])), withCustomRunCancelled(makeCustomRunFailed(customRuns[1]))}, }, want: "CustomRunCancelled", - }} { + }, + } { t.Run(tc.name, func(t *testing.T) { if got := tc.rpt.getReason(); got != tc.want { t.Errorf("expected getReason: %s but got %s", tc.want, got) diff --git a/pkg/reconciler/pipelinerun/tracing.go b/pkg/reconciler/pipelinerun/tracing.go index 8aedd34948e..7ab4d1755c5 100644 --- a/pkg/reconciler/pipelinerun/tracing.go +++ b/pkg/reconciler/pipelinerun/tracing.go @@ -45,7 +45,7 @@ func initTracing(ctx context.Context, tracerProvider trace.TracerProvider, pr *v pro := otel.GetTextMapPropagator() // SpanContext was created already - if pr.Status.SpanContext != nil && len(pr.Status.SpanContext) > 0 { + if len(pr.Status.SpanContext) > 0 { return pro.Extract(ctx, propagation.MapCarrier(pr.Status.SpanContext)) } diff --git a/pkg/reconciler/taskrun/resources/apply_test.go b/pkg/reconciler/taskrun/resources/apply_test.go index 9601df0b4bf..9b1d9f1be1b 100644 --- a/pkg/reconciler/taskrun/resources/apply_test.go +++ b/pkg/reconciler/taskrun/resources/apply_test.go @@ -551,12 +551,14 @@ var ( arrayTaskRun0Elements = &v1.TaskRun{ Spec: v1.TaskRunSpec{ - Params: []v1.Param{{ - Name: "array-param", - Value: v1.ParamValue{ - Type: v1.ParamTypeArray, - ArrayVal: []string{}, - }}, + Params: []v1.Param{ + { + Name: "array-param", + Value: v1.ParamValue{ + Type: v1.ParamTypeArray, + ArrayVal: []string{}, + }, + }, }, }, } @@ -1101,13 +1103,15 @@ func TestApplyWorkspaces(t *testing.T) { Name: "$(workspaces.myws.volume)", }, }, - }}, { + }, + }, { Name: "some-secret", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: "$(workspaces.myws.volume)", }, - }}, { + }, + }, { Name: "some-pvc", VolumeSource: corev1.VolumeSource{ PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ @@ -1479,7 +1483,7 @@ func TestContext(t *testing.T) { t.Run(tc.description, func(t *testing.T) { got := resources.ApplyContexts(&tc.spec, tc.taskName, &tc.tr) if d := cmp.Diff(&tc.want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -1488,12 +1492,14 @@ func TestContext(t *testing.T) { func TestTaskResults(t *testing.T) { names.TestingSeed() ts := &v1.TaskSpec{ - Results: []v1.TaskResult{{ - Name: "current.date.unix.timestamp", - Description: "The current date in unix timestamp format", - }, { - Name: "current-date-human-readable", - Description: "The current date in humand readable format"}, + Results: []v1.TaskResult{ + { + Name: "current.date.unix.timestamp", + Description: "The current date in unix timestamp format", + }, { + Name: "current-date-human-readable", + Description: "The current date in humand readable format", + }, }, Steps: []v1.Step{{ Name: "print-date-unix-timestamp", @@ -1630,7 +1636,7 @@ func TestApplyCredentialsPath(t *testing.T) { t.Run(tc.description, func(t *testing.T) { got := resources.ApplyCredentialsPath(&tc.spec, tc.path) if d := cmp.Diff(&tc.want, got); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } @@ -1788,10 +1794,11 @@ func TestApplyParametersToWorkspaceBindings(t *testing.T) { }, }, }, - Params: v1.Params{{Name: "secret-name", Value: v1.ParamValue{ - Type: v1.ParamTypeString, - StringVal: "secret-value", - }}, + Params: v1.Params{ + {Name: "secret-name", Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "secret-value", + }}, }, }, }, @@ -2021,14 +2028,15 @@ func TestApplyParametersToWorkspaceBindings(t *testing.T) { func TestArtifacts(t *testing.T) { ts := &v1.TaskSpec{ - Steps: []v1.Step{{ - Name: "name1", - Image: "bash:latest", - Args: []string{ - "$(step.artifacts.path)", + Steps: []v1.Step{ + { + Name: "name1", + Image: "bash:latest", + Args: []string{ + "$(step.artifacts.path)", + }, + Script: "#!/usr/bin/env bash\n echo -n $(step.artifacts.path)", }, - Script: "#!/usr/bin/env bash\n echo -n $(step.artifacts.path)", - }, }, } diff --git a/pkg/reconciler/taskrun/resources/taskspec_test.go b/pkg/reconciler/taskrun/resources/taskspec_test.go index 95aca44ed84..f2fb37ee42c 100644 --- a/pkg/reconciler/taskrun/resources/taskspec_test.go +++ b/pkg/reconciler/taskrun/resources/taskspec_test.go @@ -201,7 +201,7 @@ func TestGetTaskData_ResolutionSuccess(t *testing.T) { } if d := cmp.Diff(sourceSpec, *resolvedSpec); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } @@ -297,7 +297,7 @@ func TestGetTaskData_VerificationResult(t *testing.T) { t.Fatalf("Did not expect error but got: %s", err) } if d := cmp.Diff(verificationResult, r.VerificationResult, cmpopts.EquateErrors()); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } } diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 24a4903ee6b..a43f64b57cb 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -627,7 +627,7 @@ spec: err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, "reconcile-cloud-events", wantEvents) if !(err == nil) { - t.Errorf(err.Error()) + t.Error(err.Error()) } wantCloudEvents := []string{ @@ -968,7 +968,7 @@ spec: err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, tc.name, tc.wantEvents) if err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } }) } @@ -1122,7 +1122,7 @@ spec: err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, tc.name, tc.wantEvents) if err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } }) } @@ -1461,7 +1461,7 @@ spec: err := k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, tc.name, tc.wantEvents) if !(err == nil) { - t.Errorf(err.Error()) + t.Error(err.Error()) } newTr, err := testAssets.Clients.Pipeline.TektonV1().TaskRuns(tc.taskRun.Namespace).Get(testAssets.Ctx, tc.taskRun.Name, metav1.GetOptions{}) @@ -2487,7 +2487,7 @@ status: } err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, "test-reconcile-pod-updateStatus", wantEvents) if !(err == nil) { - t.Errorf(err.Error()) + t.Error(err.Error()) } } @@ -2586,7 +2586,7 @@ status: } err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, "test-reconcile-on-cancelled-taskrun", wantEvents) if !(err == nil) { - t.Errorf(err.Error()) + t.Error(err.Error()) } // reconcile the completed TaskRun again without the pod as that was deleted @@ -2659,7 +2659,7 @@ status: } err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, "test-reconcile-on-timedout-taskrun", wantEvents) if !(err == nil) { - t.Errorf(err.Error()) + t.Error(err.Error()) } // reconcile the completed TaskRun again without the pod as that was deleted @@ -2892,7 +2892,7 @@ status: } err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, taskRun.Name, wantEvents) if err != nil { - t.Errorf(err.Error()) + t.Error(err.Error()) } } }) @@ -3097,7 +3097,7 @@ status: } err = k8sevent.CheckEventsOrdered(t, testAssets.Recorder.Events, tc.taskRun.Name, tc.wantEvents) if !(err == nil) { - t.Errorf(err.Error()) + t.Error(err.Error()) } }) } @@ -5231,7 +5231,7 @@ status: t.Fatal(err) } if d := cmp.Diff(&tc.expectedStatus, tc.taskRun.Status.GetCondition(apis.ConditionSucceeded), ignoreLastTransitionTime); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } if tc.expectedStepStates != nil { @@ -5335,7 +5335,7 @@ spec: t.Errorf("storePipelineSpec() error = %v", err) } if d := cmp.Diff(tc.wantTaskRun, tr); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } // mock second reconcile @@ -5343,7 +5343,7 @@ spec: t.Errorf("storePipelineSpec() error = %v", err) } if d := cmp.Diff(tc.wantTaskRun, tr); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } }) } @@ -5368,10 +5368,10 @@ func Test_storeTaskSpec_metadata(t *testing.T) { t.Errorf("storeTaskSpecAndMergeMeta error = %v", err) } if d := cmp.Diff(wantedlabels, tr.ObjectMeta.Labels); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } if d := cmp.Diff(wantedannotations, tr.ObjectMeta.Annotations); d != "" { - t.Fatalf(diff.PrintWantGot(d)) + t.Fatal(diff.PrintWantGot(d)) } } diff --git a/pkg/reconciler/taskrun/tracing.go b/pkg/reconciler/taskrun/tracing.go index d5e26a3a984..9bcf616c1c4 100644 --- a/pkg/reconciler/taskrun/tracing.go +++ b/pkg/reconciler/taskrun/tracing.go @@ -42,7 +42,7 @@ func initTracing(ctx context.Context, tracerProvider trace.TracerProvider, tr *v pro := otel.GetTextMapPropagator() // SpanContext was created already - if tr.Status.SpanContext != nil && len(tr.Status.SpanContext) > 0 { + if len(tr.Status.SpanContext) > 0 { return pro.Extract(ctx, propagation.MapCarrier(tr.Status.SpanContext)) } diff --git a/pkg/remoteresolution/resolver/http/resolver_test.go b/pkg/remoteresolution/resolver/http/resolver_test.go index 0c9a3fd2ec5..f95fded82d4 100644 --- a/pkg/remoteresolution/resolver/http/resolver_test.go +++ b/pkg/remoteresolution/resolver/http/resolver_test.go @@ -155,7 +155,7 @@ func TestResolve(t *testing.T) { if tc.expectedStatus != 0 { w.WriteHeader(tc.expectedStatus) } - fmt.Fprintf(w, tc.input) + fmt.Fprint(w, tc.input) })) params := []pipelinev1.Param{} if tc.paramSet { @@ -328,7 +328,7 @@ func TestResolverReconcileBasicAuth(t *testing.T) { resolver := &Resolver{} ctx, _ := ttesting.SetupFakeContext(t) svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, tt.taskContent) + fmt.Fprint(w, tt.taskContent) })) p := tt.params if p == nil { diff --git a/pkg/remoteresolution/resolver/hub/resolver_test.go b/pkg/remoteresolution/resolver/hub/resolver_test.go index bb5f7d19bff..da8f4ea2021 100644 --- a/pkg/remoteresolution/resolver/hub/resolver_test.go +++ b/pkg/remoteresolution/resolver/hub/resolver_test.go @@ -93,6 +93,7 @@ func TestValidate(t *testing.T) { }) } } + func TestValidateMissing(t *testing.T) { resolver := Resolver{} @@ -244,7 +245,7 @@ func TestResolve(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, tc.input) + fmt.Fprint(w, tc.input) })) resolver := &Resolver{ diff --git a/pkg/resolution/resolver/http/resolver_test.go b/pkg/resolution/resolver/http/resolver_test.go index dddfab29dbf..960fd8614fc 100644 --- a/pkg/resolution/resolver/http/resolver_test.go +++ b/pkg/resolution/resolver/http/resolver_test.go @@ -181,7 +181,7 @@ func TestResolve(t *testing.T) { if tc.expectedStatus != 0 { w.WriteHeader(tc.expectedStatus) } - fmt.Fprintf(w, tc.input) + fmt.Fprint(w, tc.input) })) params := []pipelinev1.Param{} if tc.paramSet { @@ -396,7 +396,7 @@ func TestResolverReconcileBasicAuth(t *testing.T) { resolver := &Resolver{} ctx, _ := ttesting.SetupFakeContext(t) svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, tt.taskContent) + fmt.Fprint(w, tt.taskContent) })) p := tt.params if p == nil { diff --git a/pkg/resolution/resolver/hub/resolver_test.go b/pkg/resolution/resolver/hub/resolver_test.go index 918d3a8d521..82335875d7d 100644 --- a/pkg/resolution/resolver/hub/resolver_test.go +++ b/pkg/resolution/resolver/hub/resolver_test.go @@ -346,7 +346,7 @@ func TestResolveConstraint(t *testing.T) { ret = tt.resultTask } output, _ := json.Marshal(ret) - fmt.Fprintf(w, string(output)) + fmt.Fprint(w, string(output)) })) resolver := &Resolver{ @@ -582,7 +582,7 @@ func TestResolve(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, tc.input) + fmt.Fprint(w, tc.input) })) resolver := &Resolver{ diff --git a/pkg/result/result_test.go b/pkg/result/result_test.go index 34654ec3f0c..fbd26b3712e 100644 --- a/pkg/result/result_test.go +++ b/pkg/result/result_test.go @@ -29,32 +29,38 @@ func TestRunResult_UnmarshalJSON(t *testing.T) { name string data string pr RunResult - }{{ - name: "type defined as string - TaskRunResult", - data: "{\"key\":\"resultName\",\"value\":\"resultValue\", \"type\": \"TaskRunResult\"}", - pr: RunResult{Key: "resultName", Value: "resultValue", ResultType: TaskRunResultType}, - }, { - name: "type defined as string - StepResult", - data: "{\"key\":\"resultName\",\"value\":\"resultValue\", \"type\": \"StepResult\"}", - pr: RunResult{Key: "resultName", Value: "resultValue", ResultType: StepResultType}, - }, + }{ + { + name: "type defined as string - TaskRunResult", + data: "{\"key\":\"resultName\",\"value\":\"resultValue\", \"type\": \"TaskRunResult\"}", + pr: RunResult{Key: "resultName", Value: "resultValue", ResultType: TaskRunResultType}, + }, + { + name: "type defined as string - StepResult", + data: "{\"key\":\"resultName\",\"value\":\"resultValue\", \"type\": \"StepResult\"}", + pr: RunResult{Key: "resultName", Value: "resultValue", ResultType: StepResultType}, + }, { name: "type defined as string - InternalTektonResult", data: "{\"key\":\"resultName\",\"value\":\"\", \"type\": \"InternalTektonResult\"}", pr: RunResult{Key: "resultName", Value: "", ResultType: InternalTektonResultType}, - }, { + }, + { name: "type defined as string - StepArtifactsResultType", data: "{\"key\":\"resultName\",\"value\":\"\", \"type\": \"StepArtifactsResult\"}", pr: RunResult{Key: "resultName", Value: "", ResultType: StepArtifactsResultType}, - }, { + }, + { name: "type defined as string - TaskRunArtifactResult", data: "{\"key\":\"resultName\",\"value\":\"\", \"type\": \"TaskRunArtifactsResult\"}", pr: RunResult{Key: "resultName", Value: "", ResultType: TaskRunArtifactsResultType}, - }, { + }, + { name: "type defined as int", data: "{\"key\":\"resultName\",\"value\":\"\", \"type\": 1}", pr: RunResult{Key: "resultName", Value: "", ResultType: TaskRunResultType}, - }} + }, + } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { @@ -63,7 +69,7 @@ func TestRunResult_UnmarshalJSON(t *testing.T) { t.Errorf("Unexpected error when unmarshalling the json into RunResult") } if d := cmp.Diff(tc.pr, pipRes); d != "" { - t.Errorf(diff.PrintWantGot(d)) + t.Error(diff.PrintWantGot(d)) } }) } diff --git a/test/gohelloworld/main.go b/test/gohelloworld/main.go index 8c0bd0f8a5b..2cfe8f5a3ef 100644 --- a/test/gohelloworld/main.go +++ b/test/gohelloworld/main.go @@ -31,8 +31,7 @@ func main() { log.Print("Hello world sample started.") http.HandleFunc("/", handler) - //nolint:gosec - // #nosec G114 -- see https://github.com/securego/gosec#available-rules + //nolint: gosec if err := http.ListenAndServe(":8080", nil); err != nil { panic(err) } diff --git a/test/util.go b/test/util.go index 99e005a86b4..e1254e2edb1 100644 --- a/test/util.go +++ b/test/util.go @@ -92,9 +92,9 @@ func header(t *testing.T, text string) { right := " ###" txt := left + text + right bar := strings.Repeat("#", len(txt)) - t.Logf(bar) - t.Logf(txt) - t.Logf(bar) + t.Log(bar) + t.Log(txt) + t.Log(bar) } func tearDown(ctx context.Context, t *testing.T, cs *clients, namespace string) { diff --git a/tools/go.mod b/tools/go.mod index 5bb3fb544bd..d30514f33d7 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -1,6 +1,7 @@ module github.com/tektoncd/pipeline/tools -go 1.22 +go 1.22.1 + toolchain go1.22.5 require github.com/golangci/golangci-lint v1.60.3