Skip to content

Commit 6f6e4a7

Browse files
committed
Fill in chunks
1 parent 78c8302 commit 6f6e4a7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/test/cache-github-live.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {pseudoRandomBytes} from 'node:crypto';
7+
import {randomFillSync} from 'node:crypto';
88
import {test} from 'uvu';
99
import * as assert from 'uvu/assert';
1010
import {GitHubActionsCache} from '../caching/github-actions-cache.js';
@@ -45,7 +45,13 @@ test(
4545
assert.is(get1, undefined);
4646

4747
const filename = 'test';
48-
const content = pseudoRandomBytes(200 * 1024 * 1024);
48+
49+
const content = Buffer.alloc(200 * 1024 * 1024);
50+
const chunkSize = 10 * 1024 * 1024;
51+
for (let i = 0; i < content.length; i += chunkSize) {
52+
randomFillSync(content, i, Math.min(chunkSize, content.length - i));
53+
}
54+
4955
await rig.write(filename, content);
5056
const set1 = await cache.set(script, fingerprint, [
5157
{
@@ -74,7 +80,6 @@ test(
7480
await get2.apply();
7581
assert.ok(await rig.exists('test'));
7682
const actual = await rig.readBytes('test');
77-
console.log({actual});
7883
assert.equal(actual, content);
7984

8085
// TODO(aomarks) Test >100MB file because that will require some different

src/test/util/filesystem-test-rig.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ export class FilesystemTestRig {
7979
if (typeof fileOrFiles === 'string') {
8080
const absolute = pathlib.resolve(this.temp, fileOrFiles);
8181
await fs.mkdir(pathlib.dirname(absolute), {recursive: true});
82-
const str =
83-
typeof data === 'string' ? data : JSON.stringify(data, null, 2);
84-
await fs.writeFile(absolute, str, 'utf8');
82+
if (typeof data === 'string') {
83+
await fs.writeFile(absolute, data, 'utf8');
84+
} else if (Buffer.isBuffer(data)) {
85+
await fs.writeFile(absolute, data);
86+
} else {
87+
await fs.writeFile(absolute, JSON.stringify(data, null, 2), 'utf8');
88+
}
8589
} else {
8690
await Promise.all(
8791
Object.entries(fileOrFiles).map(async ([relative, data]) =>

0 commit comments

Comments
 (0)