Skip to content

Commit

Permalink
Added govet linter.
Browse files Browse the repository at this point in the history
Also:
- fixed two minor issues uncovered by `go vet`:
  - cmd/nop/main.go:30:3: misuse of unbuffered os.Signal channel as argument to signal.Notify
  - internal/sidecarlogresults/sidecarlogresults_test.go:46:4: call to (*T).Fatal from a non-test goroutine
- fixed unkeyed composite literal fields in various _test.go files
  • Loading branch information
bendory authored and tekton-robot committed Dec 16, 2022
1 parent a68ab6b commit 30fe803
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Documentation: https://golangci-lint.run/usage/configuration/
linters-settings:
errcheck:
exclude: .errcheck.txt
Expand All @@ -21,11 +22,15 @@ linters:
- goimports
- gomodguard
- gosec
- govet
- gocritic
- revive
- misspell
- unconvert
- depguard
# To keep this PR small, I'm going to add one linter at a time.
#- unused
#- whitespace
output:
uniq-by-line: false
issues:
Expand Down
2 changes: 1 addition & 1 deletion cmd/nop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
func main() {
if len(os.Args) >= 2 && os.Args[1] == "tekton_run_indefinitely" {
log.Println("Waiting indefinitely...")
ch := make(chan os.Signal)
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
log.Println("received signal:", <-ch)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sidecarlogresults/sidecarlogresults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestLookForResults_FanOutAndWait(t *testing.T) {
wantResults = append(wantResults, encodedResult...)
}
dir2 := t.TempDir()
go createRun(t, dir2, false)
createRun(t, dir2, false)
got := new(bytes.Buffer)
err := LookForResults(got, dir2, dir, resultNames)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1/pipelinerun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestPipelineRun_Invalid(t *testing.T) {
},
Status: v1.PipelineRunStatus{
PipelineRunStatusFields: v1.PipelineRunStatusFields{
StartTime: &metav1.Time{time.Now()},
StartTime: &metav1.Time{Time: time.Now()},
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1alpha1/run_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func TestRunGetTimeOut(t *testing.T) {
name: "runWithTimeout",
run: v1alpha1.Run{
TypeMeta: metav1.TypeMeta{Kind: "kind", APIVersion: "apiVersion"},
Spec: v1alpha1.RunSpec{Timeout: &metav1.Duration{10 * time.Second}},
Spec: v1alpha1.RunSpec{Timeout: &metav1.Duration{Duration: 10 * time.Second}},
},
expectedValue: 10 * time.Second,
}}
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestRunHasTimedOut(t *testing.T) {
name: "runWithStartTimeAndTimeout",
run: v1alpha1.Run{
TypeMeta: metav1.TypeMeta{Kind: "kind", APIVersion: "apiVersion"},
Spec: v1alpha1.RunSpec{Timeout: &metav1.Duration{10 * time.Second}},
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)},
}}},
Expand All @@ -353,14 +353,14 @@ func TestRunHasTimedOut(t *testing.T) {
name: "runWithNoStartTimeAndTimeout",
run: v1alpha1.Run{
TypeMeta: metav1.TypeMeta{Kind: "kind", APIVersion: "apiVersion"},
Spec: v1alpha1.RunSpec{Timeout: &metav1.Duration{1 * time.Second}},
Spec: v1alpha1.RunSpec{Timeout: &metav1.Duration{Duration: 1 * time.Second}},
},
expectedValue: false,
}, {
name: "runWithStartTimeAndTimeout2",
run: v1alpha1.Run{
TypeMeta: metav1.TypeMeta{Kind: "kind", APIVersion: "apiVersion"},
Spec: v1alpha1.RunSpec{Timeout: &metav1.Duration{10 * time.Second}},
Spec: v1alpha1.RunSpec{Timeout: &metav1.Duration{Duration: 10 * time.Second}},
Status: v1alpha1.RunStatus{RunStatusFields: v1alpha1.RunStatusFields{
StartTime: &metav1.Time{Time: now},
}}},
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1beta1/customrun_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func TestRunGetTimeOut(t *testing.T) {
name: "runWithTimeout",
customRun: v1beta1.CustomRun{
TypeMeta: metav1.TypeMeta{Kind: "kind", APIVersion: "apiVersion"},
Spec: v1beta1.CustomRunSpec{Timeout: &metav1.Duration{10 * time.Second}},
Spec: v1beta1.CustomRunSpec{Timeout: &metav1.Duration{Duration: 10 * time.Second}},
},
expectedValue: 10 * time.Second,
}}
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestRunHasTimedOut(t *testing.T) {
name: "runWithStartTimeAndTimeout",
customRun: v1beta1.CustomRun{
TypeMeta: metav1.TypeMeta{Kind: "kind", APIVersion: "apiVersion"},
Spec: v1beta1.CustomRunSpec{Timeout: &metav1.Duration{10 * time.Second}},
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)},
}}},
Expand All @@ -348,14 +348,14 @@ func TestRunHasTimedOut(t *testing.T) {
name: "runWithNoStartTimeAndTimeout",
customRun: v1beta1.CustomRun{
TypeMeta: metav1.TypeMeta{Kind: "kind", APIVersion: "apiVersion"},
Spec: v1beta1.CustomRunSpec{Timeout: &metav1.Duration{1 * time.Second}},
Spec: v1beta1.CustomRunSpec{Timeout: &metav1.Duration{Duration: time.Second}},
},
expectedValue: false,
}, {
name: "runWithStartTimeAndTimeout2",
customRun: v1beta1.CustomRun{
TypeMeta: metav1.TypeMeta{Kind: "kind", APIVersion: "apiVersion"},
Spec: v1beta1.CustomRunSpec{Timeout: &metav1.Duration{10 * time.Second}},
Spec: v1beta1.CustomRunSpec{Timeout: &metav1.Duration{Duration: 10 * time.Second}},
Status: v1beta1.CustomRunStatus{CustomRunStatusFields: v1beta1.CustomRunStatusFields{
StartTime: &metav1.Time{Time: now},
}}},
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func TestPipelineRun_Invalid(t *testing.T) {
},
Status: v1beta1.PipelineRunStatus{
PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
StartTime: &metav1.Time{time.Now()},
StartTime: &metav1.Time{Time: time.Now()},
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/internal/affinityassistant/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestNewTransformerWithNodeAffinity(t *testing.T) {
Spec: corev1.PodSpec{
Affinity: &corev1.Affinity{PodAffinity: &corev1.PodAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{*podAffinityTerm},
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{{100, *podAffinityTerm}},
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{{Weight: 100, PodAffinityTerm: *podAffinityTerm}},
}},
},
},
Expand All @@ -186,7 +186,7 @@ func TestNewTransformerWithNodeAffinity(t *testing.T) {
TopologyKey: "kubernetes.io/hostname",
}},
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
{100, *podAffinityTerm},
{Weight: 100, PodAffinityTerm: *podAffinityTerm},
},
},
},
Expand All @@ -200,7 +200,7 @@ func TestNewTransformerWithNodeAffinity(t *testing.T) {
Affinity: &corev1.Affinity{
PodAffinity: &corev1.PodAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{*podAffinityTerm},
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{{100, *podAffinityTerm}},
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{{Weight: 100, PodAffinityTerm: *podAffinityTerm}},
},
NodeAffinity: nodeAffinity},
},
Expand All @@ -221,7 +221,7 @@ func TestNewTransformerWithNodeAffinity(t *testing.T) {
},
},
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
{100, *podAffinityTerm},
{Weight: 100, PodAffinityTerm: *podAffinityTerm},
},
},
NodeAffinity: nodeAffinity,
Expand Down
26 changes: 13 additions & 13 deletions test/custom_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func TestWaitCustomTask_Run(t *testing.T) {
}, {
name: "Wait Task Timed Out",
duration: "2s",
timeout: &metav1.Duration{time.Second},
timeout: &metav1.Duration{Duration: time.Second},
conditionAccessorFn: Failed,
wantCondition: apis.Condition{
Type: apis.ConditionSucceeded,
Expand All @@ -479,7 +479,7 @@ func TestWaitCustomTask_Run(t *testing.T) {
}, {
name: "Wait Task Retries on Timed Out",
duration: "2s",
timeout: &metav1.Duration{time.Second},
timeout: &metav1.Duration{Duration: time.Second},
retries: 2,
conditionAccessorFn: Failed,
wantCondition: apis.Condition{
Expand Down Expand Up @@ -617,7 +617,7 @@ func TestWaitCustomTask_PipelineRun(t *testing.T) {
}{{
name: "Wait Task Has Succeeded",
runDuration: "1s",
prTimeout: &metav1.Duration{time.Second * 60},
prTimeout: &metav1.Duration{Duration: time.Minute},
prConditionAccessorFn: Succeed,
wantPrCondition: apis.Condition{
Type: apis.ConditionSucceeded,
Expand All @@ -639,7 +639,7 @@ func TestWaitCustomTask_PipelineRun(t *testing.T) {
}, {
name: "Wait Task Is Running",
runDuration: "2s",
prTimeout: &metav1.Duration{time.Second * 5},
prTimeout: &metav1.Duration{Duration: time.Second * 5},
prConditionAccessorFn: Running,
wantPrCondition: apis.Condition{
Type: apis.ConditionSucceeded,
Expand All @@ -661,7 +661,7 @@ func TestWaitCustomTask_PipelineRun(t *testing.T) {
}, {
name: "Wait Task Failed When PipelineRun Is Timeout",
runDuration: "2s",
prTimeout: &metav1.Duration{time.Second},
prTimeout: &metav1.Duration{Duration: time.Second},
prConditionAccessorFn: Failed,
wantPrCondition: apis.Condition{
Type: apis.ConditionSucceeded,
Expand All @@ -683,7 +683,7 @@ func TestWaitCustomTask_PipelineRun(t *testing.T) {
}, {
name: "Wait Task Failed on Timeout",
runDuration: "2s",
runTimeout: &metav1.Duration{time.Second},
runTimeout: &metav1.Duration{Duration: time.Second},
prConditionAccessorFn: Failed,
wantPrCondition: apis.Condition{
Type: apis.ConditionSucceeded,
Expand All @@ -705,7 +705,7 @@ func TestWaitCustomTask_PipelineRun(t *testing.T) {
}, {
name: "Wait Task Retries on Timeout",
runDuration: "2s",
runTimeout: &metav1.Duration{time.Second},
runTimeout: &metav1.Duration{Duration: time.Second},
runRetries: 1,
prConditionAccessorFn: Failed,
wantPrCondition: apis.Condition{
Expand Down Expand Up @@ -742,7 +742,7 @@ func TestWaitCustomTask_PipelineRun(t *testing.T) {
}} {
t.Run(tc.name, func(t *testing.T) {
if tc.prTimeout == nil {
tc.prTimeout = &metav1.Duration{time.Second * 60}
tc.prTimeout = &metav1.Duration{Duration: time.Minute}
}
p := &v1beta1.Pipeline{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -905,7 +905,7 @@ func TestWaitCustomTask_V1Beta1_PipelineRun(t *testing.T) {
}{{
name: "Wait Task Has Succeeded",
customRunDuration: "1s",
prTimeout: &metav1.Duration{time.Second * 60},
prTimeout: &metav1.Duration{Duration: time.Minute},
prConditionAccessorFn: Succeed,
wantPrCondition: apis.Condition{
Type: apis.ConditionSucceeded,
Expand All @@ -927,7 +927,7 @@ func TestWaitCustomTask_V1Beta1_PipelineRun(t *testing.T) {
}, {
name: "Wait Task Is Running",
customRunDuration: "2s",
prTimeout: &metav1.Duration{time.Second * 5},
prTimeout: &metav1.Duration{Duration: time.Second * 5},
prConditionAccessorFn: Running,
wantPrCondition: apis.Condition{
Type: apis.ConditionSucceeded,
Expand Down Expand Up @@ -971,7 +971,7 @@ func TestWaitCustomTask_V1Beta1_PipelineRun(t *testing.T) {
}, {
name: "Wait Task Failed on Timeout",
customRunDuration: "2s",
customRunTimeout: &metav1.Duration{time.Second},
customRunTimeout: &metav1.Duration{Duration: time.Second},
prConditionAccessorFn: Failed,
wantPrCondition: apis.Condition{
Type: apis.ConditionSucceeded,
Expand All @@ -993,7 +993,7 @@ func TestWaitCustomTask_V1Beta1_PipelineRun(t *testing.T) {
}, {
name: "Wait Task Retries on Timeout",
customRunDuration: "2s",
customRunTimeout: &metav1.Duration{time.Second},
customRunTimeout: &metav1.Duration{Duration: time.Second},
customRunRetries: 1,
prConditionAccessorFn: Failed,
wantPrCondition: apis.Condition{
Expand Down Expand Up @@ -1030,7 +1030,7 @@ func TestWaitCustomTask_V1Beta1_PipelineRun(t *testing.T) {
}} {
t.Run(tc.name, func(t *testing.T) {
if tc.prTimeout == nil {
tc.prTimeout = &metav1.Duration{time.Second * 60}
tc.prTimeout = &metav1.Duration{Duration: time.Minute}
}
p := &v1beta1.Pipeline{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 30fe803

Please sign in to comment.