diff --git a/.golangci.yaml b/.golangci.yaml index 701dd2d62..13a3842e3 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,17 +1,57 @@ linters: + presets: + - bugs enable: - - revive + - containedctx + - copyloopvar + - decorder + - dupl + - forbidigo + - forcetypeassert + - gci - gofmt - gofumpt - - testifylint - - stylecheck + - goimports + - gosimple + - grouper + - inamedparam + - ineffassign + - misspell + - nolintlint + - nonamedreturns + - nosprintfhostport - predeclared - - makezero + - revive + - stylecheck + - tagalign - tenv - - copyloopvar - - protogetter - - nonamedreturns - - gci - - forbidigo + - unconvert + - unused + - usestdlibvars + - wastedassign + - whitespace +linters-settings: + copyloopvar: + check-alias: true + errcheck: + check-blank: true + check-type-assertions: true + disable-default-exclusions: true + gofumpt: + extra-rules: true + grouper: + const-require-grouping: true + const-require-single-const: true + import-require-grouping: false + import-require-single-import: true + type-require-grouping: false + type-require-single-type: false + var-require-grouping: false + var-require-single-var: true + nolintlint: + require-explanation: true + require-specific: true + unparam: + check-exported: true run: timeout: 30m0s diff --git a/pkg/azurelustre/fake_mount_test.go b/pkg/azurelustre/fake_mount_test.go index 846a05d4e..ce5176ed7 100644 --- a/pkg/azurelustre/fake_mount_test.go +++ b/pkg/azurelustre/fake_mount_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" mount "k8s.io/mount-utils" ) @@ -145,7 +146,8 @@ func TestMountSensitiveWithoutSystemdWithMountFlags(t *testing.T) { t.Errorf("actualErr: (%v), expectedErr: (%v)", err, test.expectedErr) } - mountPoints, _ := d.mounter.List() + mountPoints, err := d.mounter.List() + require.NoError(t, err) assert.Equal(t, test.expectedMountpoints, mountPoints) } } diff --git a/pkg/azurelustre/nodeserver_test.go b/pkg/azurelustre/nodeserver_test.go index 97228c89c..028f4ed85 100644 --- a/pkg/azurelustre/nodeserver_test.go +++ b/pkg/azurelustre/nodeserver_test.go @@ -117,7 +117,8 @@ func TestEnsureMountPoint(t *testing.T) { } for _, test := range tests { - _ = makeDir(alreadyExistTarget) + err := makeDir(alreadyExistTarget) + require.NoError(t, err) t.Run(test.desc, func(t *testing.T) { _, err := d.ensureMountPoint(test.target) @@ -126,7 +127,7 @@ func TestEnsureMountPoint(t *testing.T) { } }) - err := os.RemoveAll(alreadyExistTarget) + err = os.RemoveAll(alreadyExistTarget) require.NoError(t, err) err = os.RemoveAll(targetTest) require.NoError(t, err) @@ -542,8 +543,10 @@ func TestNodePublishVolume(t *testing.T) { Exec: fakeExec, } d.workingMountDir = workingMountDir - _ = makeDir(targetTest) - _ = makeDir(alreadyExistTarget) + err := makeDir(targetTest) + require.NoError(t, err) + err = makeDir(alreadyExistTarget) + require.NoError(t, err) if test.setup != nil { test.setup(d) @@ -552,12 +555,13 @@ func TestNodePublishVolume(t *testing.T) { fakeMounter.ResetLog() t.Run(test.desc, func(t *testing.T) { - _, err := d.NodePublishVolume(context.Background(), &test.req) + _, err = d.NodePublishVolume(context.Background(), &test.req) if !reflect.DeepEqual(err, test.expectedErr) { t.Errorf("Desc: %v, Expected error: %v, Actual error: %v", test.desc, test.expectedErr, err) } - mountPoints, _ := d.mounter.List() + mountPoints, err := d.mounter.List() + require.NoError(t, err) assert.Equal(t, test.expectedMountpoints, mountPoints, "Desc: %s - Incorrect mount points: %v - Expected: %v", test.desc, mountPoints, test.expectedMountpoints) mountActions := fakeMounter.GetLog() assert.Equal(t, test.expectedMountActions, mountActions, "Desc: %s - Incorrect mount actions: %v - Expected: %v", test.desc, mountActions, test.expectedMountActions) @@ -732,7 +736,8 @@ func TestNodeUnpublishVolume(t *testing.T) { Interface: fakeMounter, Exec: fakeExec, } - _ = makeDir(targetTest) + err := makeDir(targetTest) + require.NoError(t, err) if test.setup != nil { test.setup(d) @@ -745,7 +750,8 @@ func TestNodeUnpublishVolume(t *testing.T) { if !reflect.DeepEqual(err, test.expectedErr) { t.Errorf("Desc: %v, Expected error: %v, Actual error: %v", test.desc, test.expectedErr, err) } - mountPoints, _ := d.mounter.List() + mountPoints, err := d.mounter.List() + require.NoError(t, err) assert.Equal(t, test.expectedMountpoints, mountPoints, "Desc: %s - Incorrect mount points: %v - Expected: %v", test.desc, mountPoints, test.expectedMountpoints) mountActions := fakeMounter.GetLog() assert.Equal(t, test.expectedMountActions, mountActions, "Desc: %s - Incorrect mount actions: %v - Expected: %v", test.desc, mountActions, test.expectedMountActions) @@ -853,7 +859,8 @@ func TestNodeGetVolumeStats(t *testing.T) { d := NewFakeDriver() for _, test := range tests { - _ = makeDir(fakePath) + err := makeDir(fakePath) + require.NoError(t, err) t.Run(test.desc, func(t *testing.T) { _, err := d.NodeGetVolumeStats(context.Background(), &test.req) if !reflect.DeepEqual(err, test.expectedErr) { @@ -861,7 +868,7 @@ func TestNodeGetVolumeStats(t *testing.T) { } }) - err := os.RemoveAll(fakePath) + err = os.RemoveAll(fakePath) require.NoError(t, err) } } diff --git a/pkg/azurelustre/version_test.go b/pkg/azurelustre/version_test.go index 4a61e6084..22c9a7af1 100644 --- a/pkg/azurelustre/version_test.go +++ b/pkg/azurelustre/version_test.go @@ -23,6 +23,7 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" "sigs.k8s.io/yaml" ) @@ -51,7 +52,8 @@ func TestGetVersionYAML(t *testing.T) { } versionInfo := GetVersion("") - marshalled, _ := yaml.Marshal(&versionInfo) + marshalled, err := yaml.Marshal(&versionInfo) + require.NoError(t, err) expected := strings.TrimSpace(string(marshalled)) diff --git a/pkg/azurelustreplugin/main.go b/pkg/azurelustreplugin/main.go index cff82e437..1c2fad2e6 100644 --- a/pkg/azurelustreplugin/main.go +++ b/pkg/azurelustreplugin/main.go @@ -35,7 +35,10 @@ var ( func main() { klog.InitFlags(nil) - _ = flag.Set("logtostderr", "true") + err := flag.Set("logtostderr", "true") + if err != nil { + klog.Fatalln(err) + } flag.Parse() if *version { info, err := azurelustre.GetVersionYAML(*driverName) diff --git a/pkg/csi-common/utils_test.go b/pkg/csi-common/utils_test.go index 674faa665..b7bb0d62b 100644 --- a/pkg/csi-common/utils_test.go +++ b/pkg/csi-common/utils_test.go @@ -132,7 +132,8 @@ func TestLogGRPC(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { // EXECUTE - _, _ = logGRPC(context.Background(), test.req, &info, handler) + _, err := logGRPC(context.Background(), test.req, &info, handler) + require.NoError(t, err) klog.Flush() // ASSERT diff --git a/test/integration/integration_test.go b/test/integration/integration_test.go index a9cfd510f..b09cf661c 100644 --- a/test/integration/integration_test.go +++ b/test/integration/integration_test.go @@ -72,7 +72,7 @@ func TestIntegration(t *testing.T) { assert.True(t, strings.HasSuffix(cwd, "azurelustre-csi-driver")) // Pass in resource group name, storage account name and cloud type - cmd := exec.Command("./test/integration/run-tests-all-clouds.sh", creds.ResourceGroup, creds.Cloud) + cmd := exec.Command("./test/integration/run-tests-all-clouds.sh", creds.ResourceGroup, creds.Cloud) // #nosec G204 cmd.Dir = cwd cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/test/sanity/sanity_test.go b/test/sanity/sanity_test.go index 33b343acf..28c2693aa 100644 --- a/test/sanity/sanity_test.go +++ b/test/sanity/sanity_test.go @@ -71,7 +71,7 @@ func TestSanity(t *testing.T) { require.NoError(t, err) assert.True(t, strings.HasSuffix(projectRoot, "azurelustre-csi-driver")) - cmd := exec.Command("./test/sanity/run-tests-all-clouds.sh", creds.Cloud) + cmd := exec.Command("./test/sanity/run-tests-all-clouds.sh", creds.Cloud) // #nosec G204 cmd.Dir = projectRoot cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/test/utils/credentials/credentials.go b/test/utils/credentials/credentials.go index 202a0f5a0..908647894 100644 --- a/test/utils/credentials/credentials.go +++ b/test/utils/credentials/credentials.go @@ -30,7 +30,7 @@ import ( const ( AzurePublicCloud = "AzurePublicCloud" ResourceGroupPrefix = "azurelustre-csi-driver-test-" - TempAzureCredentialFilePath = "/tmp/azure.json" + TempAzureCredentialFilePath = "/tmp/azure.json" // #nosec G101 azureCredentialFileTemplate = `{ "cloud": "{{.Cloud}}", @@ -40,7 +40,7 @@ const ( "aadClientSecret": "{{.AADClientSecret}}", "resourceGroup": "{{.ResourceGroup}}", "location": "{{.Location}}" -}` +}` // #nosec G101 defaultAzurePublicCloudLocation = "eastus2" // Env vars @@ -48,7 +48,7 @@ const ( tenantIDEnvVar = "AZURE_TENANT_ID" subscriptionIDEnvVar = "AZURE_SUBSCRIPTION_ID" aadClientIDEnvVar = "AZURE_CLIENT_ID" - aadClientSecretEnvVar = "AZURE_CLIENT_SECRET" + aadClientSecretEnvVar = "AZURE_CLIENT_SECRET" // #nosec G101 resourceGroupEnvVar = "AZURE_RESOURCE_GROUP" locationEnvVar = "AZURE_LOCATION" ) diff --git a/test/utils/credentials/credentials_test.go b/test/utils/credentials/credentials_test.go index 9cbc2913d..1003fd90a 100644 --- a/test/utils/credentials/credentials_test.go +++ b/test/utils/credentials/credentials_test.go @@ -35,7 +35,7 @@ const ( SubscriptionID = "b9d2281e-xxxx-xxxx-xxxx-0d50377cdf76" StorageAccountName = "TestStorageAccountName" StorageAccountKey = "TestStorageAccountKey" - ` + ` // #nosec G101 testTenantID = "test-tenant-id" testSubscriptionID = "test-subscription-id" testAadClientID = "test-aad-client-id" @@ -122,7 +122,7 @@ func withAzureCredentials(t *testing.T) { "resourceGroup": "test-resource-group", "location": "test-location" } - ` + ` // #nosec G101 tmpl := template.New("expectedAzureCredentialFileContent") tmpl, err = tmpl.Parse(expectedAzureCredentialFileContent) require.NoError(t, err) @@ -172,7 +172,7 @@ func withEnvironmentVariables(t *testing.T) { "resourceGroup": "test-resource-group", "location": "test-location" } - ` + ` // #nosec G101 tmpl := template.New("expectedAzureCredentialFileContent") tmpl, err = tmpl.Parse(expectedAzureCredentialFileContent) require.NoError(t, err)