chore(pkg): enable perfsprint linter

#### Description

enable perfsprint linter in pkg/cmd

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
pull/31876/head
Matthieu MOREL 2 weeks ago
parent bd334848b4
commit 6c2cb2f547

@ -384,7 +384,7 @@ func TestInstallRelease_WithNotesRendered(t *testing.T) {
rel, err := releaserToV1Release(r)
is.NoError(err)
expectedNotes := fmt.Sprintf("got-%s", res.Name)
expectedNotes := "got-" + res.Name
is.Equal(expectedNotes, rel.Info.Notes)
is.Equal(rel.Info.Description, "Install complete")
}
@ -571,7 +571,7 @@ func TestInstallRelease_FailedHooks(t *testing.T) {
instAction := installAction(t)
instAction.ReleaseName = "failed-hooks"
failer := instAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.WatchUntilReadyError = fmt.Errorf("Failed watch")
failer.WatchUntilReadyError = errors.New("Failed watch")
instAction.cfg.KubeClient = failer
outBuffer := &bytes.Buffer{}
failer.PrintingKubeClient = kubefake.PrintingKubeClient{Out: io.Discard, LogOutput: outBuffer}
@ -633,7 +633,7 @@ func TestInstallRelease_Wait(t *testing.T) {
instAction := installAction(t)
instAction.ReleaseName = "come-fail-away"
failer := instAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.WaitError = fmt.Errorf("I timed out")
failer.WaitError = errors.New("I timed out")
instAction.cfg.KubeClient = failer
instAction.WaitStrategy = kube.StatusWatcherStrategy
vals := map[string]any{}
@ -677,7 +677,7 @@ func TestInstallRelease_WaitForJobs(t *testing.T) {
instAction := installAction(t)
instAction.ReleaseName = "come-fail-away"
failer := instAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.WaitError = fmt.Errorf("I timed out")
failer.WaitError = errors.New("I timed out")
instAction.cfg.KubeClient = failer
instAction.WaitStrategy = kube.StatusWatcherStrategy
instAction.WaitForJobs = true
@ -698,7 +698,7 @@ func TestInstallRelease_RollbackOnFailure(t *testing.T) {
instAction := installAction(t)
instAction.ReleaseName = "come-fail-away"
failer := instAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.WaitError = fmt.Errorf("I timed out")
failer.WaitError = errors.New("I timed out")
instAction.cfg.KubeClient = failer
instAction.RollbackOnFailure = true
// disabling hooks to avoid an early fail when
@ -723,8 +723,8 @@ func TestInstallRelease_RollbackOnFailure(t *testing.T) {
instAction := installAction(t)
instAction.ReleaseName = "come-fail-away-with-me"
failer := instAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.WaitError = fmt.Errorf("I timed out")
failer.DeleteError = fmt.Errorf("uninstall fail")
failer.WaitError = errors.New("I timed out")
failer.DeleteError = errors.New("uninstall fail")
instAction.cfg.KubeClient = failer
instAction.RollbackOnFailure = true
vals := map[string]any{}

@ -91,7 +91,7 @@ func TestUpgradeRelease_Wait(t *testing.T) {
require.NoError(t, upAction.cfg.Releases.Create(rel))
failer := upAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.WaitError = fmt.Errorf("I timed out")
failer.WaitError = errors.New("I timed out")
upAction.cfg.KubeClient = failer
upAction.WaitStrategy = kube.StatusWatcherStrategy
vals := map[string]any{}
@ -115,7 +115,7 @@ func TestUpgradeRelease_WaitForJobs(t *testing.T) {
require.NoError(t, upAction.cfg.Releases.Create(rel))
failer := upAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.WaitError = fmt.Errorf("I timed out")
failer.WaitError = errors.New("I timed out")
upAction.cfg.KubeClient = failer
upAction.WaitStrategy = kube.StatusWatcherStrategy
upAction.WaitForJobs = true
@ -140,8 +140,8 @@ func TestUpgradeRelease_CleanupOnFail(t *testing.T) {
require.NoError(t, upAction.cfg.Releases.Create(rel))
failer := upAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.WaitError = fmt.Errorf("I timed out")
failer.DeleteError = fmt.Errorf("I tried to delete nil")
failer.WaitError = errors.New("I timed out")
failer.DeleteError = errors.New("I tried to delete nil")
upAction.cfg.KubeClient = failer
upAction.WaitStrategy = kube.StatusWatcherStrategy
upAction.CleanupOnFail = true
@ -170,7 +170,7 @@ func TestUpgradeRelease_RollbackOnFailure(t *testing.T) {
failer := upAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
// We can't make Update error because then the rollback won't work
failer.WatchUntilReadyError = fmt.Errorf("arming key removed")
failer.WatchUntilReadyError = errors.New("arming key removed")
upAction.cfg.KubeClient = failer
upAction.RollbackOnFailure = true
vals := map[string]any{}
@ -199,7 +199,7 @@ func TestUpgradeRelease_RollbackOnFailure(t *testing.T) {
require.NoError(t, upAction.cfg.Releases.Create(rel))
failer := upAction.cfg.KubeClient.(*kubefake.FailingKubeClient)
failer.UpdateError = fmt.Errorf("update fail")
failer.UpdateError = errors.New("update fail")
upAction.cfg.KubeClient = failer
upAction.RollbackOnFailure = true
vals := map[string]any{}

@ -291,27 +291,27 @@ func TestInstallVersionCompletion(t *testing.T) {
tests := []cmdTestCase{{
name: "completion for install version flag with release name",
cmd: fmt.Sprintf("%s __complete install releasename testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete install releasename testing/alpine --version ''",
golden: "output/version-comp.txt",
}, {
name: "completion for install version flag with generate-name",
cmd: fmt.Sprintf("%s __complete install --generate-name testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete install --generate-name testing/alpine --version ''",
golden: "output/version-comp.txt",
}, {
name: "completion for install version flag, no filter",
cmd: fmt.Sprintf("%s __complete install releasename testing/alpine --version 0.3", repoSetup),
cmd: repoSetup + " __complete install releasename testing/alpine --version 0.3",
golden: "output/version-comp.txt",
}, {
name: "completion for install version flag too few args",
cmd: fmt.Sprintf("%s __complete install testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete install testing/alpine --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for install version flag too many args",
cmd: fmt.Sprintf("%s __complete install releasename testing/alpine badarg --version ''", repoSetup),
cmd: repoSetup + " __complete install releasename testing/alpine badarg --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for install version flag invalid chart",
cmd: fmt.Sprintf("%s __complete install releasename invalid/invalid --version ''", repoSetup),
cmd: repoSetup + " __complete install releasename invalid/invalid --version ''",
golden: "output/version-invalid-comp.txt",
}}
runTestCmd(t, tests)

@ -25,12 +25,12 @@ func TestLintCmdWithSubchartsFlag(t *testing.T) {
testChart := "testdata/testcharts/chart-with-bad-subcharts"
tests := []cmdTestCase{{
name: "lint good chart with bad subcharts",
cmd: fmt.Sprintf("lint %s", testChart),
cmd: "lint " + testChart,
golden: "output/lint-chart-with-bad-subcharts.txt",
wantError: true,
}, {
name: "lint good chart with bad subcharts using --with-subcharts flag",
cmd: fmt.Sprintf("lint --with-subcharts %s", testChart),
cmd: "lint --with-subcharts " + testChart,
golden: "output/lint-chart-with-bad-subcharts-with-subcharts.txt",
wantError: true,
}}
@ -42,7 +42,7 @@ func TestLintCmdWithQuietFlag(t *testing.T) {
testChart2 := "testdata/testcharts/chart-bad-requirements"
tests := []cmdTestCase{{
name: "lint good chart using --quiet flag",
cmd: fmt.Sprintf("lint --quiet %s", testChart1),
cmd: "lint --quiet " + testChart1,
golden: "output/lint-quiet.txt",
}, {
name: "lint two charts, one with error using --quiet flag",
@ -67,24 +67,24 @@ func TestLintCmdWithKubeVersionFlag(t *testing.T) {
testChart := "testdata/testcharts/chart-with-deprecated-api"
tests := []cmdTestCase{{
name: "lint chart with deprecated api version using kube version flag",
cmd: fmt.Sprintf("lint --kube-version 1.22.0 %s", testChart),
cmd: "lint --kube-version 1.22.0 " + testChart,
golden: "output/lint-chart-with-deprecated-api.txt",
wantError: false,
}, {
name: "lint chart with deprecated api version using kube version and strict flag",
cmd: fmt.Sprintf("lint --kube-version 1.22.0 --strict %s", testChart),
cmd: "lint --kube-version 1.22.0 --strict " + testChart,
golden: "output/lint-chart-with-deprecated-api-strict.txt",
wantError: true,
}, {
// the test builds will use the kubeVersionMinorTesting const in capabilities.go
// which is "20"
name: "lint chart with deprecated api version without kube version",
cmd: fmt.Sprintf("lint %s", testChart),
cmd: "lint " + testChart,
golden: "output/lint-chart-with-deprecated-api-old-k8s.txt",
wantError: false,
}, {
name: "lint chart with deprecated api version with older kube version",
cmd: fmt.Sprintf("lint --kube-version 1.21.0 --strict %s", testChart),
cmd: "lint --kube-version 1.21.0 --strict " + testChart,
golden: "output/lint-chart-with-deprecated-api-old-k8s.txt",
wantError: false,
}}

@ -342,7 +342,7 @@ func runPullTests(t *testing.T, tests []struct {
func buildOCIURL(registryURL, chartName, version, username, password string) string {
baseURL := fmt.Sprintf("oci://%s/u/ocitestuser/%s", registryURL, chartName)
if version != "" {
baseURL += fmt.Sprintf(" --version %s", version)
baseURL += " --version " + version
}
if username != "" && password != "" {
baseURL += fmt.Sprintf(" --username %s --password %s", username, password)
@ -416,23 +416,23 @@ func TestPullVersionCompletion(t *testing.T) {
tests := []cmdTestCase{{
name: "completion for pull version flag",
cmd: fmt.Sprintf("%s __complete pull testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete pull testing/alpine --version ''",
golden: "output/version-comp.txt",
}, {
name: "completion for pull version flag, no filter",
cmd: fmt.Sprintf("%s __complete pull testing/alpine --version 0.3", repoSetup),
cmd: repoSetup + " __complete pull testing/alpine --version 0.3",
golden: "output/version-comp.txt",
}, {
name: "completion for pull version flag too few args",
cmd: fmt.Sprintf("%s __complete pull --version ''", repoSetup),
cmd: repoSetup + " __complete pull --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for pull version flag too many args",
cmd: fmt.Sprintf("%s __complete pull testing/alpine badarg --version ''", repoSetup),
cmd: repoSetup + " __complete pull testing/alpine badarg --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for pull version flag invalid chart",
cmd: fmt.Sprintf("%s __complete pull invalid/invalid --version ''", repoSetup),
cmd: repoSetup + " __complete pull invalid/invalid --version ''",
golden: "output/version-invalid-comp.txt",
}}
runTestCmd(t, tests)

@ -99,35 +99,35 @@ func TestShowVersionCompletion(t *testing.T) {
tests := []cmdTestCase{{
name: "completion for show version flag",
cmd: fmt.Sprintf("%s __complete show chart testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete show chart testing/alpine --version ''",
golden: "output/version-comp.txt",
}, {
name: "completion for show version flag, no filter",
cmd: fmt.Sprintf("%s __complete show chart testing/alpine --version 0.3", repoSetup),
cmd: repoSetup + " __complete show chart testing/alpine --version 0.3",
golden: "output/version-comp.txt",
}, {
name: "completion for show version flag too few args",
cmd: fmt.Sprintf("%s __complete show chart --version ''", repoSetup),
cmd: repoSetup + " __complete show chart --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for show version flag too many args",
cmd: fmt.Sprintf("%s __complete show chart testing/alpine badarg --version ''", repoSetup),
cmd: repoSetup + " __complete show chart testing/alpine badarg --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for show version flag invalid chart",
cmd: fmt.Sprintf("%s __complete show chart invalid/invalid --version ''", repoSetup),
cmd: repoSetup + " __complete show chart invalid/invalid --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for show version flag with all",
cmd: fmt.Sprintf("%s __complete show all testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete show all testing/alpine --version ''",
golden: "output/version-comp.txt",
}, {
name: "completion for show version flag with readme",
cmd: fmt.Sprintf("%s __complete show readme testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete show readme testing/alpine --version ''",
golden: "output/version-comp.txt",
}, {
name: "completion for show version flag with values",
cmd: fmt.Sprintf("%s __complete show values testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete show values testing/alpine --version ''",
golden: "output/version-comp.txt",
}}
runTestCmd(t, tests)

@ -178,23 +178,23 @@ func TestTemplateVersionCompletion(t *testing.T) {
tests := []cmdTestCase{{
name: "completion for template version flag with release name",
cmd: fmt.Sprintf("%s __complete template releasename testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete template releasename testing/alpine --version ''",
golden: "output/version-comp.txt",
}, {
name: "completion for template version flag with generate-name",
cmd: fmt.Sprintf("%s __complete template --generate-name testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete template --generate-name testing/alpine --version ''",
golden: "output/version-comp.txt",
}, {
name: "completion for template version flag too few args",
cmd: fmt.Sprintf("%s __complete template testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete template testing/alpine --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for template version flag too many args",
cmd: fmt.Sprintf("%s __complete template releasename testing/alpine badarg --version ''", repoSetup),
cmd: repoSetup + " __complete template releasename testing/alpine badarg --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for template version flag invalid chart",
cmd: fmt.Sprintf("%s __complete template releasename invalid/invalid --version ''", repoSetup),
cmd: repoSetup + " __complete template releasename invalid/invalid --version ''",
golden: "output/version-invalid-comp.txt",
}}
runTestCmd(t, tests)

@ -149,7 +149,7 @@ func TestUpgradeCmd(t *testing.T) {
},
{
name: "upgrade a release with missing dependencies",
cmd: fmt.Sprintf("upgrade bonkers-bunny %s", missingDepsPath),
cmd: "upgrade bonkers-bunny " + missingDepsPath,
golden: "output/upgrade-with-missing-dependencies.txt",
wantError: true,
},
@ -161,7 +161,7 @@ func TestUpgradeCmd(t *testing.T) {
},
{
name: "upgrade a release with resolving missing dependencies",
cmd: fmt.Sprintf("upgrade --dependency-update funny-bunny %s", presentDepsPath),
cmd: "upgrade --dependency-update funny-bunny " + presentDepsPath,
golden: "output/upgrade-with-dependency-update.txt",
rels: []*release.Release{relMock("funny-bunny", 2, ch2)},
},
@ -443,23 +443,23 @@ func TestUpgradeVersionCompletion(t *testing.T) {
tests := []cmdTestCase{{
name: "completion for upgrade version flag",
cmd: fmt.Sprintf("%s __complete upgrade releasename testing/alpine --version ''", repoSetup),
cmd: repoSetup + " __complete upgrade releasename testing/alpine --version ''",
golden: "output/version-comp.txt",
}, {
name: "completion for upgrade version flag, no filter",
cmd: fmt.Sprintf("%s __complete upgrade releasename testing/alpine --version 0.3", repoSetup),
cmd: repoSetup + " __complete upgrade releasename testing/alpine --version 0.3",
golden: "output/version-comp.txt",
}, {
name: "completion for upgrade version flag too few args",
cmd: fmt.Sprintf("%s __complete upgrade releasename --version ''", repoSetup),
cmd: repoSetup + " __complete upgrade releasename --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for upgrade version flag too many args",
cmd: fmt.Sprintf("%s __complete upgrade releasename testing/alpine badarg --version ''", repoSetup),
cmd: repoSetup + " __complete upgrade releasename testing/alpine badarg --version ''",
golden: "output/version-invalid-comp.txt",
}, {
name: "completion for upgrade version flag invalid chart",
cmd: fmt.Sprintf("%s __complete upgrade releasename invalid/invalid --version ''", repoSetup),
cmd: repoSetup + " __complete upgrade releasename invalid/invalid --version ''",
golden: "output/version-invalid-comp.txt",
}}
runTestCmd(t, tests)
@ -636,7 +636,7 @@ func TestUpgradeInstallServerSideApply(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
store := storageFixture()
releaseName := fmt.Sprintf("ssa-test-%s", tt.expectedApplyMethod)
releaseName := "ssa-test-" + tt.expectedApplyMethod
cmd := fmt.Sprintf("upgrade %s --install %s '%s'", releaseName, tt.serverSideFlag, chartPath)
_, _, err := executeActionCommandC(store, cmd)

@ -277,7 +277,7 @@ type ClientCreateOption func(*clientCreateOptions) error
func ClientCreateOptionServerSideApply(serverSideApply, forceConflicts bool) ClientCreateOption {
return func(o *clientCreateOptions) error {
if !serverSideApply && forceConflicts {
return fmt.Errorf("forceConflicts enabled when serverSideApply disabled")
return errors.New("forceConflicts enabled when serverSideApply disabled")
}
o.serverSideApply = serverSideApply
@ -727,7 +727,7 @@ func ClientUpdateOptionThreeWayMergeForUnstructured(threeWayMergeForUnstructured
func ClientUpdateOptionServerSideApply(serverSideApply, forceConflicts bool) ClientUpdateOption {
return func(o *clientUpdateOptions) error {
if !serverSideApply && forceConflicts {
return fmt.Errorf("forceConflicts enabled when serverSideApply disabled")
return errors.New("forceConflicts enabled when serverSideApply disabled")
}
o.serverSideApply = serverSideApply
@ -811,15 +811,15 @@ func (c *Client) Update(originals, targets ResourceList, options ...ClientUpdate
}
if updateOptions.threeWayMergeForUnstructured && updateOptions.serverSideApply {
return &Result{}, fmt.Errorf("invalid operation: cannot use three-way merge for unstructured and server-side apply together")
return &Result{}, errors.New("invalid operation: cannot use three-way merge for unstructured and server-side apply together")
}
if updateOptions.forceConflicts && updateOptions.forceReplace {
return &Result{}, fmt.Errorf("invalid operation: cannot use force conflicts and force replace together")
return &Result{}, errors.New("invalid operation: cannot use force conflicts and force replace together")
}
if updateOptions.serverSideApply && updateOptions.forceReplace {
return &Result{}, fmt.Errorf("invalid operation: cannot use server-side apply and force replace together")
return &Result{}, errors.New("invalid operation: cannot use server-side apply and force replace together")
}
createApplyFunc := c.makeCreateApplyFunc(

@ -715,7 +715,7 @@ func setupRestrictedClient(fakeClient *dynamicfake.FakeDynamicClient, allowedNam
return true, nil, apierrors.NewForbidden(
action.GetResource().GroupResource(),
"",
fmt.Errorf("user does not have cluster-wide LIST permissions for cluster-scoped resources"),
errors.New("user does not have cluster-wide LIST permissions for cluster-scoped resources"),
)
}
if !config.allowedNamespaces[ns] {
@ -739,7 +739,7 @@ func setupRestrictedClient(fakeClient *dynamicfake.FakeDynamicClient, allowedNam
return true, nil, apierrors.NewForbidden(
action.GetResource().GroupResource(),
"",
fmt.Errorf("user does not have cluster-wide WATCH permissions for cluster-scoped resources"),
errors.New("user does not have cluster-wide WATCH permissions for cluster-scoped resources"),
)
}
if !config.allowedNamespaces[ns] {
@ -793,7 +793,7 @@ func TestStatusWaitRestrictedRBAC(t *testing.T) {
name: "error when cluster-scoped resource included",
objManifests: []string{podNamespace1Manifest, clusterRoleManifest},
allowedNamespaces: []string{"namespace-1"},
expectErrs: []error{fmt.Errorf("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
expectErrs: []error{errors.New("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
testFunc: func(sw *statusWaiter, rl ResourceList, timeout time.Duration) error {
return sw.Wait(rl, timeout)
},
@ -802,7 +802,7 @@ func TestStatusWaitRestrictedRBAC(t *testing.T) {
name: "error when deleting cluster-scoped resource",
objManifests: []string{podNamespace1Manifest, namespaceManifest},
allowedNamespaces: []string{"namespace-1"},
expectErrs: []error{fmt.Errorf("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
expectErrs: []error{errors.New("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
testFunc: func(sw *statusWaiter, rl ResourceList, timeout time.Duration) error {
return sw.WaitForDelete(rl, timeout)
},
@ -892,7 +892,7 @@ func TestStatusWaitMixedResources(t *testing.T) {
name: "wait fails when cluster-scoped resource included",
objManifests: []string{podNamespace1Manifest, clusterRoleManifest},
allowedNamespaces: []string{"namespace-1"},
expectErrs: []error{fmt.Errorf("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
expectErrs: []error{errors.New("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
testFunc: func(sw *statusWaiter, rl ResourceList, timeout time.Duration) error {
return sw.Wait(rl, timeout)
},
@ -901,7 +901,7 @@ func TestStatusWaitMixedResources(t *testing.T) {
name: "waitForDelete fails when cluster-scoped resource included",
objManifests: []string{podNamespace1Manifest, clusterRoleManifest},
allowedNamespaces: []string{"namespace-1"},
expectErrs: []error{fmt.Errorf("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
expectErrs: []error{errors.New("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
testFunc: func(sw *statusWaiter, rl ResourceList, timeout time.Duration) error {
return sw.WaitForDelete(rl, timeout)
},
@ -910,7 +910,7 @@ func TestStatusWaitMixedResources(t *testing.T) {
name: "wait fails when namespace resource included",
objManifests: []string{podNamespace1Manifest, namespaceManifest},
allowedNamespaces: []string{"namespace-1"},
expectErrs: []error{fmt.Errorf("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
expectErrs: []error{errors.New("user does not have cluster-wide LIST permissions for cluster-scoped resources")},
testFunc: func(sw *statusWaiter, rl ResourceList, timeout time.Duration) error {
return sw.Wait(rl, timeout)
},

Loading…
Cancel
Save