Skip to content

Commit

Permalink
Fixing linting issue with updates…
Browse files Browse the repository at this point in the history
This mainly fixes printf/errorf/fatalf not using formatting.

Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester authored and tekton-robot committed Aug 26, 2024
1 parent 1c0367d commit 78d1f11
Show file tree
Hide file tree
Showing 32 changed files with 431 additions and 324 deletions.
1 change: 1 addition & 0 deletions cmd/entrypoint/subcommands/subcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
}
Expand Down
31 changes: 19 additions & 12 deletions internal/sidecarlogresults/sidecarlogresults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
}
Expand Down Expand Up @@ -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))
}
})
}
Expand Down Expand Up @@ -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))
}
})
}
Expand Down Expand Up @@ -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":[
Expand Down Expand Up @@ -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
Expand All @@ -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{{
Expand Down Expand Up @@ -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))
}
})
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/apis/pipeline/v1/param_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -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))
}
})
}
Expand Down Expand Up @@ -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))
}
})
}
Expand All @@ -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))
}
})
}
Expand Down Expand Up @@ -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))
}
})
}
Expand Down Expand Up @@ -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))
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pipeline/v1/result_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
}
Expand All @@ -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)
Expand Down
75 changes: 39 additions & 36 deletions pkg/apis/pipeline/v1/resultref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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[*]",
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1/taskrun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
}
Expand Down Expand Up @@ -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))
}
})
}
Expand Down Expand Up @@ -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))
}
})
}
Expand Down Expand Up @@ -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))
}
})
}
Expand Down
Loading

0 comments on commit 78d1f11

Please sign in to comment.