Skip to content

Commit cd10164

Browse files
committedJul 8, 2022
added 2 testcases for getContainerReference()
1 parent ade9f5a commit cd10164

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
 

Diff for: ‎pkg/blob/blob_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,65 @@ func TestGetStorageAccount(t *testing.T) {
743743
}
744744
}
745745

746+
//needs editing, could only get past first error for testing, could not get a fake environment running
747+
func TestGetContainerReference(t *testing.T) {
748+
fakeAccountName := "storageaccountname"
749+
fakeAccountKey := "test-key"
750+
fakeContainerName := "test-con"
751+
testCases := []struct {
752+
name string
753+
containerName string
754+
secrets map[string]string
755+
expectedError error
756+
}{
757+
{
758+
name: "failed to retrieve accountName",
759+
containerName: fakeContainerName,
760+
secrets: map[string]string{
761+
"accountKey": fakeAccountKey,
762+
},
763+
expectedError: fmt.Errorf("could not find %s or %s field secrets(%v)", accountNameField, defaultSecretAccountName, map[string]string{
764+
"accountKey": fakeAccountKey,
765+
}),
766+
},
767+
{
768+
name: "failed to retrieve accountKey",
769+
containerName: fakeContainerName,
770+
secrets: map[string]string{
771+
"accountName": fakeAccountName,
772+
},
773+
expectedError: fmt.Errorf("could not find %s or %s field in secrets(%v)", accountKeyField, defaultSecretAccountKey, map[string]string{
774+
"accountName": fakeAccountName,
775+
}),
776+
},
777+
/*{
778+
name: "container reference is nil",
779+
containerName: fakeContainerName,
780+
secrets: map[string]string{
781+
"accountName": fakeAccountName,
782+
"accountKey": fakeAccountKey,
783+
},
784+
expectedError: fmt.Errorf("ContainerReference of %s is nil", fakeContainerName),
785+
},*/
786+
}
787+
788+
d := NewFakeDriver()
789+
d.cloud = &azure.Cloud{}
790+
d.cloud.KubeClient = fake.NewSimpleClientset()
791+
//d.cloud.Environment.StorageEndpointSuffix =
792+
for _, tc := range testCases {
793+
t.Run(tc.name, func(t *testing.T) {
794+
container, err := getContainerReference(tc.containerName, tc.secrets, d.cloud.Environment)
795+
if tc.expectedError != nil {
796+
assert.Error(t, err)
797+
assert.Equal(t, tc.expectedError, err)
798+
} else {
799+
container.Name = ""
800+
}
801+
})
802+
}
803+
}
804+
746805
func TestSetAzureCredentials(t *testing.T) {
747806
fakeClient := fake.NewSimpleClientset()
748807

0 commit comments

Comments
 (0)