@@ -36,6 +36,57 @@ import (
36
36
"sigs.k8s.io/cloud-provider-azure/pkg/retry"
37
37
)
38
38
39
+ type errType int32
40
+
41
+ const (
42
+ DATAPLANE errType = iota
43
+ MANAGEMENT
44
+ CUSTOM
45
+ NULL
46
+ )
47
+
48
+ //mock blobclient that returns the errortype for create/delete/get operations (default value nil)
49
+ type mockBlobClient struct {
50
+ //type of error returned
51
+ errorType errType
52
+ //custom string for error type CUSTOM
53
+ custom string
54
+ }
55
+
56
+ func (c * mockBlobClient ) CreateContainer (ctx context.Context , resourceGroupName , accountName , containerName string , blobContainer storage.BlobContainer ) error {
57
+ switch c .errorType {
58
+ case DATAPLANE :
59
+ return fmt .Errorf (containerBeingDeletedDataplaneAPIError )
60
+ case MANAGEMENT :
61
+ return fmt .Errorf (containerBeingDeletedManagementAPIError )
62
+ case CUSTOM :
63
+ return fmt .Errorf (c .custom )
64
+ }
65
+ return nil
66
+ }
67
+ func (c * mockBlobClient ) DeleteContainer (ctx context.Context , resourceGroupName , accountName , containerName string ) error {
68
+ switch c .errorType {
69
+ case DATAPLANE :
70
+ return fmt .Errorf (containerBeingDeletedDataplaneAPIError )
71
+ case MANAGEMENT :
72
+ return fmt .Errorf (containerBeingDeletedManagementAPIError )
73
+ case CUSTOM :
74
+ return fmt .Errorf (c .custom )
75
+ }
76
+ return nil
77
+ }
78
+ func (c * mockBlobClient ) GetContainer (ctx context.Context , resourceGroupName , accountName , containerName string ) (storage.BlobContainer , error ) {
79
+ switch c .errorType {
80
+ case DATAPLANE :
81
+ return storage.BlobContainer {}, fmt .Errorf (containerBeingDeletedDataplaneAPIError )
82
+ case MANAGEMENT :
83
+ return storage.BlobContainer {}, fmt .Errorf (containerBeingDeletedManagementAPIError )
84
+ case CUSTOM :
85
+ return storage.BlobContainer {}, fmt .Errorf (c .custom )
86
+ }
87
+ return storage.BlobContainer {}, nil
88
+ }
89
+
39
90
func TestControllerGetCapabilities (t * testing.T ) {
40
91
d := NewFakeDriver ()
41
92
controlCap := []* csi.ControllerServiceCapability {
@@ -783,16 +834,19 @@ func TestControllerExpandVolume(t *testing.T) {
783
834
}
784
835
}
785
836
837
+ //management error returning timed out error instead of nil, but working properly for deleteblobcontainer
786
838
func TestCreateBlobContainer (t * testing.T ) {
787
839
tests := []struct {
788
840
desc string
789
841
rg string
790
842
accountName string
791
843
containerName string
792
844
secrets map [string ]string
845
+ clientErr errType
793
846
expectedErr error
794
847
}{
795
848
{
849
+ clientErr : NULL ,
796
850
expectedErr : fmt .Errorf ("containerName is empty" ),
797
851
},
798
852
{
@@ -801,15 +855,34 @@ func TestCreateBlobContainer(t *testing.T) {
801
855
defaultSecretAccountName : "accountname" ,
802
856
defaultSecretAccountKey : "key" ,
803
857
},
858
+ clientErr : NULL ,
804
859
expectedErr : fmt .Errorf ("azure: base storage service url required" ),
805
860
},
861
+ {
862
+ containerName : "Secrets is Empty" ,
863
+ secrets : map [string ]string {},
864
+ clientErr : NULL ,
865
+ expectedErr : nil ,
866
+ },
867
+ {
868
+ containerName : "Dataplane API Error" ,
869
+ secrets : map [string ]string {},
870
+ clientErr : DATAPLANE ,
871
+ expectedErr : nil ,
872
+ },
873
+ /*{
874
+ containerName: "Management API Error",
875
+ secrets: map[string]string{},
876
+ clientErr: MANAGEMENT,
877
+ expectedErr: nil,
878
+ },*/
806
879
}
807
880
808
881
d := NewFakeDriver ()
809
882
d .cloud = & azure.Cloud {}
810
-
811
883
for _ , test := range tests {
812
884
err := d .CreateBlobContainer (context .Background (), test .rg , test .accountName , test .containerName , test .secrets )
885
+ d .cloud .BlobClient = & mockBlobClient {errorType : test .clientErr }
813
886
if ! reflect .DeepEqual (err , test .expectedErr ) {
814
887
t .Errorf ("test(%s), actualErr: (%v), expectedErr: (%v)" , test .desc , err , test .expectedErr )
815
888
}
@@ -823,9 +896,11 @@ func TestDeleteBlobContainer(t *testing.T) {
823
896
accountName string
824
897
containerName string
825
898
secrets map [string ]string
899
+ clientErr errType
826
900
expectedErr error
827
901
}{
828
902
{
903
+ clientErr : NULL ,
829
904
expectedErr : fmt .Errorf ("containerName is empty" ),
830
905
},
831
906
{
@@ -834,15 +909,35 @@ func TestDeleteBlobContainer(t *testing.T) {
834
909
defaultSecretAccountName : "accountname" ,
835
910
defaultSecretAccountKey : "key" ,
836
911
},
912
+ clientErr : NULL ,
837
913
expectedErr : fmt .Errorf ("azure: base storage service url required" ),
838
914
},
915
+ {
916
+ containerName : "Secrets is Empty" ,
917
+ secrets : map [string ]string {},
918
+ clientErr : NULL ,
919
+ expectedErr : nil ,
920
+ },
921
+ {
922
+ containerName : "Dataplane API Error" ,
923
+ secrets : map [string ]string {},
924
+ clientErr : DATAPLANE ,
925
+ expectedErr : nil ,
926
+ },
927
+ {
928
+ containerName : "Management API Error" ,
929
+ secrets : map [string ]string {},
930
+ clientErr : MANAGEMENT ,
931
+ expectedErr : nil ,
932
+ },
839
933
}
840
934
841
935
d := NewFakeDriver ()
842
936
d .cloud = & azure.Cloud {}
843
937
844
938
for _ , test := range tests {
845
939
err := d .DeleteBlobContainer (context .Background (), test .rg , test .accountName , test .containerName , test .secrets )
940
+ d .cloud .BlobClient = & mockBlobClient {errorType : test .clientErr }
846
941
if ! reflect .DeepEqual (err , test .expectedErr ) {
847
942
t .Errorf ("test(%s), actualErr: (%v), expectedErr: (%v)" , test .desc , err , test .expectedErr )
848
943
}
0 commit comments