@@ -86,7 +86,7 @@ var SpecialCharBlobTagsMap = map[string]string{
8686 "GO " : ".Net" ,
8787}
8888
89- func setClientOptions (t * testing.T , opts * azcore.ClientOptions ) {
89+ func SetClientOptions (t * testing.T , opts * azcore.ClientOptions ) {
9090 opts .Logging .AllowedHeaders = append (opts .Logging .AllowedHeaders , "X-Request-Mismatch" , "X-Request-Mismatch-Error" )
9191
9292 transport , err := recording .NewRecordingHTTPClient (t , nil )
@@ -99,9 +99,9 @@ func GetClient(t *testing.T, accountType TestAccountType, options *azblob.Client
9999 options = & azblob.ClientOptions {}
100100 }
101101
102- setClientOptions (t , & options .ClientOptions )
102+ SetClientOptions (t , & options .ClientOptions )
103103
104- cred , err := GetGenericCredential (accountType )
104+ cred , err := GetGenericSharedKeyCredential (accountType )
105105 if err != nil {
106106 return nil , err
107107 }
@@ -116,9 +116,9 @@ func GetServiceClient(t *testing.T, accountType TestAccountType, options *servic
116116 options = & service.ClientOptions {}
117117 }
118118
119- setClientOptions (t , & options .ClientOptions )
119+ SetClientOptions (t , & options .ClientOptions )
120120
121- cred , err := GetGenericCredential (accountType )
121+ cred , err := GetGenericSharedKeyCredential (accountType )
122122 if err != nil {
123123 return nil , err
124124 }
@@ -128,48 +128,62 @@ func GetServiceClient(t *testing.T, accountType TestAccountType, options *servic
128128 return serviceClient , err
129129}
130130
131- func GetAccountInfo (accountType TestAccountType ) (string , string ) {
131+ func GetServiceClientNoCredential (t * testing.T , sasUrl string , options * service.ClientOptions ) (* service.Client , error ) {
132+ if options == nil {
133+ options = & service.ClientOptions {}
134+ }
135+
136+ SetClientOptions (t , & options .ClientOptions )
137+
138+ serviceClient , err := service .NewClientWithNoCredential (sasUrl , options )
139+
140+ return serviceClient , err
141+ }
142+
143+ func GetGenericAccountInfo (accountType TestAccountType ) (string , string ) {
144+ if recording .GetRecordMode () == recording .PlaybackMode {
145+ return FakeStorageAccount , "ZmFrZQ=="
146+ }
132147 accountNameEnvVar := string (accountType ) + AccountNameEnvVar
133148 accountKeyEnvVar := string (accountType ) + AccountKeyEnvVar
134149 accountName , _ := GetRequiredEnv (accountNameEnvVar )
135150 accountKey , _ := GetRequiredEnv (accountKeyEnvVar )
136151 return accountName , accountKey
137152}
138153
139- func GetGenericCredential (accountType TestAccountType ) (* azblob.SharedKeyCredential , error ) {
140- if recording .GetRecordMode () == recording .PlaybackMode {
141- return azblob .NewSharedKeyCredential (FakeStorageAccount , "ZmFrZQ==" )
142- }
143-
144- accountName , accountKey := GetAccountInfo (accountType )
154+ func GetGenericSharedKeyCredential (accountType TestAccountType ) (* azblob.SharedKeyCredential , error ) {
155+ accountName , accountKey := GetGenericAccountInfo (accountType )
145156 if accountName == "" || accountKey == "" {
146157 return nil , errors .New (string (accountType ) + AccountNameEnvVar + " and/or " + string (accountType ) + AccountKeyEnvVar + " environment variables not specified." )
147158 }
148159 return azblob .NewSharedKeyCredential (accountName , accountKey )
149160}
150161
151- func GetConnectionString (accountType TestAccountType ) string {
152- accountName , accountKey := GetAccountInfo (accountType )
162+ func GetGenericConnectionString (accountType TestAccountType ) (* string , error ) {
163+ accountName , accountKey := GetGenericAccountInfo (accountType )
164+ if accountName == "" || accountKey == "" {
165+ return nil , errors .New (string (accountType ) + AccountNameEnvVar + " and/or " + string (accountType ) + AccountKeyEnvVar + " environment variables not specified." )
166+ }
153167 connectionString := fmt .Sprintf ("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;EndpointSuffix=core.windows.net/" ,
154168 accountName , accountKey )
155- return connectionString
169+ return & connectionString , nil
156170}
157171
158172func GetServiceClientFromConnectionString (t * testing.T , accountType TestAccountType , options * service.ClientOptions ) (* service.Client , error ) {
159173 if options == nil {
160174 options = & service.ClientOptions {}
161175 }
176+ SetClientOptions (t , & options .ClientOptions )
162177
163178 transport , err := recording .NewRecordingHTTPClient (t , nil )
164179 require .NoError (t , err )
165180 options .Transport = transport
166181
167- if recording .GetRecordMode () == recording .PlaybackMode {
168- return service .NewClientWithNoCredential (FakeStorageURL , options )
182+ cred , err := GetGenericConnectionString (accountType )
183+ if err != nil {
184+ return nil , err
169185 }
170-
171- connectionString := GetConnectionString (accountType )
172- svcClient , err := service .NewClientFromConnectionString (connectionString , options )
186+ svcClient , err := service .NewClientFromConnectionString (* cred , options )
173187 return svcClient , err
174188}
175189
0 commit comments