import { v4 } from 'uuid' ; import { homedir } from 'os' ; import { basename , dirname , join } from 'path' ; import { Common , CLI , ReplExpect } from '@kui-shell/test' ; import S3Utils , { PROVIDER , README } from './util' ; export default function cd ( this ) { const initialPWD = process . cwd ( ) ; const { cd , copyToS3 , lsCurrentDir , lsExpecting404 , mkdir , rimraf } = S3Utils . bind ( this ) ( ) ; const bucketName = `kuitest-${ v4 ( ) }` ; mkdir ( bucketName ) ; copyToS3 ( bucketName , README ) ; cd ( '/s3' ) ; cd ( PROVIDER ) ; lsCurrentDir ( bucketName ) ; cd ( bucketName ) ; lsCurrentDir ( README ) ; cd ( '..' , `/s3/${ PROVIDER }` ) ; lsCurrentDir ( bucketName ) ; cd ( '..' , join ( '/s3' , dirname ( PROVIDER ) ) ) ; lsCurrentDir ( basename ( PROVIDER ) ) ; cd ( '' , homedir ( ) ) ; cd ( '/' ) ; cd ( 's3' ) ; lsCurrentDir ( PROVIDER . slice ( 0 , PROVIDER . indexOf ( '/' ) ) ) ; rimraf ( bucketName ) ; lsExpecting404 ( bucketName ) ; it ( 'should cd back to the initial working directory' , ( ) => CLI . command ( `cd "${ initialPWD }"` , this . app ) . then ( ReplExpect . okWithString ( initialPWD ) ) . catch ( Common . oops ( this , true ) ) ) ; }