Skip to content

Commit 4fc25ef

Browse files
committed
test: add unit test
1 parent d3cd71d commit 4fc25ef

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

pkg/blob/blob_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,54 @@ func TestGetAuthEnv(t *testing.T) {
588588
}
589589
},
590590
},
591+
{
592+
name: "valid request with MSIAuthTypeAddsIdentityEnv",
593+
testFunc: func(t *testing.T) {
594+
d := NewFakeDriver()
595+
d.cloud = &storage.AccountRepo{}
596+
d.cloud.Config.AzureAuthConfig = azclient.AzureAuthConfig{
597+
UserAssignedIdentityID: "unit-test-identity-id",
598+
}
599+
600+
attrib := map[string]string{
601+
subscriptionIDField: "subID",
602+
resourceGroupField: "rg",
603+
storageAccountField: "accountname",
604+
storageAccountNameField: "accountname",
605+
secretNameField: "secretName",
606+
secretNamespaceField: "sNS",
607+
containerNameField: "containername",
608+
mountWithWITokenField: "false",
609+
pvcNamespaceKey: "pvcNSKey",
610+
getAccountKeyFromSecretField: "false",
611+
storageAuthTypeField: storageAuthTypeMSI,
612+
msiEndpointField: "msiEndpoint",
613+
getLatestAccountKeyField: "true",
614+
}
615+
secret := make(map[string]string)
616+
volumeID := "rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41"
617+
ctrl := gomock.NewController(t)
618+
defer ctrl.Finish()
619+
mockStorageAccountsClient := mock_accountclient.NewMockInterface(ctrl)
620+
d.cloud.ComputeClientFactory = mock_azclient.NewMockClientFactory(ctrl)
621+
d.cloud.ComputeClientFactory.(*mock_azclient.MockClientFactory).EXPECT().GetAccountClient().Return(mockStorageAccountsClient).AnyTimes()
622+
s := "unit-test"
623+
accountkey := armstorage.AccountKey{Value: &s}
624+
list := []*armstorage.AccountKey{&accountkey}
625+
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any()).Return(list, nil).AnyTimes()
626+
d.cloud.ComputeClientFactory.(*mock_azclient.MockClientFactory).EXPECT().GetAccountClientForSub(gomock.Any()).Return(mockStorageAccountsClient, nil).AnyTimes()
627+
_, _, _, _, authEnv, err := d.GetAuthEnv(context.TODO(), volumeID, "", attrib, secret)
628+
assert.NoError(t, err)
629+
found := false
630+
for _, env := range authEnv {
631+
if env == "AZURE_STORAGE_IDENTITY_CLIENT_ID=unit-test-identity-id" {
632+
found = true
633+
break
634+
}
635+
}
636+
assert.True(t, found, "AZURE_STORAGE_IDENTITY_CLIENT_ID should be present in authEnv")
637+
},
638+
},
591639
{
592640
name: "invalid getLatestAccountKey value",
593641
testFunc: func(t *testing.T) {

0 commit comments

Comments
 (0)