@@ -34,7 +34,8 @@ describe('moveAndMaybeCompressFile', () => {
34
34
const source = path . join ( TEST_DIR , 'test.log' ) ;
35
35
const destination = path . join ( TEST_DIR , 'moved-test.log.gz' ) ;
36
36
await fs . outputFile ( source , 'This is the test file.' ) ;
37
- await moveAndMaybeCompressFile ( source , destination , true ) ;
37
+ const moveAndCompressOptions = { compress : true }
38
+ await moveAndMaybeCompressFile ( source , destination , moveAndCompressOptions ) ;
38
39
39
40
const zippedContents = await fs . readFile ( destination ) ;
40
41
const contents = await new Promise ( resolve => {
@@ -101,7 +102,8 @@ describe('moveAndMaybeCompressFile', () => {
101
102
const source = path . join ( TEST_DIR , 'test.log' ) ;
102
103
const destination = path . join ( TEST_DIR , 'moved-test.log.gz' ) ;
103
104
await fs . outputFile ( source , 'This is the test file.' ) ;
104
- await moveWithMock ( source , destination , true ) ;
105
+ const options = { compress : true } ;
106
+ await moveWithMock ( source , destination , options ) ;
105
107
106
108
const zippedContents = await fs . readFile ( destination ) ;
107
109
const contents = await new Promise ( resolve => {
@@ -115,4 +117,50 @@ describe('moveAndMaybeCompressFile', () => {
115
117
( await fs . readFile ( source , 'utf8' ) ) . should . be . empty ( )
116
118
117
119
} ) ;
120
+
121
+ it ( 'should compress the source file at the new destination with 0o775 rights' , async ( ) => {
122
+ const source = path . join ( TEST_DIR , 'test.log' ) ;
123
+ const destination = path . join ( TEST_DIR , 'moved-test.log.gz' ) ;
124
+ await fs . outputFile ( source , 'This is the test file.' ) ;
125
+ const moveAndCompressOptions = { compress : true , mode :0o775 }
126
+ await moveAndMaybeCompressFile ( source , destination , moveAndCompressOptions ) ;
127
+
128
+ const destinationStats = await fs . stat ( destination ) ;
129
+ const destMode = ( destinationStats . mode & 0o775 ) . toString ( 8 ) ;
130
+ destMode . should . equal ( '775' ) ;
131
+
132
+ const zippedContents = await fs . readFile ( destination ) ;
133
+ const contents = await new Promise ( resolve => {
134
+ zlib . gunzip ( zippedContents , ( e , data ) => {
135
+ resolve ( data . toString ( ) ) ;
136
+ } ) ;
137
+ } ) ;
138
+ contents . should . equal ( 'This is the test file.' ) ;
139
+
140
+ const exists = await fs . pathExists ( source ) ;
141
+ exists . should . be . false ( ) ;
142
+ } ) ;
143
+
144
+ it ( 'should compress the source file at the new destination with 0o400 rights' , async ( ) => {
145
+ const source = path . join ( TEST_DIR , 'test.log' ) ;
146
+ const destination = path . join ( TEST_DIR , 'moved-test.log.gz' ) ;
147
+ await fs . outputFile ( source , 'This is the test file.' ) ;
148
+ const moveAndCompressOptions = { compress : true , mode :0o400 }
149
+ await moveAndMaybeCompressFile ( source , destination , moveAndCompressOptions ) ;
150
+
151
+ const destinationStats = await fs . stat ( destination ) ;
152
+ const destMode = ( destinationStats . mode & 0o400 ) . toString ( 8 ) ;
153
+ destMode . should . equal ( '400' ) ;
154
+
155
+ const zippedContents = await fs . readFile ( destination ) ;
156
+ const contents = await new Promise ( resolve => {
157
+ zlib . gunzip ( zippedContents , ( e , data ) => {
158
+ resolve ( data . toString ( ) ) ;
159
+ } ) ;
160
+ } ) ;
161
+ contents . should . equal ( 'This is the test file.' ) ;
162
+
163
+ const exists = await fs . pathExists ( source ) ;
164
+ exists . should . be . false ( ) ;
165
+ } ) ;
118
166
} ) ;
0 commit comments