Skip to content

Commit

Permalink
test: upgrade golint version in github action
Browse files Browse the repository at this point in the history
fix golint

fix golint

fix golint
  • Loading branch information
andyzhangx committed Sep 1, 2024
1 parent e98134c commit 885c80d
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.54
version: v1.60
args: -E=gofmt,unused,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,dupl,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s
2 changes: 1 addition & 1 deletion pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func NewDriver(options *DriverOptions) *Driver {
driver.endpoint = options.Endpoint

var err error
getter := func(key string) (interface{}, error) { return nil, nil }
getter := func(_ string) (interface{}, error) { return nil, nil }

if driver.secretCacheMap, err = azcache.NewTimedCache(time.Minute, getter, false); err != nil {
klog.Fatalf("%v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azurefile/azurefile_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestDriverOptions_AddFlags(t *testing.T) {

got := o.AddFlags()
count := 0
got.VisitAll(func(f *flag.Flag) {
got.VisitAll(func(_ *flag.Flag) {
count++
})
if count != typeInfo.NumField() {
Expand Down
40 changes: 20 additions & 20 deletions pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case selectRandomMatchingAccountField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", selectRandomMatchingAccountField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", selectRandomMatchingAccountField, v)
}
selectRandomMatchingAccount = value
case secretNameField:
Expand All @@ -194,15 +194,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case enableLargeFileSharesField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", enableLargeFileSharesField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", enableLargeFileSharesField, v)
}
enableLFS = &value
case useDataPlaneAPIField:
useDataPlaneAPI = strings.EqualFold(v, trueValue)
case disableDeleteRetentionPolicyField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", disableDeleteRetentionPolicyField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", disableDeleteRetentionPolicyField, v)
}
disableDeleteRetentionPolicy = &value
case pvcNamespaceKey:
Expand All @@ -223,13 +223,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case allowBlobPublicAccessField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowBlobPublicAccessField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", allowBlobPublicAccessField, v)
}
allowBlobPublicAccess = &value
case allowSharedKeyAccessField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowSharedKeyAccessField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", allowSharedKeyAccessField, v)
}
allowSharedKeyAccess = &value
case pvcNameKey:
Expand All @@ -245,7 +245,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case mountPermissionsField:
// only do validations here, used in NodeStageVolume, NodePublishVolume
if _, err := strconv.ParseUint(v, 8, 32); err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s in storage class", v))
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s in storage class", v)
}
case vnetResourceGroupField:
vnetResourceGroup = v
Expand All @@ -258,41 +258,41 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case requireInfraEncryptionField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", requireInfraEncryptionField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", requireInfraEncryptionField, v)
}
requireInfraEncryption = &value
case enableMultichannelField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", enableMultichannelField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", enableMultichannelField, v)
}
isMultichannelEnabled = &value
case getLatestAccountKeyField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", getLatestAccountKeyField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", getLatestAccountKeyField, v)
}
getLatestAccountKey = value
case accountQuotaField:
value, err := strconv.ParseInt(v, 10, 32)
if err != nil || value < minimumAccountQuota {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid accountQuota %s in storage class, minimum quota: %d", v, minimumAccountQuota))
return nil, status.Errorf(codes.InvalidArgument, "invalid accountQuota %s in storage class, minimum quota: %d", v, minimumAccountQuota)
}
accountQuota = int32(value)
case tagValueDelimiterField:
tagValueDelimiter = v
default:
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid parameter %q in storage class", k))
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", k)
}
}

if matchTags && account != "" {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("matchTags must set as false when storageAccount(%s) is provided", account))
return nil, status.Errorf(codes.InvalidArgument, "matchTags must set as false when storageAccount(%s) is provided", account)
}

if subsID != "" && subsID != d.cloud.SubscriptionID {
if resourceGroup == "" {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("resourceGroup must be provided in cross subscription(%s)", subsID))
return nil, status.Errorf(codes.InvalidArgument, "resourceGroup must be provided in cross subscription(%s)", subsID)
}
}

Expand Down Expand Up @@ -433,7 +433,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)

tags, err := ConvertTagsToMap(customTags, tagValueDelimiter)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
return nil, status.Errorf(codes.InvalidArgument, "%v", err)
}

if strings.TrimSpace(storageEndpointSuffix) == "" {
Expand Down Expand Up @@ -497,7 +497,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
// search in cache first
cache, err := d.accountSearchCache.Get(lockKey, azcache.CacheReadTypeDefault)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
if cache != nil {
accountName = cache.(string)
Expand Down Expand Up @@ -553,7 +553,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
// skip validating file share quota if useDataPlaneAPI
} else {
if quota, err := d.getFileShareQuota(ctx, subsID, resourceGroup, accountName, validFileShareName, secret); err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
} else if quota != -1 && quota < fileShareSize {
return nil, status.Errorf(codes.AlreadyExists, "request file share(%s) already exists, but its capacity %d is smaller than %d", validFileShareName, quota, fileShareSize)
}
Expand Down Expand Up @@ -857,7 +857,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
case useDataPlaneAPIField:
useDataPlaneAPI = strings.EqualFold(v, trueValue)
default:
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid parameter %q in storage class", k))
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", k)
}
}

Expand Down Expand Up @@ -1358,7 +1358,7 @@ func (d *Driver) authorizeAzcopyWithIdentity() ([]string, error) {
authAzcopyEnv = append(authAzcopyEnv, fmt.Sprintf("%s=%s", azcopySPAApplicationID, azureAuthConfig.AADClientID))
authAzcopyEnv = append(authAzcopyEnv, fmt.Sprintf("%s=%s", azcopySPAClientSecret, azureAuthConfig.AADClientSecret))
authAzcopyEnv = append(authAzcopyEnv, fmt.Sprintf("%s=%s", azcopyTenantID, azureAuthConfig.TenantID))
klog.V(2).Infof(fmt.Sprintf("set AZCOPY_SPA_APPLICATION_ID=%s, AZCOPY_TENANT_ID=%s successfully", azureAuthConfig.AADClientID, azureAuthConfig.TenantID))
klog.V(2).Infof("set AZCOPY_SPA_APPLICATION_ID=%s, AZCOPY_TENANT_ID=%s successfully", azureAuthConfig.AADClientID, azureAuthConfig.TenantID)

return authAzcopyEnv, nil
}
Expand Down Expand Up @@ -1411,13 +1411,13 @@ func (d *Driver) generateSASToken(accountName, accountKey, storageEndpointSuffix

credential, err := service.NewSharedKeyCredential(accountName, accountKey)
if err != nil {
return "", status.Errorf(codes.Internal, fmt.Sprintf("failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", accountName, err.Error()))
return "", status.Errorf(codes.Internal, "failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", accountName, err.Error())
}
clientOptions := service.ClientOptions{}
clientOptions.InsecureAllowCredentialWithHTTP = true
serviceClient, err := service.NewClientWithSharedKeyCredential(fmt.Sprintf("https://%s.file.%s/", accountName, storageEndpointSuffix), credential, &clientOptions)
if err != nil {
return "", status.Errorf(codes.Internal, fmt.Sprintf("failed to generate sas token in creating new client with shared key credential, accountName: %s, err: %s", accountName, err.Error()))
return "", status.Errorf(codes.Internal, "failed to generate sas token in creating new client with shared key credential, accountName: %s, err: %s", accountName, err.Error())
}
nowTime := time.Now()
sasURL, err := serviceClient.GetSASURL(
Expand Down
4 changes: 2 additions & 2 deletions pkg/azurefile/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ func TestDeleteVolume(t *testing.T) {
},
},
}
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(key string) (interface{}, error) { return nil, nil }, false)
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(_ string) (interface{}, error) { return nil, nil }, false)
d.dataPlaneAPIAccountCache.Set("f5713de20cde511e8ba4900", "1")
d.cloud = &azure.Cloud{}

Expand Down Expand Up @@ -2426,7 +2426,7 @@ func TestControllerExpandVolume(t *testing.T) {
ResourceGroup: "vol_2",
},
}
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(key string) (interface{}, error) { return nil, nil }, false)
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(_ string) (interface{}, error) { return nil, nil }, false)
d.dataPlaneAPIAccountCache.Set("f5713de20cde511e8ba4900", "1")
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down
4 changes: 2 additions & 2 deletions pkg/azurefile/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
if perm := getValueInMap(context, mountPermissionsField); perm != "" {
var err error
if mountPermissions, err = strconv.ParseUint(perm, 8, 32); err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", perm))
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s", perm)
}
}
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
var err error
var perm uint64
if perm, err = strconv.ParseUint(v, 8, 32); err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", v))
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s", v)
}
if perm == 0 {
performChmodOp = false
Expand Down
23 changes: 11 additions & 12 deletions pkg/azurefile/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func TestNodePublishVolume(t *testing.T) {
StagingTargetPath: sourceTest,
Readonly: true},
expectedErr: testutil.TestError{
DefaultError: status.Errorf(codes.Internal, fmt.Sprintf("Could not mount target %s: mkdir %s: not a directory", azureFile, azureFile)),
WindowsError: status.Errorf(codes.Internal, fmt.Sprintf("Could not mount target %v: mkdir %s: The system cannot find the path specified.", azureFile, azureFile)),
DefaultError: status.Errorf(codes.Internal, "Could not mount target %s: mkdir %s: not a directory", azureFile, azureFile),
WindowsError: status.Errorf(codes.Internal, "Could not mount target %v: mkdir %s: The system cannot find the path specified.", azureFile, azureFile),
},
},
{
Expand All @@ -178,7 +178,7 @@ func TestNodePublishVolume(t *testing.T) {
StagingTargetPath: errorMountSource,
Readonly: true},
expectedErr: testutil.TestError{
DefaultError: status.Errorf(codes.Internal, fmt.Sprintf("Could not mount %s at %s: fake Mount: source error", errorMountSource, targetTest)),
DefaultError: status.Errorf(codes.Internal, "Could not mount %s at %s: fake Mount: source error", errorMountSource, targetTest),
},
},
{
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestNodePublishVolume(t *testing.T) {
_ = makeDir(alreadyMountedTarget, 0755)
mounter, err := NewFakeMounter()
if err != nil {
t.Fatalf(fmt.Sprintf("failed to get fake mounter: %v", err))
t.Fatalf("failed to get fake mounter: %v", err)
}
if runtime.GOOS != "windows" {
mounter.Exec = &testingexec.FakeExec{ExactOrder: true}
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
_ = makeDir(errorTarget, 0755)
mounter, err := NewFakeMounter()
if err != nil {
t.Fatalf(fmt.Sprintf("failed to get fake mounter: %v", err))
t.Fatalf("failed to get fake mounter: %v", err)
}
if runtime.GOOS != "windows" {
mounter.Exec = &testingexec.FakeExec{ExactOrder: true}
Expand Down Expand Up @@ -555,7 +555,7 @@ func TestNodeStageVolume(t *testing.T) {
VolumeContext: volContextEmptyDiskName,
Secrets: secrets},
expectedErr: testutil.TestError{
DefaultError: status.Errorf(codes.Internal, fmt.Sprintf("diskname could not be empty, targetPath: %s", sourceTest)),
DefaultError: status.Errorf(codes.Internal, "diskname could not be empty, targetPath: %s", sourceTest),
},
},
{
Expand Down Expand Up @@ -596,7 +596,7 @@ func TestNodeStageVolume(t *testing.T) {
"with smb mapping failed with error: rpc error: code = Unknown desc = NewSmbGlobalMapping failed.",
errorSource, errorMountSensSource),
expectedErr: testutil.TestError{
DefaultError: status.Errorf(codes.Internal, fmt.Sprintf("volume(vol_1##) mount //test_servername/test_sharename on %v failed with fake MountSensitive: target error", errorMountSensSource)),
DefaultError: status.Errorf(codes.Internal, "volume(vol_1##) mount //test_servername/test_sharename on %v failed with fake MountSensitive: target error", errorMountSensSource),
},
},
{
Expand Down Expand Up @@ -716,7 +716,7 @@ func TestNodeStageVolume(t *testing.T) {
}
mounter, err := NewFakeMounter()
if err != nil {
t.Fatalf(fmt.Sprintf("failed to get fake mounter: %v", err))
t.Fatalf("failed to get fake mounter: %v", err)
}

if runtime.GOOS != "windows" {
Expand Down Expand Up @@ -822,7 +822,7 @@ func TestNodeUnstageVolume(t *testing.T) {
_ = makeDir(errorTarget, 0755)
mounter, err := NewFakeMounter()
if err != nil {
t.Fatalf(fmt.Sprintf("failed to get fake mounter: %v", err))
t.Fatalf("failed to get fake mounter: %v", err)
}
if runtime.GOOS != "windows" {
mounter.Exec = &testingexec.FakeExec{ExactOrder: true}
Expand Down Expand Up @@ -1066,9 +1066,8 @@ func TestNodePublishVolumeIdempotentMount(t *testing.T) {
func makeFakeCmd(fakeCmd *testingexec.FakeCmd, cmd string, args ...string) testingexec.FakeCommandAction {
c := cmd
a := args
return func(cmd string, args ...string) exec.Cmd {
command := testingexec.InitFakeCmd(fakeCmd, c, a...)
return command
return func(_ string, _ ...string) exec.Cmd {
return testingexec.InitFakeCmd(fakeCmd, c, a...)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/csi-common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestLogGRPC(t *testing.T) {
buf := new(bytes.Buffer)
klog.SetOutput(buf)

handler := func(ctx context.Context, req interface{}) (interface{}, error) { return nil, nil }
handler := func(_ context.Context, _ interface{}) (interface{}, error) { return nil, nil }
info := grpc.UnaryServerInfo{
FullMethod: "fake",
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
testDriver driver.PVTestDriver
)

ginkgo.BeforeEach(func(ctx ginkgo.SpecContext) {
ginkgo.BeforeEach(func(_ ginkgo.SpecContext) {
checkPodsRestart := testCmd{
command: "bash",
args: []string{"test/utils/check_driver_pods_restart.sh"},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/pre_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = ginkgo.Describe("Pre-Provisioned", func() {
skipManuallyDeletingVolume bool
)

ginkgo.BeforeEach(func(ctx ginkgo.SpecContext) {
ginkgo.BeforeEach(func(_ ginkgo.SpecContext) {
checkPodsRestart := testCmd{
command: "bash",
args: []string{"test/utils/check_driver_pods_restart.sh"},
Expand Down

0 comments on commit 885c80d

Please sign in to comment.