14
14
* limitations under the License.
15
15
*
16
16
*/
17
- import { afterAll , beforeAll , describe , expect , it } from '@jest/globals'
18
17
import fs from 'fs'
19
18
import net from 'net'
20
19
import os from 'os'
@@ -38,6 +37,7 @@ import {
38
37
V1ServiceSpec ,
39
38
V1VolumeResourceRequirements
40
39
} from '@kubernetes/client-node'
40
+ import crypto from 'crypto'
41
41
42
42
const defaultTimeout = 120000
43
43
@@ -179,14 +179,21 @@ describe('K8', () => {
179
179
const localTmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'k8-test' ) )
180
180
const remoteTmpDir = '/tmp'
181
181
const localFilePath = 'test/data/pem/keys/a-private-node0.pem'
182
+ const fileName = path . basename ( localFilePath )
182
183
const remoteFilePath = `${ remoteTmpDir } /a-private-node0.pem`
184
+ const originalFileHash = crypto . createHash ( 'sha384' ) . update ( localFilePath ) . digest ( ) . toString ( )
185
+ const originalStat = fs . statSync ( localFilePath )
183
186
184
187
// upload the file
185
188
await expect ( k8 . copyTo ( podName , containerName , localFilePath , remoteTmpDir ) ) . resolves . toBeTruthy ( )
186
189
187
190
// download the same file
188
191
await expect ( k8 . copyFrom ( podName , containerName , remoteFilePath , localTmpDir ) ) . resolves . toBeTruthy ( )
192
+ const downloadedFilePath = path . join ( localTmpDir , fileName )
193
+ const downloadedFileHash = crypto . createHash ( 'sha384' ) . update ( downloadedFilePath ) . digest ( ) . toString ( )
194
+ const downloadedStat = fs . statSync ( downloadedFilePath )
189
195
196
+ expect ( downloadedFileHash , 'downloaded file hash should match original file hash' ) . toEqual ( originalFileHash )
190
197
// rm file inside the container
191
198
await expect ( k8 . execContainer ( podName , containerName , [ 'rm' , '-f' , remoteFilePath ] ) ) . resolves
192
199
0 commit comments