used shared random gen for tests

This commit is contained in:
Michael C
2023-02-21 03:24:07 -05:00
parent 31a460e750
commit 37a1c7e88d
4 changed files with 6 additions and 8 deletions

View File

@@ -1,10 +1,9 @@
import assert from "assert"; import assert from "assert";
import { client } from "../utils/httpClient"; import { client } from "../utils/httpClient";
import redis from "../../src/utils/redis"; import redis from "../../src/utils/redis";
import crypto from "crypto";
import { config } from "../../src/config"; import { config } from "../../src/config";
import { genRandom } from "../utils/getRandom";
const genRandom = (bytes=8) => crypto.pseudoRandomBytes(bytes).toString("hex");
const validateEtag = (expected: string, actual: string): boolean => { const validateEtag = (expected: string, actual: string): boolean => {
const [actualHashType, actualHashKey, actualService] = actual.split(";"); const [actualHashType, actualHashKey, actualService] = actual.split(";");
const [expectedHashType, expectedHashKey, expectedService] = expected.split(";"); const [expectedHashType, expectedHashKey, expectedService] = expected.split(";");

View File

@@ -3,11 +3,9 @@ import { getHashCache } from "../../src/utils/getHashCache";
import { shaHashKey } from "../../src/utils/redisKeys"; import { shaHashKey } from "../../src/utils/redisKeys";
import { getHash } from "../../src/utils/getHash"; import { getHash } from "../../src/utils/getHash";
import redis from "../../src/utils/redis"; import redis from "../../src/utils/redis";
import crypto from "crypto";
import assert from "assert"; import assert from "assert";
import { setTimeout } from "timers/promises"; import { setTimeout } from "timers/promises";
import { genRandom } from "../utils/getRandom";
const genRandom = (bytes=8) => crypto.pseudoRandomBytes(bytes).toString("hex");
const rand1Hash = genRandom(24); const rand1Hash = genRandom(24);
const rand1Hash_Key = getHash(rand1Hash, 1); const rand1Hash_Key = getHash(rand1Hash, 1);

View File

@@ -1,9 +1,7 @@
import { config } from "../../src/config"; import { config } from "../../src/config";
import redis from "../../src/utils/redis"; import redis from "../../src/utils/redis";
import crypto from "crypto";
import assert from "assert"; import assert from "assert";
import { genRandom } from "../utils/getRandom";
const genRandom = (bytes=8) => crypto.pseudoRandomBytes(bytes).toString("hex");
const randKey1 = genRandom(); const randKey1 = genRandom();
const randValue1 = genRandom(); const randValue1 = genRandom();

3
test/utils/getRandom.ts Normal file
View File

@@ -0,0 +1,3 @@
import crypto from "crypto";
export const genRandom = (bytes=8) => crypto.pseudoRandomBytes(bytes).toString("hex");