@@ -380,6 +380,49 @@ mocha.describe('bucket operations - namespace_fs', function() {
380380 console . log ( inspect ( res ) ) ;
381381 await fs_utils . file_must_exist ( path . join ( s3_new_buckets_path , bucket_name + '-s3' ) ) ;
382382 } ) ;
383+ mocha . it ( 'create s3 bucket with x-nsfs-bucket-path' , async function ( ) {
384+ const new_buckets_path = get_new_buckets_path_by_test_env ( tmp_fs_root , s3_new_buckets_dir ) ;
385+ const x_nsfs_bucket_path = `${ new_buckets_path } ${ bucket_name } -custom-path` ;
386+ s3_correct_uid_default_nsr . middlewareStack . add (
387+ ( next , context ) => args => {
388+ args . request . headers [ "x-nsfs-bucket-path" ] = x_nsfs_bucket_path ;
389+ return next ( args ) ;
390+ } ,
391+ {
392+ step : "finalizeRequest" ,
393+ name : "addCustomHeader" ,
394+ }
395+ ) ;
396+ const res = await s3_correct_uid_default_nsr . createBucket ( { Bucket : bucket_name + '-s3-custom' , } ) ;
397+ console . log ( inspect ( res ) ) ;
398+ await fs_utils . file_must_exist ( x_nsfs_bucket_path ) ;
399+ s3_correct_uid_default_nsr . middlewareStack . remove ( "addCustomHeader" ) ;
400+ } ) ;
401+
402+ mocha . it ( 'create s3 bucket with x-mcg-bucket-path fail as directory exist' , async function ( ) {
403+ const new_buckets_path = get_new_buckets_path_by_test_env ( tmp_fs_root , s3_new_buckets_dir ) ;
404+ const x_nsfs_bucket_path = `${ new_buckets_path } ${ bucket_name } -custom-path` ; // already created in previous test
405+ // this is the path that was created if x_nsfs_bucket_path header wasn't used
406+ const no_x_nsfs_bucket_path = `${ new_buckets_path } ${ bucket_name } -s3-custom-fail` ;
407+ s3_correct_uid_default_nsr . middlewareStack . add (
408+ ( next , context ) => args => {
409+ args . request . headers [ "x-nsfs-bucket-path" ] = x_nsfs_bucket_path ;
410+ return next ( args ) ;
411+ } ,
412+ {
413+ step : "finalizeRequest" ,
414+ name : "addCustomHeader" ,
415+ }
416+ ) ;
417+ try {
418+ const res = await s3_correct_uid_default_nsr . createBucket ( { Bucket : bucket_name + '-s3-custom-fail' , } ) ;
419+ assert . fail ( inspect ( res ) ) ;
420+ } catch ( err ) {
421+ assert . strictEqual ( err . Code , 'BucketAlreadyExists' ) ;
422+ }
423+ await fs_utils . file_must_not_exist ( no_x_nsfs_bucket_path ) ;
424+ s3_correct_uid_default_nsr . middlewareStack . remove ( "addCustomHeader" ) ;
425+ } ) ;
383426
384427 mocha . it ( 'get bucket acl - rpc bucket' , async function ( ) {
385428 const res = await s3_correct_uid_default_nsr . getBucketAcl ( { Bucket : first_bucket } ) ;
0 commit comments