diff --git a/.github/workflows/static.yaml b/.github/workflows/static.yaml index b59c459821..6336054b56 100644 --- a/.github/workflows/static.yaml +++ b/.github/workflows/static.yaml @@ -16,4 +16,4 @@ jobs: uses: golangci/golangci-lint-action@v6 with: version: v1.60 - args: -E=gofmt,unused,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,dupl,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s + args: -E=gofmt,unused,ineffassign,revive,misspell,copyloopvar,asciicheck,bodyclose,depguard,dogsled,dupl,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s diff --git a/pkg/azurefile/controllerserver_test.go b/pkg/azurefile/controllerserver_test.go index ea8e41d3fc..dde0465e12 100644 --- a/pkg/azurefile/controllerserver_test.go +++ b/pkg/azurefile/controllerserver_test.go @@ -24,17 +24,16 @@ import ( "net/url" "reflect" "runtime" - "strings" "sync" - "testing" "time" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-07-01/network" "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-09-01/storage" azure2 "github.com/Azure/go-autorest/autorest/azure" "github.com/container-storage-interface/spec/lib/go/csi" "github.com/onsi/ginkgo/v2" - "github.com/stretchr/testify/assert" + "github.com/onsi/gomega" "go.uber.org/mock/gomock" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -56,7 +55,9 @@ import ( "sigs.k8s.io/cloud-provider-azure/pkg/retry" ) -var _ = ginkgo.Describe(" TestCreateVolume", func() { +var _ = ginkgo.Describe("TestCreateVolume", func() { + var d *Driver + var ctrl *gomock.Controller stdVolCap := []*csi.VolumeCapability{ { AccessType: &csi.VolumeCapability_Mount{ @@ -88,6 +89,11 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { stdCapRange = &csi.CapacityRange{RequiredBytes: stdVolSize} zeroCapRange = &csi.CapacityRange{RequiredBytes: int64(0)} lessThanPremCapRange = &csi.CapacityRange{RequiredBytes: int64(fakeShareQuota * 1024 * 1024 * 1024)} + d = NewFakeDriver() + ctrl = gomock.NewController(ginkgo.GinkgoT()) + }) + ginkgo.AfterEach(func() { + ctrl.Finish() }) ginkgo.When("Controller Capability missing", func() { ginkgo.It("should fail", func(ctx context.Context) { @@ -98,15 +104,11 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { Parameters: nil, } - d := NewFakeDriver() d.Cap = []*csi.ControllerServiceCapability{} expectedErr := status.Errorf(codes.InvalidArgument, "CREATE_DELETE_VOLUME") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) @@ -118,14 +120,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: nil, } - d := NewFakeDriver() - expectedErr := status.Error(codes.InvalidArgument, "CreateVolume Name must be provided") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Volume capabilities missing", func() { @@ -135,15 +132,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { CapacityRange: stdCapRange, Parameters: nil, } - - d := NewFakeDriver() - expectedErr := status.Error(codes.InvalidArgument, "CreateVolume Volume capabilities not valid: CreateVolume Volume capabilities must be provided") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid volume capabilities", func() { @@ -163,15 +154,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { }, Parameters: nil, } - - d := NewFakeDriver() - expectedErr := status.Error(codes.InvalidArgument, "CreateVolume Volume capabilities not valid: driver does not support block volumes") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Volume lock already present", func() { @@ -182,18 +167,13 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: nil, } - - d := NewFakeDriver() locks := newVolumeLocks() locks.locks.Insert(req.GetName()) d.volumeLocks = locks expectedErr := status.Error(codes.Aborted, "An operation with the given Volume ID random-vol-name-vol-cap-invalid already exists") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Disabled fsType", func() { @@ -220,10 +200,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := status.Errorf(codes.InvalidArgument, "fsType storage class parameter enables experimental VDH disk feature which is currently disabled, use --enable-vhd driver option to enable it") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid fsType", func() { @@ -248,10 +225,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := status.Errorf(codes.InvalidArgument, "fsType(test_fs) is not supported, supported fsType list: [cifs smb nfs ext4 ext3 ext2 xfs]") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid protocol", func() { @@ -266,15 +240,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() - expectedErr := status.Errorf(codes.InvalidArgument, "protocol(test_protocol) is not supported, supported protocol list: [smb nfs]") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("nfs protocol only supports premium storage", func() { @@ -290,14 +258,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() expectedErr := status.Errorf(codes.InvalidArgument, "nfs protocol only supports premium storage, current account type: Standard_LRS") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid accessTier", func() { @@ -313,15 +276,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() - expectedErr := status.Errorf(codes.InvalidArgument, "shareAccessTier(test_accessTier) is not supported, supported ShareAccessTier list: [Cool Hot Premium TransactionOptimized]") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid rootSquashType", func() { @@ -336,15 +293,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() - expectedErr := status.Errorf(codes.InvalidArgument, "rootSquashType(test_rootSquashType) is not supported, supported RootSquashType list: [AllSquash NoRootSquash RootSquash]") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid fsGroupChangePolicy", func() { @@ -359,15 +310,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() - expectedErr := status.Errorf(codes.InvalidArgument, "fsGroupChangePolicy(test_fsGroupChangePolicy) is not supported, supported fsGroupChangePolicy list: [None Always OnRootMismatch]") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid shareNamePrefix", func() { @@ -382,14 +327,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - d := NewFakeDriver() - expectedErr := status.Errorf(codes.InvalidArgument, "shareNamePrefix(-invalid) can only contain lowercase letters, numbers, hyphens, and length should be less than 21") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid accountQuota", func() { @@ -404,15 +344,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() - expectedErr := status.Errorf(codes.InvalidArgument, "invalid accountQuota %d in storage class, minimum quota: %d", 10, minimumAccountQuota) _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("invalid tags format to convert to map", func() { @@ -436,15 +370,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() - expectedErr := status.Errorf(codes.InvalidArgument, "Tags 'tags' are invalid, the format should like: 'key1=value1,key2=value2'") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("failed to GetStorageAccesskey", func() { @@ -470,18 +398,13 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() d.cloud = fakeCloud d.volMap = sync.Map{} d.volMap.Store("random-vol-name-vol-cap-invalid", "account") expectedErr := status.Errorf(codes.Internal, "failed to GetStorageAccesskey on account(account) rg(), error: StorageAccountClient is nil") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid protocol & fsType combination", func() { @@ -507,10 +430,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := status.Errorf(codes.InvalidArgument, "fsType(ext4) is not supported with protocol(nfs)") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("storeAccountKey must set as true in cross subscription", func() { @@ -527,18 +447,13 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{}, } expectedErr := status.Errorf(codes.InvalidArgument, "resourceGroup must be provided in cross subscription(abc)") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("invalid selectRandomMatchingAccount value", func() { @@ -553,18 +468,13 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{}, } expectedErr := status.Errorf(codes.InvalidArgument, "invalid selectrandommatchingaccount: invalid in storage class") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("invalid getLatestAccountKey value", func() { @@ -579,18 +489,13 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{}, } expectedErr := status.Errorf(codes.InvalidArgument, "invalid getlatestaccountkey: invalid in storage class") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v, expected error: %v", err, expectedErr) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("storageAccount and matchTags conflict", func() { @@ -606,18 +511,13 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{}, } expectedErr := status.Errorf(codes.InvalidArgument, "matchTags must set as false when storageAccount(abc) is provided") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("invalid privateEndpoint and subnetName combination", func() { @@ -633,18 +533,13 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{}, } expectedErr := status.Errorf(codes.InvalidArgument, "subnetName(subnet1,subnet2) can only contain one subnet for private endpoint") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v, expected error: %v", err, expectedErr) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Failed to update subnet service endpoints", func() { @@ -669,11 +564,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - d := NewFakeDriver() - d.cloud = fakeCloud - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() mockSubnetClient := mocksubnetclient.NewMockInterface(ctrl) fakeCloud.SubnetsClient = mockSubnetClient @@ -681,10 +572,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := status.Errorf(codes.Internal, "update service endpoints failed with error: failed to list the subnets under rg rg vnet fake-vnet: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: the subnet does not exist") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Failed with storeAccountKey is not supported for account with shared access key disabled", func() { @@ -720,16 +608,11 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { VolumeCapabilities: stdVolCap, Parameters: allParam, } - d := NewFakeDriver() - d.cloud = fakeCloud expectedErr := status.Errorf(codes.InvalidArgument, "storeAccountKey is not supported for account with shared access key disabled") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("fileServicePropertiesCache is nil", func() { @@ -766,13 +649,8 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { CapacityRange: zeroCapRange, Parameters: allParam, } - - d := NewFakeDriver() d.cloud = &azure.Cloud{} - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -794,10 +672,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := fmt.Errorf("failed to ensure storage account: fileServicePropertiesCache is nil") _, err := d.CreateVolume(ctx, req) - if !strings.Contains(err.Error(), expectedErr.Error()) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err.Error()).To(gomega.ContainSubstring(expectedErr.Error())) }) }) ginkgo.When("No valid key, check all params, with less than min premium volume", func() { @@ -835,12 +710,8 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { Parameters: allParam, } - d := NewFakeDriver() d.cloud = &azure.Cloud{} - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -856,10 +727,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := fmt.Errorf("no valid keys") _, err := d.CreateVolume(ctx, req) - if !strings.Contains(err.Error(), expectedErr.Error()) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err.Error()).To(gomega.ContainSubstring(expectedErr.Error())) }) }) ginkgo.When("Get file share returns error", func() { @@ -885,12 +753,8 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { Parameters: nil, } - d := NewFakeDriver() d.cloud = &azure.Cloud{} - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -908,10 +772,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := status.Errorf(codes.Internal, "test error") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("test name: %s, Unexpected error: %v, expected error: %v", name, err, expectedErr) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Create file share error tests", func() { @@ -950,12 +811,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { Parameters: allParam, } - d := NewFakeDriver() d.cloud = &azure.Cloud{} - - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -975,10 +831,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := status.Errorf(codes.Internal, "FileShareProperties or FileShareProperties.ShareQuota is nil") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("test name: %s, Unexpected error: %v, expected error: %v", name, err, expectedErr) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("existing file share quota is smaller than request quota", func() { @@ -1017,12 +870,8 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { Parameters: allParam, } - d := NewFakeDriver() d.cloud = &azure.Cloud{} - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -1041,10 +890,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := status.Errorf(codes.AlreadyExists, "request file share(random-vol-name-crete-file-error) already exists, but its capacity 1 is smaller than 100") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("test name: %s, Unexpected error: %v, expected error: %v", name, err, expectedErr) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Create disk returns error", func() { @@ -1094,9 +940,6 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { d.cloud = &azure.Cloud{} d.cloud.KubeClient = fake.NewSimpleClientset() - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - tests := []struct { desc string fileSharename string @@ -1129,10 +972,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { mockFileClient.EXPECT().GetFileShare(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes() _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, test.expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(test.expectedErr)) } }) }) @@ -1174,13 +1014,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { Parameters: allParam, } - d := NewFakeDriver() d.cloud = &azure.Cloud{} d.cloud.KubeClient = fake.NewSimpleClientset() - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -1195,10 +1031,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { mockFileClient.EXPECT().GetFileShare(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes() _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, nil) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).NotTo(gomega.HaveOccurred()) }) }) ginkgo.When("invalid mountPermissions", func() { @@ -1228,13 +1061,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { Parameters: allParam, } - d := NewFakeDriver() d.cloud = &azure.Cloud{} d.cloud.KubeClient = fake.NewSimpleClientset() - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -1250,10 +1079,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := status.Errorf(codes.InvalidArgument, "invalid %s %s in storage class", "mountPermissions", "0abc") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("invalid parameter", func() { @@ -1283,13 +1109,9 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { Parameters: allParam, } - d := NewFakeDriver() d.cloud = &azure.Cloud{} d.cloud.KubeClient = fake.NewSimpleClientset() - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -1305,10 +1127,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { expectedErr := status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", "invalidparameter") _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Account limit exceeded", func() { @@ -1346,10 +1165,8 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { Parameters: allParam, } - d := NewFakeDriver() d.cloud.KubeClient = fake.NewSimpleClientset() - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() + d.cloud = azure.GetTestCloud(ctrl) mockFileClient := mockfileclient.NewMockInterface(ctrl) @@ -1371,10 +1188,8 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { mockFileClient.EXPECT().GetFileShare(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes() _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, nil) { + gomega.Expect(err).NotTo(gomega.HaveOccurred()) - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } }) }) ginkgo.When("Premium storage account type (sku) loads from storage account when not given as parameter and share request size is increased to min. size required by premium", func() { @@ -1412,9 +1227,6 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { CapacityRange: capRange, } - d := NewFakeDriver() - - ctrl := gomock.NewController(ginkgo.GinkgoT()) mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -1430,10 +1242,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, nil) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).NotTo(gomega.HaveOccurred()) }) }) ginkgo.When("Premium storage account type (sku) does not load from storage account for size request above min. premium size", func() { @@ -1471,9 +1280,6 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { CapacityRange: capRange, } - d := NewFakeDriver() - - ctrl := gomock.NewController(ginkgo.GinkgoT()) mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -1487,11 +1293,7 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { mockStorageAccountsClient.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes() _, err := d.CreateVolume(ctx, req) - - if !reflect.DeepEqual(err, nil) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).NotTo(gomega.HaveOccurred()) }) }) ginkgo.When("Storage account type (sku) defaults to standard type and share request size is unchanged", func() { @@ -1528,9 +1330,6 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { CapacityRange: capRange, } - d := NewFakeDriver() - - ctrl := gomock.NewController(ginkgo.GinkgoT()) mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud.FileClient = mockFileClient @@ -1545,30 +1344,30 @@ var _ = ginkgo.Describe(" TestCreateVolume", func() { mockStorageAccountsClient.EXPECT().GetProperties(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(accounts[0], nil).AnyTimes() _, err := d.CreateVolume(ctx, req) - if !reflect.DeepEqual(err, nil) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).NotTo(gomega.HaveOccurred()) }) }) }) var _ = ginkgo.Describe("TestDeleteVolume", func() { - + var ctrl *gomock.Controller + var d *Driver + ginkgo.BeforeEach(func() { + ctrl = gomock.NewController(ginkgo.GinkgoT()) + d = NewFakeDriver() + }) + ginkgo.AfterEach(func() { + ctrl.Finish() + }) ginkgo.When("Volume ID missing", func() { ginkgo.It("should fail", func(ctx context.Context) { req := &csi.DeleteVolumeRequest{ Secrets: map[string]string{}, } - d := NewFakeDriver() - expectedErr := status.Error(codes.InvalidArgument, "Volume ID missing in request") _, err := d.DeleteVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Controller capability missing", func() { @@ -1578,15 +1377,11 @@ var _ = ginkgo.Describe("TestDeleteVolume", func() { Secrets: map[string]string{}, } - d := NewFakeDriver() d.Cap = []*csi.ControllerServiceCapability{} expectedErr := status.Errorf(codes.InvalidArgument, "invalid delete volume request: %v", req) _, err := d.DeleteVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid volume ID", func() { @@ -1596,7 +1391,6 @@ var _ = ginkgo.Describe("TestDeleteVolume", func() { Secrets: map[string]string{}, } - d := NewFakeDriver() d.Cap = []*csi.ControllerServiceCapability{ { Type: &csi.ControllerServiceCapability_Rpc{ @@ -1606,10 +1400,8 @@ var _ = ginkgo.Describe("TestDeleteVolume", func() { } _, err := d.DeleteVolume(ctx, req) - if !reflect.DeepEqual(err, nil) { + gomega.Expect(err).NotTo(gomega.HaveOccurred()) - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } }) }) ginkgo.When("failed to get account info", func() { @@ -1619,7 +1411,6 @@ var _ = ginkgo.Describe("TestDeleteVolume", func() { Secrets: map[string]string{}, } - d := NewFakeDriver() d.Cap = []*csi.ControllerServiceCapability{ { Type: &csi.ControllerServiceCapability_Rpc{ @@ -1633,10 +1424,7 @@ var _ = ginkgo.Describe("TestDeleteVolume", func() { expectedErr := status.Errorf(codes.NotFound, "get account info from(vol_1#f5713de20cde511e8ba4900#fileshare#diskname.vhd##secret) failed with error: could not get account key from secret(azure-storage-account-f5713de20cde511e8ba4900-secret): KubeClient is nil") _, err := d.DeleteVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Delete file share returns error", func() { @@ -1646,9 +1434,6 @@ var _ = ginkgo.Describe("TestDeleteVolume", func() { Secrets: map[string]string{}, } - d := NewFakeDriver() - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud = &azure.Cloud{} d.cloud.FileClient = mockFileClient @@ -1657,10 +1442,7 @@ var _ = ginkgo.Describe("TestDeleteVolume", func() { expectedErr := status.Errorf(codes.Internal, "DeleteFileShare fileshare under account(f5713de20cde511e8ba4900) rg() failed with error: test error") _, err := d.DeleteVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Valid request", func() { @@ -1670,9 +1452,6 @@ var _ = ginkgo.Describe("TestDeleteVolume", func() { Secrets: map[string]string{}, } - d := NewFakeDriver() - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() mockFileClient := mockfileclient.NewMockInterface(ctrl) d.cloud = azure.GetTestCloud(ctrl) d.cloud.FileClient = mockFileClient @@ -1681,16 +1460,15 @@ var _ = ginkgo.Describe("TestDeleteVolume", func() { expectedResp := &csi.DeleteSnapshotResponse{} resp, err := d.DeleteVolume(ctx, req) - if !(reflect.DeepEqual(err, nil) || reflect.DeepEqual(resp, expectedResp)) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + gomega.Expect(resp).To(gomega.BeEquivalentTo(expectedResp)) }) }) - }) var _ = ginkgo.Describe("TestCopyVolume", func() { + var ctrl *gomock.Controller + var d *Driver stdVolCap := []*csi.VolumeCapability{ { AccessType: &csi.VolumeCapability_Mount{ @@ -1716,6 +1494,11 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { } fakeShareQuota = int32(100) lessThanPremCapRange = &csi.CapacityRange{RequiredBytes: int64(fakeShareQuota * 1024 * 1024 * 1024)} + ctrl = gomock.NewController(ginkgo.GinkgoT()) + d = NewFakeDriver() + }) + ginkgo.AfterEach(func() { + ctrl.Finish() }) ginkgo.When("restore volume from volumeSnapshot nfs is not supported", func() { ginkgo.It("should fail", func(ctx context.Context) { @@ -1739,14 +1522,9 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { VolumeContentSource: &volumecontensource, } - d := NewFakeDriver() - expectedErr := fmt.Errorf("protocol nfs is not supported for snapshot restore") err := d.copyVolume(ctx, req, "", "", []string{}, "", &fileclient.ShareOptions{Protocol: storage.EnabledProtocolsNFS}, nil, "core.windows.net") - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("restore volume from volumeSnapshot not found", func() { @@ -1771,14 +1549,9 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { VolumeContentSource: &volumecontensource, } - d := NewFakeDriver() - expectedErr := status.Errorf(codes.NotFound, "error parsing volume id: \"unit-test\", should at least contain two #") err := d.copyVolume(ctx, req, "", "", []string{}, "", &fileclient.ShareOptions{Name: "dstFileshare"}, nil, "core.windows.net") - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("restore volume from volumeSnapshot src fileshare is empty", func() { @@ -1803,14 +1576,9 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { VolumeContentSource: &volumecontensource, } - d := NewFakeDriver() - expectedErr := fmt.Errorf("one or more of srcAccountName(unit-test), srcFileShareName(), dstFileShareName(dstFileshare) are empty") err := d.copyVolume(ctx, req, "", "", []string{}, "", &fileclient.ShareOptions{Name: "dstFileshare"}, nil, "core.windows.net") - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("copy volume nfs is not supported", func() { @@ -1835,14 +1603,9 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { VolumeContentSource: &volumecontensource, } - d := NewFakeDriver() - expectedErr := fmt.Errorf("protocol nfs is not supported for volume cloning") err := d.copyVolume(ctx, req, "", "", []string{}, "", &fileclient.ShareOptions{Protocol: storage.EnabledProtocolsNFS}, nil, "core.windows.net") - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("copy volume from volume not found", func() { @@ -1867,14 +1630,9 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { VolumeContentSource: &volumecontensource, } - d := NewFakeDriver() - expectedErr := status.Errorf(codes.NotFound, "error parsing volume id: \"unit-test\", should at least contain two #") err := d.copyVolume(ctx, req, "", "", []string{}, "", &fileclient.ShareOptions{Name: "dstFileshare"}, nil, "core.windows.net") - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("src fileshare is empty", func() { @@ -1899,14 +1657,9 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { VolumeContentSource: &volumecontensource, } - d := NewFakeDriver() - expectedErr := fmt.Errorf("one or more of srcAccountName(unit-test), srcFileShareName(), dstFileShareName(dstFileshare) are empty") err := d.copyVolume(ctx, req, "", "", []string{}, "", &fileclient.ShareOptions{Name: "dstFileshare"}, nil, "core.windows.net") - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("dst fileshare is empty", func() { @@ -1931,19 +1684,14 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { VolumeContentSource: &volumecontensource, } - d := NewFakeDriver() - expectedErr := fmt.Errorf("one or more of srcAccountName(f5713de20cde511e8ba4900), srcFileShareName(fileshare), dstFileShareName() are empty") err := d.copyVolume(ctx, req, "", "", []string{}, "", &fileclient.ShareOptions{}, nil, "core.windows.net") - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("azcopy job is in progress", func() { ginkgo.It("should fail", func(ctx context.Context) { - d := NewFakeDriver() + mp := map[string]string{} volumeSource := &csi.VolumeContentSource_VolumeSource{ @@ -1963,9 +1711,6 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { VolumeContentSource: &volumecontensource, } - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() - m := util.NewMockEXEC(ctrl) listStr1 := "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: InProgress\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false" m.EXPECT().RunCommand(gomock.Eq("azcopy jobs list | grep dstFileshare -B 3"), gomock.Any()).Return(listStr1, nil).Times(1) @@ -1975,46 +1720,54 @@ var _ = ginkgo.Describe("TestCopyVolume", func() { expectedErr := fmt.Errorf("wait for the existing AzCopy job to complete, current copy percentage is 50.0%%") err := d.copyVolume(ctx, req, "", "sastoken", []string{}, "", &fileclient.ShareOptions{Name: "dstFileshare"}, nil, "core.windows.net") - if !reflect.DeepEqual(err, expectedErr) { + gomega.Expect(err).To(gomega.Equal(expectedErr)) + }) + }) - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } +}) + +var _ = ginkgo.Describe("ControllerGetVolume", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { + d := NewFakeDriver() + req := csi.ControllerGetVolumeRequest{} + resp, err := d.ControllerGetVolume(context.Background(), &req) + gomega.Expect(resp).To(gomega.BeNil()) + gomega.Expect(err).To(gomega.Equal(status.Error(codes.Unimplemented, ""))) }) }) +}) +var _ = ginkgo.Describe("ControllerGetCapabilities", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { + + d := NewFakeDriver() + controlCap := []*csi.ControllerServiceCapability{ + { + Type: &csi.ControllerServiceCapability_Rpc{}, + }, + } + d.Cap = controlCap + req := csi.ControllerGetCapabilitiesRequest{} + resp, err := d.ControllerGetCapabilities(context.Background(), &req) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + gomega.Expect(resp).NotTo(gomega.BeNil()) + gomega.Expect(resp.Capabilities).To(gomega.Equal(controlCap)) + }) + }) }) -func TestControllerGetVolume(t *testing.T) { +var _ = ginkgo.DescribeTable("ValidateVolumeCapabilities", func( + req csi.ValidateVolumeCapabilitiesRequest, + expectedErr error, + mockedFileShareErr error, +) { d := NewFakeDriver() - req := csi.ControllerGetVolumeRequest{} - resp, err := d.ControllerGetVolume(context.Background(), &req) - assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { - t.Errorf("Unexpected error: %v", err) - } -} + d.cloud = &azure.Cloud{} -func TestControllerGetCapabilities(t *testing.T) { - d := NewFakeDriver() - controlCap := []*csi.ControllerServiceCapability{ - { - Type: &csi.ControllerServiceCapability_Rpc{}, - }, - } - d.Cap = controlCap - req := csi.ControllerGetCapabilitiesRequest{} - resp, err := d.ControllerGetCapabilities(context.Background(), &req) - assert.NoError(t, err) - assert.NotNil(t, resp) - assert.Equal(t, resp.Capabilities, controlCap) -} - -func TestValidateVolumeCapabilities(t *testing.T) { - d := NewFakeDriver() - d.cloud = &azure.Cloud{} - - ctrl := gomock.NewController(t) + ctrl := gomock.NewController(ginkgo.GinkgoT()) defer ctrl.Finish() value := base64.StdEncoding.EncodeToString([]byte("acc_key")) key := storage.AccountListKeysResult{ @@ -2023,259 +1776,295 @@ func TestValidateVolumeCapabilities(t *testing.T) { }, } clientSet := fake.NewSimpleClientset() - stdVolCap := []*csi.VolumeCapability{ - { - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - }, - }, - } - multiNodeVolCap := []*csi.VolumeCapability{ - { - AccessType: &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - }, - AccessMode: &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_SINGLE_WRITER, - }, - }, - } fakeShareQuota := int32(100) - - tests := []struct { - desc string - req csi.ValidateVolumeCapabilitiesRequest - expectedErr error - mockedFileShareErr error - }{ - { - desc: "Volume ID missing", - req: csi.ValidateVolumeCapabilitiesRequest{}, - expectedErr: status.Error(codes.InvalidArgument, "Volume ID not provided"), - mockedFileShareErr: nil, - }, - { - desc: "Volume capabilities missing", - req: csi.ValidateVolumeCapabilitiesRequest{VolumeId: "vol_1"}, - expectedErr: status.Error(codes.InvalidArgument, "Volume capabilities not provided"), - mockedFileShareErr: nil, - }, - { - desc: "Volume ID not valid", - req: csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: "vol_1", - VolumeCapabilities: stdVolCap, + mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) + d.cloud.StorageAccountClient = mockStorageAccountsClient + d.cloud.KubeClient = clientSet + d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} + mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(key, nil).AnyTimes() + mockFileClient := mockfileclient.NewMockInterface(ctrl) + d.cloud.FileClient = mockFileClient + mockFileClient.EXPECT().WithSubscriptionID(gomock.Any()).Return(mockFileClient).AnyTimes() + mockFileClient.EXPECT().GetFileShare(context.Background(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, mockedFileShareErr).AnyTimes() + + _, err := d.ValidateVolumeCapabilities(context.Background(), &req) + if expectedErr == nil { + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + } else { + gomega.Expect(err).To(gomega.Equal(expectedErr)) + } +}, + ginkgo.Entry("Volume ID missing", + csi.ValidateVolumeCapabilitiesRequest{}, + status.Error(codes.InvalidArgument, "Volume ID not provided"), + nil, + ), + ginkgo.Entry("Volume capabilities missing", + csi.ValidateVolumeCapabilitiesRequest{VolumeId: "vol_1"}, + status.Error(codes.InvalidArgument, "Volume capabilities not provided"), + nil, + ), + ginkgo.Entry("Volume ID not valid", + csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: "vol_1", + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, }, - expectedErr: status.Errorf(codes.NotFound, "get account info from(vol_1) failed with error: "), - mockedFileShareErr: nil, }, - { - desc: "Check file share exists errors", - req: csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#", - VolumeCapabilities: stdVolCap, + status.Errorf(codes.NotFound, "get account info from(vol_1) failed with error: "), + nil, + ), + ginkgo.Entry("Check file share exists errors", + csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#", + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, }, - expectedErr: status.Errorf(codes.Internal, "error checking if volume(vol_1#f5713de20cde511e8ba4900#fileshare#) exists: test error"), - mockedFileShareErr: fmt.Errorf("test error"), }, - { - desc: "Share not found", - req: csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#", - VolumeCapabilities: stdVolCap, + status.Errorf(codes.Internal, "error checking if volume(vol_1#f5713de20cde511e8ba4900#fileshare#) exists: test error"), + fmt.Errorf("test error"), + ), + ginkgo.Entry("Share not found", + csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#", + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, }, - expectedErr: status.Errorf(codes.NotFound, "the requested volume(vol_1#f5713de20cde511e8ba4900#fileshare#) does not exist."), - mockedFileShareErr: fmt.Errorf("ShareNotFound"), }, - { - desc: "Valid request disk name is empty", - req: csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#", - VolumeCapabilities: stdVolCap, + status.Errorf(codes.NotFound, "the requested volume(vol_1#f5713de20cde511e8ba4900#fileshare#) does not exist."), + fmt.Errorf("ShareNotFound"), + ), + ginkgo.Entry("Valid request disk name is empty", + csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#", + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, }, - expectedErr: nil, - mockedFileShareErr: nil, }, - { - desc: "Valid request volume capability is multi node single writer", - req: csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#diskname.vhd#", - VolumeCapabilities: multiNodeVolCap, + nil, + nil, + ), + ginkgo.Entry("Valid request volume capability is multi node single writer", + csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#diskname.vhd#", + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_SINGLE_WRITER, + }, + }, }, - expectedErr: nil, - mockedFileShareErr: nil, }, - { - desc: "Valid request", - req: csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#diskname.vhd#", - VolumeCapabilities: stdVolCap, + nil, + nil, + ), + ginkgo.Entry("Valid request", + csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#diskname.vhd#", + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, }, - expectedErr: nil, - mockedFileShareErr: nil, }, - { - desc: "Resource group empty", - req: csi.ValidateVolumeCapabilitiesRequest{ - VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#diskname.vhd#", - VolumeCapabilities: stdVolCap, - VolumeContext: map[string]string{ - shareNameField: "sharename", - diskNameField: "diskname.vhd", + nil, + nil, + ), + ginkgo.Entry("Resource group empty", + csi.ValidateVolumeCapabilitiesRequest{ + VolumeId: "vol_1#f5713de20cde511e8ba4900#fileshare#diskname.vhd#", + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, }, }, - expectedErr: nil, - mockedFileShareErr: nil, + VolumeContext: map[string]string{ + shareNameField: "sharename", + diskNameField: "diskname.vhd", + }, }, - } - - for _, test := range tests { - mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) - d.cloud.StorageAccountClient = mockStorageAccountsClient - d.cloud.KubeClient = clientSet - d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} - mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(key, nil).AnyTimes() - mockFileClient := mockfileclient.NewMockInterface(ctrl) - d.cloud.FileClient = mockFileClient - mockFileClient.EXPECT().WithSubscriptionID(gomock.Any()).Return(mockFileClient).AnyTimes() - mockFileClient.EXPECT().GetFileShare(context.Background(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, test.mockedFileShareErr).AnyTimes() - - _, err := d.ValidateVolumeCapabilities(context.Background(), &test.req) - if !reflect.DeepEqual(err, test.expectedErr) { - - t.Errorf("test[%s]: unexpected error: %v, expected error: %v", test.desc, err, test.expectedErr) - } - } -} + nil, + nil, + ), +) +var _ = ginkgo.Describe("CreateSnapshot", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { -func TestCreateSnapshot(t *testing.T) { - d := NewFakeDriver() - d.cloud = &azure.Cloud{} + d := NewFakeDriver() - tests := []struct { - desc string - req *csi.CreateSnapshotRequest - expectedErr error - }{ - { - desc: "Snapshot name missing", - req: &csi.CreateSnapshotRequest{}, - expectedErr: status.Error(codes.InvalidArgument, "Snapshot name must be provided"), - }, - { - desc: "Source volume ID", - req: &csi.CreateSnapshotRequest{ - Name: "snapname", - }, - expectedErr: status.Error(codes.InvalidArgument, "CreateSnapshot Source Volume ID must be provided"), - }, - { - desc: "Invalid volume ID", - req: &csi.CreateSnapshotRequest{ - SourceVolumeId: "vol_1", - Name: "snapname", - }, - expectedErr: status.Errorf(codes.Internal, `GetFileShareInfo(vol_1) failed with error: error parsing volume id: "vol_1", should at least contain two #`), - }, - } + d.cloud = &azure.Cloud{} - for _, test := range tests { - _, err := d.CreateSnapshot(context.Background(), test.req) - if !reflect.DeepEqual(err, test.expectedErr) { + tests := []struct { + desc string + req *csi.CreateSnapshotRequest + expectedErr error + }{ + { + desc: "Snapshot name missing", + req: &csi.CreateSnapshotRequest{}, + expectedErr: status.Error(codes.InvalidArgument, "Snapshot name must be provided"), + }, + { + desc: "Source volume ID", + req: &csi.CreateSnapshotRequest{ + Name: "snapname", + }, + expectedErr: status.Error(codes.InvalidArgument, "CreateSnapshot Source Volume ID must be provided"), + }, + { + desc: "Invalid volume ID", + req: &csi.CreateSnapshotRequest{ + SourceVolumeId: "vol_1", + Name: "snapname", + }, + expectedErr: status.Errorf(codes.Internal, `GetFileShareInfo(vol_1) failed with error: error parsing volume id: "vol_1", should at least contain two #`), + }, + } - t.Errorf("test[%s]: unexpected error: %v, expected error: %v", test.desc, err, test.expectedErr) - } - } -} + for _, test := range tests { + _, err := d.CreateSnapshot(context.Background(), test.req) + gomega.Expect(err).To(gomega.Equal(test.expectedErr)) + } + }) + }) +}) +var _ = ginkgo.Describe("DeleteSnapshot", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { -func TestDeleteSnapshot(t *testing.T) { - d := NewFakeDriver() - d.cloud = &azure.Cloud{} + d := NewFakeDriver() - validSecret := map[string]string{} - ctrl := gomock.NewController(t) - defer ctrl.Finish() - value := base64.StdEncoding.EncodeToString([]byte("acc_key")) - key := storage.AccountListKeysResult{ - Keys: &[]storage.AccountKey{ - {Value: &value}, - }, - } - clientSet := fake.NewSimpleClientset() + d.cloud = &azure.Cloud{} - tests := []struct { - desc string - req *csi.DeleteSnapshotRequest - expectedErr error - }{ - { - desc: "Snapshot name missing", - req: &csi.DeleteSnapshotRequest{}, - expectedErr: status.Error(codes.InvalidArgument, "Snapshot ID must be provided"), - }, - { - desc: "Invalid volume ID", - req: &csi.DeleteSnapshotRequest{ - SnapshotId: "vol_1#", - }, - expectedErr: nil, - }, - { - desc: "Invalid volume ID for snapshot name", - req: &csi.DeleteSnapshotRequest{ - SnapshotId: "vol_1##", - Secrets: validSecret, - }, - expectedErr: nil, - }, - { - desc: "Invalid Snapshot ID", - req: &csi.DeleteSnapshotRequest{ - SnapshotId: "testrg#testAccount#testFileShare#testuuid", - Secrets: map[string]string{"accountName": "TestAccountName", "accountKey": base64.StdEncoding.EncodeToString([]byte("TestAccountKey"))}, - }, - expectedErr: status.Error(codes.Internal, "failed to get snapshot name with (testrg#testAccount#testFileShare#testuuid): error parsing volume id: \"testrg#testAccount#testFileShare#testuuid\", should at least contain four #"), - }, - } + validSecret := map[string]string{} + ctrl := gomock.NewController(ginkgo.GinkgoT()) - for _, test := range tests { - mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) - d.cloud.StorageAccountClient = mockStorageAccountsClient - d.cloud.KubeClient = clientSet - d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} - mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), "vol_1", gomock.Any()).Return(key, nil).AnyTimes() + defer ctrl.Finish() + value := base64.StdEncoding.EncodeToString([]byte("acc_key")) + key := storage.AccountListKeysResult{ + Keys: &[]storage.AccountKey{ + {Value: &value}, + }, + } + clientSet := fake.NewSimpleClientset() - _, err := d.DeleteSnapshot(context.Background(), test.req) - if !reflect.DeepEqual(err, test.expectedErr) { + tests := []struct { + desc string + req *csi.DeleteSnapshotRequest + expectedErr error + }{ + { + desc: "Snapshot name missing", + req: &csi.DeleteSnapshotRequest{}, + expectedErr: status.Error(codes.InvalidArgument, "Snapshot ID must be provided"), + }, + { + desc: "Invalid volume ID", + req: &csi.DeleteSnapshotRequest{ + SnapshotId: "vol_1#", + }, + expectedErr: nil, + }, + { + desc: "Invalid volume ID for snapshot name", + req: &csi.DeleteSnapshotRequest{ + SnapshotId: "vol_1##", + Secrets: validSecret, + }, + expectedErr: nil, + }, + { + desc: "Invalid Snapshot ID", + req: &csi.DeleteSnapshotRequest{ + SnapshotId: "testrg#testAccount#testFileShare#testuuid", + Secrets: map[string]string{"accountName": "TestAccountName", "accountKey": base64.StdEncoding.EncodeToString([]byte("TestAccountKey"))}, + }, + expectedErr: status.Error(codes.Internal, "failed to get snapshot name with (testrg#testAccount#testFileShare#testuuid): error parsing volume id: \"testrg#testAccount#testFileShare#testuuid\", should at least contain four #"), + }, + } - t.Errorf("test[%s]: unexpected error: %v, expected error: %v", test.desc, err, test.expectedErr) - } - } -} + for _, test := range tests { + mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) + d.cloud.StorageAccountClient = mockStorageAccountsClient + d.cloud.KubeClient = clientSet + d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} + mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), "vol_1", gomock.Any()).Return(key, nil).AnyTimes() + + _, err := d.DeleteSnapshot(context.Background(), test.req) + if test.expectedErr == nil { + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + } else { + gomega.Expect(err).To(gomega.Equal(test.expectedErr)) + } + } + }) + }) +}) var _ = ginkgo.Describe("TestControllerExpandVolume", func() { stdVolSize := int64(5 * 1024 * 1024 * 1024) stdCapRange := &csi.CapacityRange{RequiredBytes: stdVolSize} + var ctrl *gomock.Controller + var d *Driver ginkgo.BeforeEach(func() { stdVolSize = int64(5 * 1024 * 1024 * 1024) stdCapRange = &csi.CapacityRange{RequiredBytes: stdVolSize} + ctrl = gomock.NewController(ginkgo.GinkgoT()) + d = NewFakeDriver() + }) + ginkgo.AfterEach(func() { + ctrl.Finish() }) ginkgo.When("Volume ID missing", func() { ginkgo.It("should fail", func(ctx context.Context) { req := &csi.ControllerExpandVolumeRequest{} - d := NewFakeDriver() - expectedErr := status.Error(codes.InvalidArgument, "Volume ID missing in request") _, err := d.ControllerExpandVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Volume Capacity range missing", func() { @@ -2284,15 +2073,11 @@ var _ = ginkgo.Describe("TestControllerExpandVolume", func() { VolumeId: "vol_1", } - d := NewFakeDriver() d.Cap = []*csi.ControllerServiceCapability{} expectedErr := status.Error(codes.InvalidArgument, "volume capacity range missing in request") _, err := d.ControllerExpandVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Volume capabilities missing", func() { @@ -2302,15 +2087,11 @@ var _ = ginkgo.Describe("TestControllerExpandVolume", func() { CapacityRange: stdCapRange, } - d := NewFakeDriver() d.Cap = []*csi.ControllerServiceCapability{} expectedErr := status.Errorf(codes.InvalidArgument, "invalid expand volume request: volume_id:\"vol_1\" capacity_range: ") _, err := d.ControllerExpandVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Invalid Volume ID", func() { @@ -2320,23 +2101,16 @@ var _ = ginkgo.Describe("TestControllerExpandVolume", func() { CapacityRange: stdCapRange, } - d := NewFakeDriver() - expectedErr := status.Errorf(codes.InvalidArgument, "GetFileShareInfo(vol_1) failed with error: error parsing volume id: \"vol_1\", should at least contain two #") _, err := d.ControllerExpandVolume(ctx, req) - if !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("Disk name not empty", func() { ginkgo.It("should fail", func(ctx context.Context) { - d := NewFakeDriver() + d.cloud = &azure.Cloud{} - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() value := base64.StdEncoding.EncodeToString([]byte("acc_key")) key := storage.AccountListKeysResult{ Keys: &[]storage.AccountKey{ @@ -2357,19 +2131,14 @@ var _ = ginkgo.Describe("TestControllerExpandVolume", func() { expectErr := status.Error(codes.Unimplemented, "vhd disk volume(vol_1#f5713de20cde511e8ba4900#filename#diskname.vhd#, diskName:diskname.vhd) is not supported on ControllerExpandVolume") _, err := d.ControllerExpandVolume(ctx, req) - if !reflect.DeepEqual(err, expectErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v, expected error: %v", err, expectErr) - } + gomega.Expect(err).To(gomega.Equal(expectErr)) }) }) ginkgo.When("Resize file share returns error", func() { ginkgo.It("should fail", func(ctx context.Context) { - d := NewFakeDriver() + d.cloud = &azure.Cloud{} - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() value := base64.StdEncoding.EncodeToString([]byte("acc_key")) key := storage.AccountListKeysResult{ Keys: &[]storage.AccountKey{ @@ -2394,15 +2163,12 @@ var _ = ginkgo.Describe("TestControllerExpandVolume", func() { expectErr := status.Errorf(codes.Internal, "expand volume error: test error") _, err := d.ControllerExpandVolume(ctx, req) - if !reflect.DeepEqual(err, expectErr) { - - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } + gomega.Expect(err).To(gomega.Equal(expectErr)) }) }) ginkgo.When("get account info failed", func() { ginkgo.It("should fail", func(ctx context.Context) { - d := NewFakeDriver() + d.cloud = &azure.Cloud{ Config: azure.Config{ ResourceGroup: "vol_2", @@ -2410,8 +2176,7 @@ var _ = ginkgo.Describe("TestControllerExpandVolume", func() { } d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(_ string) (interface{}, error) { return nil, nil }, false) d.dataPlaneAPIAccountCache.Set("f5713de20cde511e8ba4900", "1") - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() + value := base64.StdEncoding.EncodeToString([]byte("acc_key")) key := storage.AccountListKeysResult{ Keys: &[]storage.AccountKey{ @@ -2432,19 +2197,15 @@ var _ = ginkgo.Describe("TestControllerExpandVolume", func() { expectErr := status.Error(codes.NotFound, "get account info from(#f5713de20cde511e8ba4900#filename##secret) failed with error: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 502, RawError: instance not found") _, err := d.ControllerExpandVolume(ctx, req) - if !reflect.DeepEqual(err, expectErr) { + gomega.Expect(err).To(gomega.Equal(expectErr)) - ginkgo.GinkgoT().Errorf("Unexpected error: %v", err) - } }) }) ginkgo.When("Valid request", func() { ginkgo.It("should fail", func(ctx context.Context) { - d := NewFakeDriver() + d.cloud = &azure.Cloud{} - ctrl := gomock.NewController(ginkgo.GinkgoT()) - defer ctrl.Finish() value := base64.StdEncoding.EncodeToString([]byte("acc_key")) key := storage.AccountListKeysResult{ Keys: &[]storage.AccountKey{ @@ -2479,333 +2240,338 @@ var _ = ginkgo.Describe("TestControllerExpandVolume", func() { }) }) -func TestGetShareURL(t *testing.T) { - d := NewFakeDriver() - validSecret := map[string]string{} - d.cloud = &azure.Cloud{} +var _ = ginkgo.Describe("GetShareURL", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - value := base64.StdEncoding.EncodeToString([]byte("acc_key")) - key := storage.AccountListKeysResult{ - Keys: &[]storage.AccountKey{ - {Value: &value}, - }, - } - clientSet := fake.NewSimpleClientset() - tests := []struct { - desc string - sourceVolumeID string - expectedErr error - }{ - { - desc: "Volume ID error", - sourceVolumeID: "vol_1", - expectedErr: fmt.Errorf("failed to get file share from vol_1"), - }, - { - desc: "Volume ID error2", - sourceVolumeID: "vol_1###", - expectedErr: fmt.Errorf("failed to get file share from vol_1###"), - }, - { - desc: "Valid request", - sourceVolumeID: "rg#accountname#fileshare#", - expectedErr: nil, - }, - } - - for _, test := range tests { - mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) - d.cloud.StorageAccountClient = mockStorageAccountsClient - d.cloud.KubeClient = clientSet - d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} - mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), "rg", gomock.Any()).Return(key, nil).AnyTimes() - _, err := d.getShareURL(context.Background(), test.sourceVolumeID, validSecret) - if !reflect.DeepEqual(err, test.expectedErr) { - - t.Errorf("test[%s]: unexpected error: %v, expected error: %v", test.desc, err, test.expectedErr) - } - } -} - -func TestGetServiceURL(t *testing.T) { - d := NewFakeDriver() - validSecret := map[string]string{} - d.cloud = &azure.Cloud{} + d := NewFakeDriver() - ctrl := gomock.NewController(t) - defer ctrl.Finish() - value := base64.StdEncoding.EncodeToString([]byte("acc_key")) - errValue := "acc_key" - validKey := storage.AccountListKeysResult{ - Keys: &[]storage.AccountKey{ - {Value: &value}, - }, - } - errKey := storage.AccountListKeysResult{ - Keys: &[]storage.AccountKey{ - {Value: &errValue}, - }, - } - clientSet := fake.NewSimpleClientset() - tests := []struct { - desc string - sourceVolumeID string - key storage.AccountListKeysResult - expectedErr error - }{ - { - desc: "Invalid volume ID", - sourceVolumeID: "vol_1", - key: validKey, - expectedErr: nil, - }, - { - desc: "Invalid Key", - sourceVolumeID: "vol_1##", - key: errKey, - expectedErr: nil, - }, - { - desc: "Invalid URL", - sourceVolumeID: "vol_1#^f5713de20cde511e8ba4900#", - key: validKey, - expectedErr: &url.Error{Op: "parse", URL: "https://^f5713de20cde511e8ba4900.file.abc", Err: url.InvalidHostError("^")}, - }, - { - desc: "Valid call", - sourceVolumeID: "vol_1##", - key: validKey, - expectedErr: nil, - }, - } + validSecret := map[string]string{} + d.cloud = &azure.Cloud{} - for _, test := range tests { - mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) - d.cloud.StorageAccountClient = mockStorageAccountsClient - d.cloud.KubeClient = clientSet - d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} - mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), "vol_1", gomock.Any()).Return(test.key, nil).AnyTimes() + ctrl := gomock.NewController(ginkgo.GinkgoT()) - _, _, err := d.getServiceURL(context.Background(), test.sourceVolumeID, validSecret) - if !reflect.DeepEqual(err, test.expectedErr) { + defer ctrl.Finish() + value := base64.StdEncoding.EncodeToString([]byte("acc_key")) + key := storage.AccountListKeysResult{ + Keys: &[]storage.AccountKey{ + {Value: &value}, + }, + } + clientSet := fake.NewSimpleClientset() + tests := []struct { + desc string + sourceVolumeID string + expectedErr error + }{ + { + desc: "Volume ID error", + sourceVolumeID: "vol_1", + expectedErr: fmt.Errorf("failed to get file share from vol_1"), + }, + { + desc: "Volume ID error2", + sourceVolumeID: "vol_1###", + expectedErr: fmt.Errorf("failed to get file share from vol_1###"), + }, + { + desc: "Valid request", + sourceVolumeID: "rg#accountname#fileshare#", + expectedErr: nil, + }, + } - t.Errorf("test[%s]: unexpected error: %v, expected error: %v", test.desc, err, test.expectedErr) - } - } -} + for _, test := range tests { + mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) + d.cloud.StorageAccountClient = mockStorageAccountsClient + d.cloud.KubeClient = clientSet + d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} + mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), "rg", gomock.Any()).Return(key, nil).AnyTimes() + _, err := d.getShareURL(context.Background(), test.sourceVolumeID, validSecret) + if test.expectedErr == nil { + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + } else { + gomega.Expect(err).To(gomega.Equal(test.expectedErr)) + } + } + }) + }) +}) -func TestSnapshotExists(t *testing.T) { +var _ = ginkgo.DescribeTable("GetServiceURL", func(sourceVolumeID string, key storage.AccountListKeysResult, expectedErr error) { d := NewFakeDriver() validSecret := map[string]string{} d.cloud = &azure.Cloud{} - - ctrl := gomock.NewController(t) + ctrl := gomock.NewController(ginkgo.GinkgoT()) defer ctrl.Finish() - value := base64.StdEncoding.EncodeToString([]byte("acc_key")) - validKey := storage.AccountListKeysResult{ + clientSet := fake.NewSimpleClientset() + mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) + d.cloud.StorageAccountClient = mockStorageAccountsClient + d.cloud.KubeClient = clientSet + d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} + mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), "vol_1", gomock.Any()).Return(key, nil).AnyTimes() + + _, _, err := d.getServiceURL(context.Background(), sourceVolumeID, validSecret) + if expectedErr == nil { + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + } else { + gomega.Expect(err).To(gomega.Equal(expectedErr)) + } +}, + ginkgo.Entry("Invalid volume ID", "vol_1", storage.AccountListKeysResult{ Keys: &[]storage.AccountKey{ - {Value: &value}, + {Value: to.Ptr(base64.StdEncoding.EncodeToString([]byte("acc_key")))}, }, - } - - clientSet := fake.NewSimpleClientset() - tests := []struct { - desc string - sourceVolumeID string - key storage.AccountListKeysResult - secret map[string]string - expectedErr error - }{ - { - desc: "Invalid volume ID with data plane api", - sourceVolumeID: "vol_1", - key: validKey, - secret: map[string]string{"accountName": "TestAccountName", "accountKey": base64.StdEncoding.EncodeToString([]byte("TestAccountKey"))}, - expectedErr: fmt.Errorf("file share is empty after parsing sourceVolumeID: vol_1"), + }, nil), + ginkgo.Entry("Invalid Key", + "vol_1##", + storage.AccountListKeysResult{ + Keys: &[]storage.AccountKey{ + {Value: to.Ptr("acc_key")}, + }, }, - { - desc: "Invalid volume ID with management api", - sourceVolumeID: "vol_1", - key: validKey, - secret: validSecret, - expectedErr: fmt.Errorf("error parsing volume id: %q, should at least contain two #", "vol_1"), + nil, + ), + ginkgo.Entry("Invalid URL", + "vol_1#^f5713de20cde511e8ba4900#", + storage.AccountListKeysResult{ + Keys: &[]storage.AccountKey{ + {Value: to.Ptr(base64.StdEncoding.EncodeToString([]byte("acc_key")))}, + }, }, - } - - for _, test := range tests { - mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) - d.cloud.StorageAccountClient = mockStorageAccountsClient - d.cloud.KubeClient = clientSet - d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} - mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), "", gomock.Any()).Return(test.key, nil).AnyTimes() - - _, _, _, _, err := d.snapshotExists(context.Background(), test.sourceVolumeID, "sname", test.secret, false) - if !reflect.DeepEqual(err, test.expectedErr) { - - t.Errorf("test[%s]: unexpected error: %v, expected error: %v", test.desc, err, test.expectedErr) - } - } -} - -func TestGetCapacity(t *testing.T) { - d := NewFakeDriver() - req := csi.GetCapacityRequest{} - resp, err := d.GetCapacity(context.Background(), &req) - assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + &url.Error{Op: "parse", URL: "https://^f5713de20cde511e8ba4900.file.abc", Err: url.InvalidHostError("^")}, + ), + ginkgo.Entry("Valid call", + "vol_1##", + storage.AccountListKeysResult{ + Keys: &[]storage.AccountKey{ + {Value: to.Ptr(base64.StdEncoding.EncodeToString([]byte("acc_key")))}, + }, + }, + nil, + ), +) - t.Errorf("Unexpected error: %v", err) - } -} +var _ = ginkgo.Describe("SnapshotExists", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { + d := NewFakeDriver() + validSecret := map[string]string{} + d.cloud = &azure.Cloud{} + ctrl := gomock.NewController(ginkgo.GinkgoT()) + defer ctrl.Finish() + value := base64.StdEncoding.EncodeToString([]byte("acc_key")) + validKey := storage.AccountListKeysResult{ + Keys: &[]storage.AccountKey{ + {Value: &value}, + }, + } + clientSet := fake.NewSimpleClientset() + tests := []struct { + desc string + sourceVolumeID string + key storage.AccountListKeysResult + secret map[string]string + expectedErr error + }{ + { + desc: "Invalid volume ID with data plane api", + sourceVolumeID: "vol_1", + key: validKey, + secret: map[string]string{"accountName": "TestAccountName", "accountKey": base64.StdEncoding.EncodeToString([]byte("TestAccountKey"))}, + expectedErr: fmt.Errorf("file share is empty after parsing sourceVolumeID: vol_1"), + }, + { + desc: "Invalid volume ID with management api", + sourceVolumeID: "vol_1", + key: validKey, + secret: validSecret, + expectedErr: fmt.Errorf("error parsing volume id: %q, should at least contain two #", "vol_1"), + }, + } -func TestListVolumes(t *testing.T) { - d := NewFakeDriver() - req := csi.ListVolumesRequest{} - resp, err := d.ListVolumes(context.Background(), &req) - assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { + for _, test := range tests { + mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl) + d.cloud.StorageAccountClient = mockStorageAccountsClient + d.cloud.KubeClient = clientSet + d.cloud.Environment = azure2.Environment{StorageEndpointSuffix: "abc"} + mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), "", gomock.Any()).Return(test.key, nil).AnyTimes() - t.Errorf("Unexpected error: %v", err) - } -} + _, _, _, _, err := d.snapshotExists(context.Background(), test.sourceVolumeID, "sname", test.secret, false) + gomega.Expect(err).To(gomega.Equal(test.expectedErr)) + } + }) + }) +}) -func TestListSnapshots(t *testing.T) { - d := NewFakeDriver() - req := csi.ListSnapshotsRequest{} - resp, err := d.ListSnapshots(context.Background(), &req) - assert.Nil(t, resp) - if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) { +var _ = ginkgo.Describe("GetCapacity", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { - t.Errorf("Unexpected error: %v", err) - } -} + d := NewFakeDriver() + req := csi.GetCapacityRequest{} + resp, err := d.GetCapacity(context.Background(), &req) + gomega.Expect(resp).To(gomega.BeNil()) + gomega.Expect(err).To(gomega.Equal(status.Error(codes.Unimplemented, ""))) + }) + }) +}) -func TestSetAzureCredentials(t *testing.T) { - d := NewFakeDriver() - d.cloud = &azure.Cloud{ - Config: azure.Config{ - ResourceGroup: "rg", - Location: "loc", - VnetName: "fake-vnet", - SubnetName: "fake-subnet", - }, - } - fakeClient := fake.NewSimpleClientset() - - tests := []struct { - desc string - kubeClient kubernetes.Interface - accountName string - accountKey string - secretName string - secretNamespace string - expectedName string - expectedErr error - }{ - { - desc: "[failure] accountName is nil", - kubeClient: fakeClient, - expectedErr: fmt.Errorf("the account info is not enough, accountName(), accountKey()"), - }, - { - desc: "[failure] accountKey is nil", - kubeClient: fakeClient, - accountName: "testName", - accountKey: "", - expectedErr: fmt.Errorf("the account info is not enough, accountName(testName), accountKey()"), - }, - { - desc: "[success] kubeClient is nil", - kubeClient: nil, - expectedErr: nil, - }, - { - desc: "[success] normal scenario", - kubeClient: fakeClient, - accountName: "testName", - accountKey: "testKey", - expectedName: "azure-storage-account-testName-secret", - expectedErr: nil, - }, - { - desc: "[success] already exist", - kubeClient: fakeClient, - accountName: "testName", - accountKey: "testKey", - expectedName: "azure-storage-account-testName-secret", - expectedErr: nil, - }, - { - desc: "[success] normal scenario using secretName", - kubeClient: fakeClient, - accountName: "testName", - accountKey: "testKey", - secretName: "secretName", - secretNamespace: "secretNamespace", - expectedName: "secretName", - expectedErr: nil, - }, - } +var _ = ginkgo.Describe("ListVolumes", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { + d := NewFakeDriver() + req := csi.ListVolumesRequest{} + resp, err := d.ListVolumes(context.Background(), &req) + gomega.Expect(resp).To(gomega.BeNil()) + gomega.Expect(err).To(gomega.Equal(status.Error(codes.Unimplemented, ""))) + }) + }) +}) - for _, test := range tests { - d.cloud.KubeClient = test.kubeClient - result, err := d.SetAzureCredentials(context.Background(), test.accountName, test.accountKey, test.secretName, test.secretNamespace) - if result != test.expectedName || !reflect.DeepEqual(err, test.expectedErr) { +var _ = ginkgo.Describe("ListSnapshots", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { + d := NewFakeDriver() + req := csi.ListSnapshotsRequest{} + resp, err := d.ListSnapshots(context.Background(), &req) + gomega.Expect(resp).To(gomega.BeNil()) + gomega.Expect(err).To(gomega.Equal(status.Error(codes.Unimplemented, ""))) + }) + }) +}) - t.Errorf("desc: %s,\n input: accountName(%v), accountKey(%v),\n setAzureCredentials result: %v, expectedName: %v err: %v, expectedErr: %v", - test.desc, test.accountName, test.accountKey, result, test.expectedName, err, test.expectedErr) - } - } -} +var _ = ginkgo.Describe("SetAzureCredentials", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { + d := NewFakeDriver() + d.cloud = &azure.Cloud{ + Config: azure.Config{ + ResourceGroup: "rg", + Location: "loc", + VnetName: "fake-vnet", + SubnetName: "fake-subnet", + }, + } + fakeClient := fake.NewSimpleClientset() -func TestGenerateSASToken(t *testing.T) { - d := NewFakeDriver() - storageEndpointSuffix := "core.windows.net" - tests := []struct { - name string - accountName string - accountKey string - want string - expectedErr error - }{ - { - name: "accountName nil", - accountName: "", - accountKey: "", - want: "se=", - expectedErr: nil, - }, - { - name: "account key illegal", - accountName: "unit-test", - accountKey: "fakeValue", - want: "", - expectedErr: status.Errorf(codes.Internal, "failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", "unit-test", "decode account key: illegal base64 data at input byte 8"), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - sas, err := d.generateSASToken(tt.accountName, tt.accountKey, storageEndpointSuffix, 30) - if !reflect.DeepEqual(err, tt.expectedErr) { + tests := []struct { + desc string + kubeClient kubernetes.Interface + accountName string + accountKey string + secretName string + secretNamespace string + expectedName string + expectedErr error + }{ + { + desc: "[failure] accountName is nil", + kubeClient: fakeClient, + expectedErr: fmt.Errorf("the account info is not enough, accountName(), accountKey()"), + }, + { + desc: "[failure] accountKey is nil", + kubeClient: fakeClient, + accountName: "testName", + accountKey: "", + expectedErr: fmt.Errorf("the account info is not enough, accountName(testName), accountKey()"), + }, + { + desc: "[success] kubeClient is nil", + kubeClient: nil, + expectedErr: nil, + }, + { + desc: "[success] normal scenario", + kubeClient: fakeClient, + accountName: "testName", + accountKey: "testKey", + expectedName: "azure-storage-account-testName-secret", + expectedErr: nil, + }, + { + desc: "[success] already exist", + kubeClient: fakeClient, + accountName: "testName", + accountKey: "testKey", + expectedName: "azure-storage-account-testName-secret", + expectedErr: nil, + }, + { + desc: "[success] normal scenario using secretName", + kubeClient: fakeClient, + accountName: "testName", + accountKey: "testKey", + secretName: "secretName", + secretNamespace: "secretNamespace", + expectedName: "secretName", + expectedErr: nil, + }, + } - t.Errorf("generateSASToken error = %v, expectedErr %v, sas token = %v, want %v", err, tt.expectedErr, sas, tt.want) - return + for _, test := range tests { + d.cloud.KubeClient = test.kubeClient + result, err := d.SetAzureCredentials(context.Background(), test.accountName, test.accountKey, test.secretName, test.secretNamespace) + gomega.Expect(result).To(gomega.Equal(test.expectedName)) + if test.expectedErr == nil { + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + } else { + gomega.Expect(err).To(gomega.Equal(test.expectedErr)) + } } - if !strings.Contains(sas, tt.want) { + }) + }) +}) - ginkgo.GinkgoT().Errorf("sas token = %v, want %v", sas, tt.want) +var _ = ginkgo.Describe("GenerateSASToken", func() { + ginkgo.When("test", func() { + ginkgo.It("should work", func(_ context.Context) { + d := NewFakeDriver() + storageEndpointSuffix := "core.windows.net" + tests := []struct { + name string + accountName string + accountKey string + want string + expectedErr error + }{ + { + name: "accountName nil", + accountName: "", + accountKey: "", + want: "se=", + expectedErr: nil, + }, + { + name: "account key illegal", + accountName: "unit-test", + accountKey: "fakeValue", + want: "", + expectedErr: status.Errorf(codes.Internal, "failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", "unit-test", "decode account key: illegal base64 data at input byte 8"), + }, + } + for _, tt := range tests { + sas, err := d.generateSASToken(tt.accountName, tt.accountKey, storageEndpointSuffix, 30) + if tt.expectedErr == nil { + gomega.Expect(err).NotTo(gomega.HaveOccurred()) + } else { + gomega.Expect(err).To(gomega.Equal(tt.expectedErr)) + } + gomega.Expect(sas).To(gomega.ContainSubstring(tt.want)) } }) - } -} + }) +}) var _ = ginkgo.Describe("TestAuthorizeAzcopyWithIdentity", func() { + var d *Driver + ginkgo.BeforeEach(func() { + d = NewFakeDriver() + }) ginkgo.When("use service principal to authorize azcopy", func() { ginkgo.It("should fail", func(_ context.Context) { - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{ AzureAuthConfig: config.AzureAuthConfig{ @@ -2833,7 +2599,6 @@ var _ = ginkgo.Describe("TestAuthorizeAzcopyWithIdentity", func() { }) ginkgo.When("use service principal to authorize azcopy but client id is empty", func() { ginkgo.It("should fail", func(_ context.Context) { - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{ AzureAuthConfig: config.AzureAuthConfig{ @@ -2849,15 +2614,12 @@ var _ = ginkgo.Describe("TestAuthorizeAzcopyWithIdentity", func() { expectedAuthAzcopyEnv := []string{} expectedErr := fmt.Errorf("AADClientID and TenantID must be set when use service principal") authAzcopyEnv, err := d.authorizeAzcopyWithIdentity() - if !reflect.DeepEqual(authAzcopyEnv, expectedAuthAzcopyEnv) || !reflect.DeepEqual(err, expectedErr) { - - ginkgo.GinkgoT().Errorf("Unexpected authAzcopyEnv: %v, Unexpected error: %v", authAzcopyEnv, err) - } + gomega.Expect(authAzcopyEnv).To(gomega.Equal(expectedAuthAzcopyEnv)) + gomega.Expect(err).To(gomega.Equal(expectedErr)) }) }) ginkgo.When("use user assigned managed identity to authorize azcopy", func() { ginkgo.It("should fail", func(_ context.Context) { - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{ AzureAuthConfig: config.AzureAuthConfig{ @@ -2875,14 +2637,13 @@ var _ = ginkgo.Describe("TestAuthorizeAzcopyWithIdentity", func() { var expected error authAzcopyEnv, err := d.authorizeAzcopyWithIdentity() if !reflect.DeepEqual(authAzcopyEnv, expectedAuthAzcopyEnv) || !reflect.DeepEqual(err, expected) { - ginkgo.GinkgoT().Errorf("Unexpected authAzcopyEnv: %v, Unexpected error: %v", authAzcopyEnv, err) } }) }) ginkgo.When("use system assigned managed identity to authorize azcopy", func() { ginkgo.It("should fail", func(_ context.Context) { - d := NewFakeDriver() + d.cloud = &azure.Cloud{ Config: azure.Config{ AzureAuthConfig: config.AzureAuthConfig{ @@ -2905,7 +2666,7 @@ var _ = ginkgo.Describe("TestAuthorizeAzcopyWithIdentity", func() { }) ginkgo.When("AADClientSecret be nil and useManagedIdentityExtension is false", func() { ginkgo.It("should fail", func(_ context.Context) { - d := NewFakeDriver() + d.cloud = &azure.Cloud{ Config: azure.Config{ AzureAuthConfig: config.AzureAuthConfig{}, @@ -2915,7 +2676,6 @@ var _ = ginkgo.Describe("TestAuthorizeAzcopyWithIdentity", func() { expected := fmt.Errorf("neither the service principal nor the managed identity has been set") authAzcopyEnv, err := d.authorizeAzcopyWithIdentity() if !reflect.DeepEqual(authAzcopyEnv, expectedAuthAzcopyEnv) || !reflect.DeepEqual(err, expected) { - ginkgo.GinkgoT().Errorf("Unexpected authAzcopyEnv: %v, Unexpected error: %v", authAzcopyEnv, err) } }) @@ -2924,10 +2684,12 @@ var _ = ginkgo.Describe("TestAuthorizeAzcopyWithIdentity", func() { }) var _ = ginkgo.Describe("TestGetAzcopyAuth", func() { - + var d *Driver + ginkgo.BeforeEach(func() { + d = NewFakeDriver() + }) ginkgo.When("failed to get accountKey in secrets", func() { ginkgo.It("should fail", func(ctx context.Context) { - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{}, } @@ -2938,15 +2700,13 @@ var _ = ginkgo.Describe("TestGetAzcopyAuth", func() { expectedAccountSASToken := "" expectedErr := fmt.Errorf("could not find accountkey or azurestorageaccountkey field in secrets") accountSASToken, authAzcopyEnv, err := d.getAzcopyAuth(ctx, "accountName", "", "core.windows.net", &azure.AccountOptions{}, secrets, "secretsName", "secretsNamespace", false) - if !reflect.DeepEqual(err, expectedErr) || authAzcopyEnv != nil || !reflect.DeepEqual(accountSASToken, expectedAccountSASToken) { - - ginkgo.GinkgoT().Errorf("Unexpected accountSASToken: %s, Unexpected authAzcopyEnv: %v, Unexpected error: %v", accountSASToken, authAzcopyEnv, err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) + gomega.Expect(authAzcopyEnv).To(gomega.BeNil()) + gomega.Expect(accountSASToken).To(gomega.Equal(expectedAccountSASToken)) }) }) ginkgo.When("generate SAS token failed for illegal account key", func() { ginkgo.It("should fail", func(ctx context.Context) { - d := NewFakeDriver() d.cloud = &azure.Cloud{ Config: azure.Config{}, } @@ -2958,10 +2718,9 @@ var _ = ginkgo.Describe("TestGetAzcopyAuth", func() { expectedAccountSASToken := "" expectedErr := status.Errorf(codes.Internal, "failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", "accountName", "decode account key: illegal base64 data at input byte 8") accountSASToken, authAzcopyEnv, err := d.getAzcopyAuth(ctx, "accountName", "", "core.windows.net", &azure.AccountOptions{}, secrets, "secretsName", "secretsNamespace", false) - if !reflect.DeepEqual(err, expectedErr) || authAzcopyEnv != nil || !reflect.DeepEqual(accountSASToken, expectedAccountSASToken) { - - ginkgo.GinkgoT().Errorf("Unexpected accountSASToken: %s, Unexpected authAzcopyEnv: %v, Unexpected error: %v", accountSASToken, authAzcopyEnv, err) - } + gomega.Expect(err).To(gomega.Equal(expectedErr)) + gomega.Expect(authAzcopyEnv).To(gomega.BeNil()) + gomega.Expect(accountSASToken).To(gomega.Equal(expectedAccountSASToken)) }) }) })