Skip to content

Commit

Permalink
fix(node/crypto): test randomFill
Browse files Browse the repository at this point in the history
  • Loading branch information
levex committed Apr 11, 2023
1 parent a1f9065 commit a92ccab
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cli/tests/unit_node/internal/_randomFill_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { Buffer } from "node:buffer";
import { AsyncLocalStorage } from "node:async_hooks";
import { randomFill, randomFillSync } from "node:crypto";
import {
assertEquals,
assertNotEquals,
assertThrows,
} from "../../../../test_util/std/testing/asserts.ts";
import { deferred } from "../../../../test_util/std/async/deferred.ts";

const validateNonZero = (buf: Buffer) => {
if (!buf.some((ch) => ch > 0)) throw new Error("Error");
Expand All @@ -15,14 +17,18 @@ const validateZero = (buf: Buffer) => {
buf.forEach((val) => assertEquals(val, 0));
};

Deno.test("[node/crypto.randomFill]", () => {
Deno.test("[node/crypto.randomFill]", async () => {
const promise = deferred();
const buf = Buffer.alloc(10);
const before = buf.toString("hex");

randomFill(buf, 5, 5, (_err, bufTwo) => {
const after = bufTwo?.toString("hex");
assertEquals(before.slice(0, 10), after?.slice(0, 10));
promise.resolve(true);
});

await promise;
});

Deno.test("[node/crypto.randomFillSync]", () => {
Expand Down

0 comments on commit a92ccab

Please sign in to comment.