@@ -36,8 +36,8 @@ describe('TracingSession', () => {
3636 listener ,
3737 ) ;
3838 const fileIdentifiers = [
39- new AdbFileIdentifier ( 'test path 1' , [ 'matcher' ] , 'saved file 1 ' ) ,
40- new AdbFileIdentifier ( 'test path 2' , [ 'matcher' ] , 'saved file 2 ' ) ,
39+ new AdbFileIdentifier ( 'test path 1' , [ 'matcher' ] , 'saved_file_1 ' ) ,
40+ new AdbFileIdentifier ( 'test path 2' , [ 'matcher' ] , 'saved_file_2 ' ) ,
4141 ] ;
4242 const sessionName = 'TestSession' ;
4343 const stopCmd = 'test stop cmd' ;
@@ -108,19 +108,45 @@ describe('TracingSession', () => {
108108 [ 'test path 2' , [ 'matcher' ] ] ,
109109 ] ) ;
110110 expect ( runShellCmdSpy . calls . allArgs ( ) ) . toEqual ( [
111+ [ 'su root id -u' ] ,
111112 [
112- `su root [ ! -f file ] || su root mv file ${ WINSCOPE_BACKUP_DIR } saved file 1 ` ,
113+ `[ -f file ] && cp file ${ WINSCOPE_BACKUP_DIR } saved_file_1 && rm -f file ` ,
113114 ] ,
114115 [
115- `su root [ ! -f file ] || su root mv file ${ WINSCOPE_BACKUP_DIR } saved file 2` ,
116+ `[ -f file ] && cp file ${ WINSCOPE_BACKUP_DIR } saved_file_2 && rm -f file` ,
117+ ] ,
118+ ] ) ;
119+ } ) ;
120+
121+ it ( 'moves files as root' , async ( ) => {
122+ runShellCmdSpy . and . returnValue ( Promise . resolve ( '' ) ) ;
123+ setDeviceAsRoot ( ) ;
124+ await session . moveFiles ( mockDevice ) ;
125+ expect ( findFilesSpy . calls . allArgs ( ) ) . toEqual ( [
126+ [ 'test path 1' , [ 'matcher' ] ] ,
127+ [ 'test path 2' , [ 'matcher' ] ] ,
128+ ] ) ;
129+ expect ( runShellCmdSpy . calls . allArgs ( ) ) . toEqual ( [
130+ [ 'su root id -u' ] ,
131+ [
132+ `su root [ -f file ] && su root cp file ${ WINSCOPE_BACKUP_DIR } saved_file_1 && su root rm -f file` ,
133+ ] ,
134+ [
135+ `su root [ -f file ] && su root cp file ${ WINSCOPE_BACKUP_DIR } saved_file_2 && su root rm -f file` ,
116136 ] ,
117137 ] ) ;
118138 } ) ;
119139
120140 it ( 'handles error in move command' , async ( ) => {
141+ runShellCmdSpy . and . returnValue ( Promise . resolve ( '' ) ) ;
142+ runShellCmdSpy
143+ . withArgs (
144+ `[ -f file ] && cp file ${ WINSCOPE_BACKUP_DIR } saved_file_1 && rm -f file` ,
145+ )
146+ . and . throwError ( new Error ( ) ) ;
121147 runShellCmdSpy
122148 . withArgs (
123- `su root [ ! -f file ] || su root mv file ${ WINSCOPE_BACKUP_DIR } saved file 1 ` ,
149+ `[ -f file ] && cp file ${ WINSCOPE_BACKUP_DIR } saved_file_2 && rm -f file ` ,
124150 )
125151 . and . throwError ( new Error ( ) ) ;
126152 await expectAsync ( session . moveFiles ( mockDevice ) ) . toBeResolved ( ) ;
@@ -133,4 +159,10 @@ describe('TracingSession', () => {
133159 expect ( endTraceSpy ) . toHaveBeenCalledWith ( ...endArgs ) ;
134160 }
135161 }
162+
163+ function setDeviceAsRoot ( ) {
164+ runShellCmdSpy
165+ . withArgs ( 'su root id -u' )
166+ . and . returnValue ( Promise . resolve ( '0' ) ) ;
167+ }
136168} ) ;
0 commit comments