@@ -68,8 +68,9 @@ impl BlobClient {
68
68
where
69
69
I : IntoIterator < Item = & ' a str > ,
70
70
{
71
+ let blob_name_with_segments = self . blob_name . split ( '/' ) . into_iter ( ) . chain ( segments) ;
71
72
self . container_client
72
- . url_with_segments ( Some ( self . blob_name . as_str ( ) ) . into_iter ( ) . chain ( segments ) )
73
+ . url_with_segments ( blob_name_with_segments )
73
74
}
74
75
75
76
pub fn get ( & self ) -> GetBlobBuilder {
@@ -209,6 +210,49 @@ impl BlobClient {
209
210
}
210
211
}
211
212
213
+ #[ cfg( test) ]
214
+ mod tests {
215
+ use super :: * ;
216
+ use crate :: blob:: clients:: AsBlobClient ;
217
+
218
+ struct FakeSas {
219
+ token : String ,
220
+ }
221
+ impl SasToken for FakeSas {
222
+ fn token ( & self ) -> String {
223
+ self . token . clone ( )
224
+ }
225
+ }
226
+
227
+ fn build_url ( container_name : & str , blob_name : & str , sas : & FakeSas ) -> url:: Url {
228
+ let storage_account = StorageAccountClient :: new_emulator_default ( ) . as_storage_client ( ) ;
229
+ storage_account
230
+ . as_container_client ( container_name)
231
+ . as_blob_client ( blob_name)
232
+ . generate_signed_blob_url ( sas)
233
+ . expect ( "build url failed" )
234
+ }
235
+
236
+ #[ test]
237
+ fn test_generate_url ( ) {
238
+ let sas = FakeSas {
239
+ token : "fake_token" . to_owned ( ) ,
240
+ } ;
241
+
242
+ let url = build_url ( "a" , "b" , & sas) ;
243
+ assert_eq ! (
244
+ url. as_str( ) ,
245
+ "http://127.0.0.1:10000/devstoreaccount1/a/b?fake_token"
246
+ ) ;
247
+
248
+ let url = build_url ( "a" , "b/c/d" , & sas) ;
249
+ assert_eq ! (
250
+ url. as_str( ) ,
251
+ "http://127.0.0.1:10000/devstoreaccount1/a/b/c/d?fake_token"
252
+ ) ;
253
+ }
254
+ }
255
+
212
256
#[ cfg( test) ]
213
257
#[ cfg( feature = "test_integration" ) ]
214
258
mod integration_tests {
0 commit comments