Skip to content

Commit 93b6a6f

Browse files
committed
enhance k8 copyto copyfrom test
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 74bcc12 commit 93b6a6f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/e2e/core/k8_e2e.test.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'
1817
import fs from 'fs'
1918
import net from 'net'
2019
import os from 'os'
@@ -38,6 +37,7 @@ import {
3837
V1ServiceSpec,
3938
V1VolumeResourceRequirements
4039
} from '@kubernetes/client-node'
40+
import crypto from 'crypto'
4141

4242
const defaultTimeout = 120000
4343

@@ -179,14 +179,21 @@ describe('K8', () => {
179179
const localTmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'k8-test'))
180180
const remoteTmpDir = '/tmp'
181181
const localFilePath = 'test/data/pem/keys/a-private-node0.pem'
182+
const fileName = path.basename(localFilePath)
182183
const remoteFilePath = `${remoteTmpDir}/a-private-node0.pem`
184+
const originalFileHash = crypto.createHash('sha384').update(localFilePath).digest().toString()
185+
const originalStat = fs.statSync(localFilePath)
183186

184187
// upload the file
185188
await expect(k8.copyTo(podName, containerName, localFilePath, remoteTmpDir)).resolves.toBeTruthy()
186189

187190
// download the same file
188191
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)
189195

196+
expect(downloadedFileHash, 'downloaded file hash should match original file hash').toEqual(originalFileHash)
190197
// rm file inside the container
191198
await expect(k8.execContainer(podName, containerName, ['rm', '-f', remoteFilePath])).resolves
192199

0 commit comments

Comments
 (0)