Merge pull request #32321 from mmorel-35/gocritic

refactor: enable several checks from gocritic
pull/32197/merge
George Jenkins 1 day ago committed by GitHub
commit 66c1232dc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -84,19 +84,14 @@ linters:
gocritic:
disabled-checks:
- appendAssign
- appendCombine
- assignOp
- badCall
- commentedOutCode
- commentFormatting
- deferInLoop
- elseif
- exposedSyncMutex
- filepathJoin
- hugeParam
- ifElseChain
- importShadow
- nilValReturn
- paramTypeCombine
- ptrToRefParam
- rangeValCopy

@ -26,7 +26,7 @@ import (
"helm.sh/helm/v4/internal/test/ensure"
)
var nonExistingValuesFilePath = filepath.Join("/fake/dir", "values.yaml")
var nonExistingValuesFilePath = filepath.FromSlash("/fake/dir/values.yaml")
const testSchema = `
{

@ -121,7 +121,7 @@ func TestCreate_Overwrite(t *testing.T) {
dir := filepath.Join(tdir, "foo")
tplname := filepath.Join(dir, "templates/hpa.yaml")
tplname := filepath.Join(dir, "templates", "hpa.yaml")
writeFile(tplname, []byte("FOO"))
// Now re-run the create

@ -64,7 +64,7 @@ func SplitManifests(bigFile string) map[string]string {
d = strings.TrimLeftFunc(d, unicode.IsSpace)
res[fmt.Sprintf(tpl, count)] = d
count = count + 1
count++
}
return res
}

@ -358,9 +358,9 @@ func TestCopyFileSymlink(t *testing.T) {
tempdir := t.TempDir()
testcases := map[string]string{
filepath.Join("./testdata/symlinks/file-symlink"): filepath.Join(tempdir, "dst-file"),
filepath.Join("./testdata/symlinks/windows-file-symlink"): filepath.Join(tempdir, "windows-dst-file"),
filepath.Join("./testdata/symlinks/invalid-symlink"): filepath.Join(tempdir, "invalid-symlink"),
filepath.Join(".", "testdata", "symlinks", "file-symlink"): filepath.Join(tempdir, "dst-file"),
filepath.Join(".", "testdata", "symlinks", "windows-file-symlink"): filepath.Join(tempdir, "windows-dst-file"),
filepath.Join(".", "testdata", "symlinks", "invalid-symlink"): filepath.Join(tempdir, "invalid-symlink"),
}
for symlink, dst := range testcases {

@ -201,7 +201,7 @@ func (d *Dependency) printDependencies(chartpath string, out io.Writer, c *chart
// printMissing prints warnings about charts that are present on disk, but are
// not in Chart.yaml.
func (d *Dependency) printMissing(chartpath string, out io.Writer, reqs []*chart.Dependency) {
folder := filepath.Join(chartpath, "charts/*")
folder := filepath.Join(chartpath, "charts", "*")
files, err := filepath.Glob(folder)
if err != nil {
fmt.Fprintln(out, err)

@ -868,21 +868,21 @@ func TestInstallReleaseOutputDir(t *testing.T) {
t.Fatalf("Failed install: %s", err)
}
_, err = os.Stat(filepath.Join(dir, "hello/templates/goodbye"))
_, err = os.Stat(filepath.Join(dir, "hello", "templates", "goodbye"))
req.NoError(err)
_, err = os.Stat(filepath.Join(dir, "hello/templates/hello"))
_, err = os.Stat(filepath.Join(dir, "hello", "templates", "hello"))
req.NoError(err)
_, err = os.Stat(filepath.Join(dir, "hello/templates/with-partials"))
_, err = os.Stat(filepath.Join(dir, "hello", "templates", "with-partials"))
req.NoError(err)
_, err = os.Stat(filepath.Join(dir, "hello/templates/rbac"))
_, err = os.Stat(filepath.Join(dir, "hello", "templates", "rbac"))
req.NoError(err)
test.AssertGoldenFile(t, filepath.Join(dir, "hello/templates/rbac"), "rbac.txt")
test.AssertGoldenFile(t, filepath.Join(dir, "hello", "templates", "rbac"), "rbac.txt")
_, err = os.Stat(filepath.Join(dir, "hello/templates/empty"))
_, err = os.Stat(filepath.Join(dir, "hello", "templates", "empty"))
is.ErrorIs(err, fs.ErrNotExist)
}
@ -905,21 +905,21 @@ func TestInstallOutputDirWithReleaseName(t *testing.T) {
t.Fatalf("Failed install: %s", err)
}
_, err = os.Stat(filepath.Join(newDir, "hello/templates/goodbye"))
_, err = os.Stat(filepath.Join(newDir, "hello", "templates", "goodbye"))
req.NoError(err)
_, err = os.Stat(filepath.Join(newDir, "hello/templates/hello"))
_, err = os.Stat(filepath.Join(newDir, "hello", "templates", "hello"))
req.NoError(err)
_, err = os.Stat(filepath.Join(newDir, "hello/templates/with-partials"))
_, err = os.Stat(filepath.Join(newDir, "hello", "templates", "with-partials"))
req.NoError(err)
_, err = os.Stat(filepath.Join(newDir, "hello/templates/rbac"))
_, err = os.Stat(filepath.Join(newDir, "hello", "templates", "rbac"))
req.NoError(err)
test.AssertGoldenFile(t, filepath.Join(newDir, "hello/templates/rbac"), "rbac.txt")
test.AssertGoldenFile(t, filepath.Join(newDir, "hello", "templates", "rbac"), "rbac.txt")
_, err = os.Stat(filepath.Join(newDir, "hello/templates/empty"))
_, err = os.Stat(filepath.Join(newDir, "hello", "templates", "empty"))
is.ErrorIs(err, fs.ErrNotExist)
}

@ -178,7 +178,7 @@ func (l *List) Run() ([]ri.Releaser, error) {
}
if results == nil {
return results, nil
return nil, nil
}
rresults, err := releaseListToV1List(results)

@ -26,7 +26,7 @@ import (
"helm.sh/helm/v4/internal/test/ensure"
)
var nonExistingValuesFilePath = filepath.Join("/fake/dir", "values.yaml")
var nonExistingValuesFilePath = filepath.FromSlash("/fake/dir/values.yaml")
const testSchema = `
{

@ -121,7 +121,7 @@ func TestCreate_Overwrite(t *testing.T) {
dir := filepath.Join(tdir, "foo")
tplname := filepath.Join(dir, "templates/hpa.yaml")
tplname := filepath.Join(dir, "templates", "hpa.yaml")
writeFile(tplname, []byte("FOO"))
// Now re-run the create

@ -72,7 +72,7 @@ func TestDependencyBuildCmd(t *testing.T) {
}
// Make sure the actual file got downloaded.
expect := filepath.Join(rootDir, chartname, "charts/reqtest-0.1.0.tgz")
expect := filepath.Join(rootDir, chartname, "charts", "reqtest-0.1.0.tgz")
if _, err := os.Stat(expect); err != nil {
t.Fatal(err)
}

@ -49,7 +49,7 @@ func TestRepoAddCmd(t *testing.T) {
)
defer srv2.Stop()
tmpdir := filepath.Join(t.TempDir(), "path-component.yaml/data")
tmpdir := filepath.Join(t.TempDir(), "path-component.yaml", "data")
if err := os.MkdirAll(tmpdir, 0o777); err != nil {
t.Fatal(err)
}

@ -171,7 +171,7 @@ func TestRepoRemoveCompletion(t *testing.T) {
rootDir := t.TempDir()
repoFile := filepath.Join(rootDir, "repositories.yaml")
repoCache := filepath.Join(rootDir, "cache/")
repoCache := filepath.Join(rootDir, "cache")
var testRepoNames = []string{"foo", "bar", "baz"}

@ -382,15 +382,15 @@ func compListCharts(toComplete string, includeFiles bool) ([]string, cobra.Shell
directive := cobra.ShellCompDirectiveDefault
if noFile {
directive = directive | cobra.ShellCompDirectiveNoFileComp
directive |= cobra.ShellCompDirectiveNoFileComp
}
if noSpace {
directive = directive | cobra.ShellCompDirectiveNoSpace
directive |= cobra.ShellCompDirectiveNoSpace
}
if !includeFiles {
// If we should not include files in the completions,
// we should disable file completion
directive = directive | cobra.ShellCompDirectiveNoFileComp
directive |= cobra.ShellCompDirectiveNoFileComp
}
return completions, directive
}

@ -76,7 +76,6 @@ func TestShowPreReleaseChart(t *testing.T) {
outdir,
contentTmp,
)
//_, out, err := executeActionCommand(cmd)
_, _, err := executeActionCommand(cmd)
if err != nil {
if tt.fail {

@ -40,7 +40,7 @@ func TestTemplateCmd(t *testing.T) {
},
{
name: "check values files",
cmd: fmt.Sprintf("template '%s' --values '%s'", chartPath, filepath.Join(chartPath, "/charts/subchartA/values.yaml")),
cmd: fmt.Sprintf("template '%s' --values '%s'", chartPath, filepath.Join(chartPath, "charts", "subchartA", "values.yaml")),
golden: "output/template-values-files.txt",
},
{

@ -117,6 +117,6 @@ func TestDiskCache_fileName(t *testing.T) {
cache := &DiskCache{Root: "/tmp/cache"}
key := sha256.Sum256([]byte("some data"))
assert.Equal(t, filepath.Join("/tmp/cache", "13", "1307990e6ba5ca145eb35e99182a9bec46531bc54ddf656a602c780fa0240dee.chart"), cache.fileName(key, CacheChart))
assert.Equal(t, filepath.Join("/tmp/cache", "13", "1307990e6ba5ca145eb35e99182a9bec46531bc54ddf656a602c780fa0240dee.prov"), cache.fileName(key, CacheProv))
assert.Equal(t, filepath.FromSlash("/tmp/cache/13/1307990e6ba5ca145eb35e99182a9bec46531bc54ddf656a602c780fa0240dee.chart"), cache.fileName(key, CacheChart))
assert.Equal(t, filepath.FromSlash("/tmp/cache/13/1307990e6ba5ca145eb35e99182a9bec46531bc54ddf656a602c780fa0240dee.prov"), cache.fileName(key, CacheProv))
}

@ -278,7 +278,7 @@ func TestDownloadTo_TLS(t *testing.T) {
getter.WithTLSClientConfig(
"",
"",
filepath.Join("../../testdata/rootca.crt"),
filepath.FromSlash("../../testdata/rootca.crt"),
),
},
}

@ -764,7 +764,7 @@ func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]*
}
url, err = repo.FindChartInRepoURL(repoURL, name, m.Getters, repo.WithChartVersion(version), repo.WithClientTLS(certFile, keyFile, caFile))
if err == nil {
return url, username, password, false, false, "", "", "", err
return url, username, password, false, false, "", "", "", nil
}
err = fmt.Errorf("chart %s not found in %s: %w", name, repoURL, err)
return url, username, password, false, false, "", "", "", err

@ -28,7 +28,7 @@ import (
)
func TestFuncs(t *testing.T) {
//TODO write tests for failure cases
// TODO write tests for failure cases
tests := []struct {
tpl, expect string
vars any

@ -225,7 +225,7 @@ func TestDownload(t *testing.T) {
// A different host is provided for the WithURL from the one used for Get
u2, _ := url.ParseRequestURI(crossAuthSrv.URL)
host := strings.Split(u2.Host, ":")
host[0] = host[0] + "a"
host[0] += "a"
u2.Host = strings.Join(host, ":")
httpgetter, err = NewHTTPGetter(
WithURL(u2.String()),
@ -260,7 +260,7 @@ func TestDownload(t *testing.T) {
// A different host is provided for the WithURL from the one used for Get
u2, _ = url.ParseRequestURI(crossAuthSrv.URL)
host = strings.Split(u2.Host, ":")
host[0] = host[0] + "a"
host[0] += "a"
u2.Host = strings.Join(host, ":")
httpgetter, err = NewHTTPGetter(
WithURL(u2.String()),

@ -38,7 +38,7 @@ func TestDataPath(t *testing.T) {
t.Setenv(xdg.DataHomeEnvVar, "/tmp")
expected = filepath.Join("/tmp", appName, testFile)
expected = filepath.FromSlash("/tmp/" + appName + "/" + testFile)
assert.Equal(t, expected, lazy.dataPath(testFile))
}
@ -50,7 +50,7 @@ func TestConfigPath(t *testing.T) {
t.Setenv(xdg.ConfigHomeEnvVar, "/tmp")
expected = filepath.Join("/tmp", appName, testFile)
expected = filepath.FromSlash("/tmp/" + appName + "/" + testFile)
assert.Equal(t, expected, lazy.configPath(testFile))
}
@ -62,7 +62,7 @@ func TestCachePath(t *testing.T) {
t.Setenv(xdg.CacheHomeEnvVar, "/tmp")
expected = filepath.Join("/tmp", appName, testFile)
expected = filepath.FromSlash("/tmp/" + appName + "/" + testFile)
assert.Equal(t, expected, lazy.cachePath(testFile))
}

@ -213,7 +213,7 @@ func Test_ReadyChecker_IsReady_Deployment(t *testing.T) {
wantErr: true,
},
{
name: "IsReady Deployments", //TODO fix this one
name: "IsReady Deployments", // TODO fix this one
fields: fields{
client: fake.NewClientset(),
checkJobs: true,

@ -76,7 +76,7 @@ func (suite *RegistryScopeTestSuite) Test_1_Check_Push_Request_Scope() {
_, err = suite.RegistryClient.Push(chartData, ref, PushOptCreationTime(testingChartCreationTime))
suite.Require().Error(err, "error pushing good ref because auth server doesn't give proper token")
//check the url that authentication server received
// check the url that authentication server received
select {
case urlStr := <-requestURL:
u, err := url.Parse(urlStr)
@ -122,7 +122,7 @@ func (suite *RegistryScopeTestSuite) Test_2_Check_Pull_Request_Scope() {
_, err = suite.RegistryClient.Pull(ref)
suite.Require().Error(err, "error pulling a simple chart because auth server doesn't give proper token")
//check the url that authentication server received
// check the url that authentication server received
select {
case urlStr := <-requestURL:
u, err := url.Parse(urlStr)

@ -150,7 +150,7 @@ func setup(suite *TestRegistry, tlsEnabled, insecure bool, auth string) {
suite.Require().NoError(err, "no error finding free port for test auth server")
defer ln.Close()
//set test auth server host
// set test auth server host
suite.AuthServerHost = ln.Addr().String()
config.Auth = configuration.Auth{

@ -64,7 +64,7 @@ func SplitManifests(bigFile string) map[string]string {
d = strings.TrimLeftFunc(d, unicode.IsSpace)
res[fmt.Sprintf(tpl, count)] = d
count = count + 1
count++
}
return res
}

@ -318,7 +318,7 @@ func IndexDirectory(dir, baseURL string) (*IndexFile, error) {
if err != nil {
return nil, err
}
moreArchives, err := filepath.Glob(filepath.Join(dir, "**/*.tgz"))
moreArchives, err := filepath.Glob(filepath.Join(dir, "**", "*.tgz"))
if err != nil {
return nil, err
}

@ -112,12 +112,14 @@ func TestSQLGet(t *testing.T) {
func TestSQLList(t *testing.T) {
releases := []*rspb.Release{}
releases = append(releases, releaseStub("key-1", 1, "default", common.StatusUninstalled))
releases = append(releases, releaseStub("key-2", 1, "default", common.StatusUninstalled))
releases = append(releases, releaseStub("key-3", 1, "default", common.StatusDeployed))
releases = append(releases, releaseStub("key-4", 1, "default", common.StatusDeployed))
releases = append(releases, releaseStub("key-5", 1, "default", common.StatusSuperseded))
releases = append(releases, releaseStub("key-6", 1, "default", common.StatusSuperseded))
releases = append(releases,
releaseStub("key-1", 1, "default", common.StatusUninstalled),
releaseStub("key-2", 1, "default", common.StatusUninstalled),
releaseStub("key-3", 1, "default", common.StatusDeployed),
releaseStub("key-4", 1, "default", common.StatusDeployed),
releaseStub("key-5", 1, "default", common.StatusSuperseded),
releaseStub("key-6", 1, "default", common.StatusSuperseded),
)
sqlDriver, mock := newTestFixtureSQL(t)

@ -324,7 +324,6 @@ func (d *MaxHistoryMockDriver) Name() string {
}
func TestMaxHistoryErrorHandling(t *testing.T) {
//func TestStorageRemoveLeastRecentWithError(t *testing.T) {
storage := Init(NewMaxHistoryMockDriver(driver.NewMemory()))
storage.MaxHistory = 1

@ -422,7 +422,7 @@ func TestParseLiteralNestedLevels(t *testing.T) {
for i := 1; i <= MaxNestedNameLevel+2; i++ {
tmpStr := fmt.Sprintf("name%d", i)
if i <= MaxNestedNameLevel+1 {
tmpStr = tmpStr + "."
tmpStr += "."
}
keyMultipleNestedLevels.WriteString(tmpStr)
}

@ -190,8 +190,6 @@ func (t *parser) key(data map[string]any, nestedNameLevel int) (reterr error) {
return err
}
return fmt.Errorf("key %q has no value", string(k))
//set(data, string(k), "")
//return err
case last == '[':
// We are in a list index context, so we need to set an index.
i, err := t.keyIndex()

@ -750,7 +750,7 @@ func TestParseSetNestedLevels(t *testing.T) {
for i := 1; i <= MaxNestedNameLevel+2; i++ {
tmpStr := fmt.Sprintf("name%d", i)
if i <= MaxNestedNameLevel+1 {
tmpStr = tmpStr + "."
tmpStr += "."
}
keyMultipleNestedLevels.WriteString(tmpStr)
}

Loading…
Cancel
Save