Skip to content

Commit

Permalink
Merge pull request #899 from kubernetes-sigs/add-more-linters
Browse files Browse the repository at this point in the history
test: add more golinters
  • Loading branch information
andyzhangx authored Jan 26, 2022
2 parents 8acf0ad + e230688 commit a722694
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 73 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
version: v1.43
args: -E=gofmt,deadcode,unused,varcheck,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose -D=staticcheck --timeout=30m0s
# https://golangci-lint.run/usage/linters/
args: -E=gofmt,deadcode,unused,varcheck,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,dupl,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s
3 changes: 2 additions & 1 deletion pkg/azurefile/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package azurefile

import (
"context"
"errors"
"fmt"
"os"
"runtime"
Expand Down Expand Up @@ -56,7 +57,7 @@ func getCloudProvider(kubeconfig, nodeID, secretName, secretNamespace, userAgent
kubeClient, err := getKubeClient(kubeconfig)
if err != nil {
klog.Warningf("get kubeconfig(%s) failed with error: %v", kubeconfig, err)
if !os.IsNotExist(err) && err != rest.ErrNotInCluster {
if !os.IsNotExist(err) && !errors.Is(err, rest.ErrNotInCluster) {
return az, fmt.Errorf("failed to get KubeClient: %v", err)
}
}
Expand Down
70 changes: 0 additions & 70 deletions pkg/azurefile/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,76 +641,6 @@ func TestCreateVolume(t *testing.T) {
}
},
},
{
name: "Request namespace does not match",
testFunc: func(t *testing.T) {
name := "baz"
sku := "sku"
kind := "StorageV2"
location := "centralus"
value := "foo bar"
accounts := []storage.Account{
{Name: &name, Sku: &storage.Sku{Name: storage.SkuName(sku)}, Kind: storage.Kind(kind), Location: &location},
}
keys := storage.AccountListKeysResult{
Keys: &[]storage.AccountKey{
{Value: &value},
},
}

allParam := map[string]string{
skuNameField: "premium",
storageAccountTypeField: "stoacctype",
locationField: "loc",
storageAccountField: "stoacc",
resourceGroupField: "rg",
shareNameField: "",
diskNameField: "diskname",
fsTypeField: "",
storeAccountKeyField: "storeaccountkey",
secretNamespaceField: "secretnamespace",
}

req := &csi.CreateVolumeRequest{
Name: "random-vol-name-namespace-not-match",
VolumeCapabilities: stdVolCap,
CapacityRange: lessThanPremCapRange,
Parameters: allParam,
}

d := NewFakeDriver()
d.cloud = &azure.Cloud{}
d.cloud.KubeClient = fake.NewSimpleClientset()

ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockFileClient := mockfileclient.NewMockInterface(ctrl)
d.cloud.FileClient = mockFileClient

mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl)
d.cloud.StorageAccountClient = mockStorageAccountsClient

mockFileClient.EXPECT().CreateFileShare(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any()).Return(keys, nil).AnyTimes()
mockStorageAccountsClient.EXPECT().ListByResourceGroup(gomock.Any(), gomock.Any()).Return(accounts, nil).AnyTimes()
mockStorageAccountsClient.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
mockFileClient.EXPECT().GetFileShare(gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes()

d.AddControllerServiceCapabilities(
[]csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
})

ctx := context.Background()

// 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\"")
_, err := d.CreateVolume(ctx, req)
if !reflect.DeepEqual(err, nil) {
t.Errorf("Unexpected error: %v", err)
}
},
},
{
name: "Create disk returns error",
testFunc: func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/azurefileplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func main() {
if err != nil {
klog.Fatalln(err)
}
fmt.Println(info)
fmt.Println(info) // nolint
os.Exit(0)
}

Expand Down

0 comments on commit a722694

Please sign in to comment.