Skip to content

Commit a7f487c

Browse files
committed
added testcase to getAuthEnv, and fixed some asserts (expected and actual were reversed)
1 parent c46b0ac commit a7f487c

File tree

1 file changed

+64
-8
lines changed

1 file changed

+64
-8
lines changed

pkg/blob/blob_test.go

+64-8
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,10 @@ func TestGetAuthEnv(t *testing.T) {
545545
if err != nil {
546546
t.Errorf("actualErr: (%v), expectedErr: nil", err)
547547
}
548-
assert.Equal(t, rg, "rg")
549-
assert.Equal(t, accountName, "accountname")
550-
assert.Equal(t, accountkey, "unit-test")
551-
assert.Equal(t, containerName, "containername")
548+
assert.Equal(t, "rg", rg)
549+
assert.Equal(t, "accountname", accountName)
550+
assert.Equal(t, "unit-test", accountkey)
551+
assert.Equal(t, "containername", containerName)
552552
},
553553
},
554554
{
@@ -565,13 +565,69 @@ func TestGetAuthEnv(t *testing.T) {
565565
t.Errorf("actualErr: (%v), expect no error", err)
566566
}
567567

568-
assert.Equal(t, rg, "")
569-
assert.Equal(t, accountName, "accountname")
570-
assert.Equal(t, accountkey, "")
571-
assert.Equal(t, containerName, "containername")
568+
assert.Equal(t, "", rg)
569+
assert.Equal(t, "accountname", accountName)
570+
assert.Equal(t, "", accountkey)
571+
assert.Equal(t, "containername", containerName)
572572
assert.Equal(t, len(authEnv), 0)
573573
},
574574
},
575+
{
576+
name: "failed to get keyvaultClient",
577+
testFunc: func(t *testing.T) {
578+
d := NewFakeDriver()
579+
d.cloud = &azure.Cloud{}
580+
d.cloud.ResourceGroup = "rg"
581+
attrib := make(map[string]string)
582+
secret := make(map[string]string)
583+
volumeID := "unique-volumeid"
584+
attrib[keyVaultURLField] = "kvURL"
585+
attrib[storageAccountField] = "accountname"
586+
attrib[containerNameField] = "containername"
587+
_, _, _, _, _, err := d.GetAuthEnv(context.TODO(), volumeID, "", attrib, secret)
588+
expectedErrStr := "failed to get keyvaultClient:"
589+
assert.Error(t, err)
590+
assert.Contains(t, err.Error(), expectedErrStr)
591+
},
592+
},
593+
{
594+
name: "valid request with all other attr",
595+
testFunc: func(t *testing.T) {
596+
d := NewFakeDriver()
597+
attrib := make(map[string]string)
598+
attrib[subscriptionIDField] = "subID"
599+
attrib[secretNameField] = "secretName"
600+
attrib[secretNamespaceField] = "sNS"
601+
attrib[pvcNamespaceKey] = "pvcNSKey"
602+
attrib[getAccountKeyFromSecretField] = "akFromSecret"
603+
604+
secret := make(map[string]string)
605+
volumeID := "rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41"
606+
d.cloud = &azure.Cloud{}
607+
ctrl := gomock.NewController(t)
608+
defer ctrl.Finish()
609+
mockStorageAccountsClient := mockstorageaccountclient.NewMockInterface(ctrl)
610+
d.cloud.StorageAccountClient = mockStorageAccountsClient
611+
s := "unit-test"
612+
accountkey := storage.AccountKey{
613+
Value: &s,
614+
}
615+
accountkeylist := []storage.AccountKey{}
616+
accountkeylist = append(accountkeylist, accountkey)
617+
list := storage.AccountListKeysResult{
618+
Keys: &accountkeylist,
619+
}
620+
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(list, nil).AnyTimes()
621+
rg, accountName, _, containerName, _, err := d.GetAuthEnv(context.TODO(), volumeID, "", attrib, secret)
622+
expectedErr := error(nil)
623+
if !reflect.DeepEqual(err, expectedErr) {
624+
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
625+
}
626+
assert.Equal(t, rg, "rg")
627+
assert.Equal(t, "f5713de20cde511e8ba4900", accountName)
628+
assert.Equal(t, "pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41", containerName)
629+
},
630+
},
575631
}
576632
for _, tc := range testCases {
577633
t.Run(tc.name, tc.testFunc)

0 commit comments

Comments
 (0)