Skip to content

Commit a722694

Browse files
authored
Merge pull request #899 from kubernetes-sigs/add-more-linters
test: add more golinters
2 parents 8acf0ad + e230688 commit a722694

File tree

4 files changed

+5
-73
lines changed

4 files changed

+5
-73
lines changed

.github/workflows/static.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ jobs:
1313
uses: golangci/golangci-lint-action@v2
1414
with:
1515
version: v1.43
16-
args: -E=gofmt,deadcode,unused,varcheck,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose -D=staticcheck --timeout=30m0s
16+
# https://golangci-lint.run/usage/linters/
17+
args: -E=gofmt,deadcode,unused,varcheck,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,dupl,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s

pkg/azurefile/azure.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package azurefile
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"os"
2324
"runtime"
@@ -56,7 +57,7 @@ func getCloudProvider(kubeconfig, nodeID, secretName, secretNamespace, userAgent
5657
kubeClient, err := getKubeClient(kubeconfig)
5758
if err != nil {
5859
klog.Warningf("get kubeconfig(%s) failed with error: %v", kubeconfig, err)
59-
if !os.IsNotExist(err) && err != rest.ErrNotInCluster {
60+
if !os.IsNotExist(err) && !errors.Is(err, rest.ErrNotInCluster) {
6061
return az, fmt.Errorf("failed to get KubeClient: %v", err)
6162
}
6263
}

pkg/azurefile/controllerserver_test.go

-70
Original file line numberDiff line numberDiff line change
@@ -641,76 +641,6 @@ func TestCreateVolume(t *testing.T) {
641641
}
642642
},
643643
},
644-
{
645-
name: "Request namespace does not match",
646-
testFunc: func(t *testing.T) {
647-
name := "baz"
648-
sku := "sku"
649-
kind := "StorageV2"
650-
location := "centralus"
651-
value := "foo bar"
652-
accounts := []storage.Account{
653-
{Name: &name, Sku: &storage.Sku{Name: storage.SkuName(sku)}, Kind: storage.Kind(kind), Location: &location},
654-
}
655-
keys := storage.AccountListKeysResult{
656-
Keys: &[]storage.AccountKey{
657-
{Value: &value},
658-
},
659-
}
660-
661-
allParam := map[string]string{
662-
skuNameField: "premium",
663-
storageAccountTypeField: "stoacctype",
664-
locationField: "loc",
665-
storageAccountField: "stoacc",
666-
resourceGroupField: "rg",
667-
shareNameField: "",
668-
diskNameField: "diskname",
669-
fsTypeField: "",
670-
storeAccountKeyField: "storeaccountkey",
671-
secretNamespaceField: "secretnamespace",
672-
}
673-
674-
req := &csi.CreateVolumeRequest{
675-
Name: "random-vol-name-namespace-not-match",
676-
VolumeCapabilities: stdVolCap,
677-
CapacityRange: lessThanPremCapRange,
678-
Parameters: allParam,
679-
}
680-
681-
d := NewFakeDriver()
682-
d.cloud = &azure.Cloud{}
683-
d.cloud.KubeClient = fake.NewSimpleClientset()
684-
685-
ctrl := gomock.NewController(t)
686-
defer ctrl.Finish()
687-
688-
mockFileClient := mockfileclient.NewMockInterface(ctrl)
689-
d.cloud.FileClient = mockFileClient
690-
691-
mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl)
692-
d.cloud.StorageAccountClient = mockStorageAccountsClient
693-
694-
mockFileClient.EXPECT().CreateFileShare(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
695-
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any()).Return(keys, nil).AnyTimes()
696-
mockStorageAccountsClient.EXPECT().ListByResourceGroup(gomock.Any(), gomock.Any()).Return(accounts, nil).AnyTimes()
697-
mockStorageAccountsClient.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
698-
mockFileClient.EXPECT().GetFileShare(gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes()
699-
700-
d.AddControllerServiceCapabilities(
701-
[]csi.ControllerServiceCapability_RPC_Type{
702-
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
703-
})
704-
705-
ctx := context.Background()
706-
707-
// expectedErr := status.Error(codes.Internal, "failed to store storage account key: couldn't create secret request namespace does not match object namespace, request: \"secretnamespace\" object: \"default\"")
708-
_, err := d.CreateVolume(ctx, req)
709-
if !reflect.DeepEqual(err, nil) {
710-
t.Errorf("Unexpected error: %v", err)
711-
}
712-
},
713-
},
714644
{
715645
name: "Create disk returns error",
716646
testFunc: func(t *testing.T) {

pkg/azurefileplugin/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func main() {
5858
if err != nil {
5959
klog.Fatalln(err)
6060
}
61-
fmt.Println(info)
61+
fmt.Println(info) // nolint
6262
os.Exit(0)
6363
}
6464

0 commit comments

Comments
 (0)