Skip to content

Commit

Permalink
Hygiene: enable exhaustive linter.
Browse files Browse the repository at this point in the history
The [exhaustive](https://pkg.go.dev/github.com/nishanths/exhaustive)
linter checks exhaustiveness of switch statements, ensuring completeness
of case statements.

There are no expected functional changes in this CL.

Context: #5899
  • Loading branch information
bendory authored and tekton-robot committed Apr 10, 2023
1 parent f81fe39 commit 56be556
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ linters:
- errchkjson
- errname
- errorlint
- exhaustive
- goconst
- gocritic
- gofmt
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1/param_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ func (paramValues *ParamValue) ApplyReplacements(stringReplacements map[string]s
newObjectVal[k] = substitution.ApplyReplacements(v, stringReplacements)
}
paramValues.ObjectVal = newObjectVal
case ParamTypeString:
fallthrough
default:
paramValues.applyOrCorrect(stringReplacements, arrayReplacements, objectReplacements)
}
Expand Down Expand Up @@ -543,6 +545,8 @@ func validatePipelineParametersVariablesInTaskParameters(params Params, prefix s
for key, val := range param.Value.ObjectVal {
errs = errs.Also(validateStringVariable(val, prefix, paramNames, arrayParamNames, objectParamNameKeys).ViaFieldKey("properties", key).ViaFieldKey("params", param.Name))
}
case ParamTypeString:
fallthrough
default:
errs = errs.Also(validateParamStringValue(param, prefix, paramNames, arrayParamNames, objectParamNameKeys))
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ func ValidateParameterVariables(ctx context.Context, steps []Step, params []Para
arrayParameterNames.Insert(p.Name)
case ParamTypeObject:
objectParamSpecs = append(objectParamSpecs, p)
case ParamTypeString:
fallthrough
default:
stringParameterNames.Insert(p.Name)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1beta1/param_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ func (paramValues *ParamValue) ApplyReplacements(stringReplacements map[string]s
newObjectVal[k] = substitution.ApplyReplacements(v, stringReplacements)
}
paramValues.ObjectVal = newObjectVal
case ParamTypeString:
fallthrough
default:
paramValues.applyOrCorrect(stringReplacements, arrayReplacements, objectReplacements)
}
Expand Down Expand Up @@ -539,6 +541,8 @@ func validatePipelineParametersVariablesInTaskParameters(params Params, prefix s
for key, val := range param.Value.ObjectVal {
errs = errs.Also(validateStringVariable(val, prefix, paramNames, arrayParamNames, objectParamNameKeys).ViaFieldKey("properties", key).ViaFieldKey("params", param.Name))
}
case ParamTypeString:
fallthrough
default:
errs = errs.Also(validateParamStringValue(param, prefix, paramNames, arrayParamNames, objectParamNameKeys))
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/pipeline/v1beta1/task_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ func ValidateParameterVariables(ctx context.Context, steps []Step, params []Para
arrayParameterNames.Insert(p.Name)
case ParamTypeObject:
objectParamSpecs = append(objectParamSpecs, p)
case ParamTypeString:
fallthrough
default:
stringParameterNames.Insert(p.Name)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/credentials/dockercreds/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func (*basicDockerBuilder) MatchingAnnotations(secret *corev1.Secret) []string {
flags = append(flags, fmt.Sprintf("-docker-config=%s", secret.Name))
case corev1.SecretTypeDockercfg:
flags = append(flags, fmt.Sprintf("-docker-cfg=%s", secret.Name))

case corev1.SecretTypeOpaque, corev1.SecretTypeServiceAccountToken, corev1.SecretTypeSSHAuth, corev1.SecretTypeTLS, corev1.SecretTypeBootstrapToken:
return flags

default:
return flags
}
Expand Down
24 changes: 23 additions & 1 deletion pkg/credentials/dockercreds/creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,35 @@ func TestMatchingAnnotations(t *testing.T) {
"-basic-docker=ssh=keys2",
"-basic-docker=ssh=keys3",
},
}, {
secret: &corev1.Secret{
Type: corev1.SecretTypeDockercfg,
ObjectMeta: metav1.ObjectMeta{Name: "my-dockercfg"},
},
wantFlag: []string{"-docker-cfg=my-dockercfg"},
}, {
secret: &corev1.Secret{
Type: corev1.SecretTypeDockerConfigJson,
ObjectMeta: metav1.ObjectMeta{Name: "my-dockerconfigjson"},
},
wantFlag: []string{"-docker-config=my-dockerconfigjson"},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeOpaque},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeServiceAccountToken},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeTLS},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeBootstrapToken},
}, {
secret: &corev1.Secret{}, // An empty secret should result in no flags.
}}

nb := NewBuilder()
for _, ts := range tests {
gotFlag := nb.MatchingAnnotations(ts.secret)
if !cmp.Equal(ts.wantFlag, gotFlag) {
t.Errorf("MatchingAnnotations() Mismatch of flags; wanted: %v got: %v ", ts.wantFlag, gotFlag)
t.Errorf("Mismatch of flags for %v; want: %v got: %v ", ts.secret.Type, ts.wantFlag, gotFlag)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/credentials/gitcreds/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func (*gitConfigBuilder) MatchingAnnotations(secret *corev1.Secret) []string {
case corev1.SecretTypeSSHAuth:
flagName = sshFlag

case corev1.SecretTypeOpaque, corev1.SecretTypeServiceAccountToken, corev1.SecretTypeDockercfg, corev1.SecretTypeDockerConfigJson, corev1.SecretTypeTLS, corev1.SecretTypeBootstrapToken:
return flags

default:
return flags
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/credentials/gitcreds/creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,20 @@ func TestMatchingAnnotations(t *testing.T) {
},
},
wantFlag: []string{fmt.Sprintf("-%s=ssh=keys1", sshFlag), fmt.Sprintf("-%s=ssh=keys2", sshFlag), fmt.Sprintf("-%s=ssh=keys3", sshFlag)},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeOpaque},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeServiceAccountToken},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeDockercfg},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeDockerConfigJson},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeTLS},
}, {
secret: &corev1.Secret{Type: corev1.SecretTypeBootstrapToken},
}, {
secret: &corev1.Secret{}, // An empty secret should result in no flags.
}}

nb := NewBuilder()
Expand Down
2 changes: 2 additions & 0 deletions pkg/pod/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ func updateIncompleteTaskRunStatus(trs *v1beta1.TaskRunStatus, pod *corev1.Pod)
default:
markStatusRunning(trs, ReasonPending, getWaitingMessage(pod))
}
case corev1.PodSucceeded, corev1.PodFailed, corev1.PodUnknown:
// Do nothing; pod has completed or is in an unknown state.
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/reconciler/pipelinerun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func ApplyParameters(ctx context.Context, p *v1beta1.PipelineSpec, pr *v1beta1.P
for k, v := range p.Default.ObjectVal {
stringReplacements[fmt.Sprintf(objectIndividualVariablePattern, p.Name, k)] = v
}
case v1beta1.ParamTypeString:
fallthrough
default:
for _, pattern := range paramPatterns {
stringReplacements[fmt.Sprintf(pattern, p.Name)] = p.Default.StringVal
Expand Down Expand Up @@ -127,6 +129,8 @@ func paramsFromPipelineRun(ctx context.Context, pr *v1beta1.PipelineRun) (map[st
for k, v := range p.Value.ObjectVal {
stringReplacements[fmt.Sprintf(objectIndividualVariablePattern, p.Name, k)] = v
}
case v1beta1.ParamTypeString:
fallthrough
default:
for _, pattern := range paramPatterns {
stringReplacements[fmt.Sprintf(pattern, p.Name)] = p.Value.StringVal
Expand Down
2 changes: 2 additions & 0 deletions pkg/reconciler/pipelinerun/resources/resultrefresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ func (rs ResolvedResultRefs) getStringReplacements() map[string]string {
}
}

case v1beta1.ParamTypeString:
fallthrough
default:
for _, target := range r.getReplaceTarget() {
replacements[target] = r.Value.StringVal
Expand Down
4 changes: 4 additions & 0 deletions pkg/reconciler/taskrun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func ApplyParameters(ctx context.Context, spec *v1beta1.TaskSpec, tr *v1beta1.Ta
for k, v := range p.Default.ObjectVal {
stringReplacements[fmt.Sprintf(objectIndividualVariablePattern, p.Name, k)] = v
}
case v1beta1.ParamTypeString:
fallthrough
default:
for _, pattern := range paramPatterns {
stringReplacements[fmt.Sprintf(pattern, p.Name)] = p.Default.StringVal
Expand Down Expand Up @@ -115,6 +117,8 @@ func paramsFromTaskRun(ctx context.Context, tr *v1beta1.TaskRun) (map[string]str
for k, v := range p.Value.ObjectVal {
stringReplacements[fmt.Sprintf(objectIndividualVariablePattern, p.Name, k)] = v
}
case v1beta1.ParamTypeString:
fallthrough
default:
for _, pattern := range paramPatterns {
stringReplacements[fmt.Sprintf(pattern, p.Name)] = p.Value.StringVal
Expand Down

0 comments on commit 56be556

Please sign in to comment.