test(uuid): add tests for invalid namespace UUID (#4875)

This commit is contained in:
Asher Gomez 2024-05-29 18:19:55 +10:00 committed by GitHub
parent a0b0f4c553
commit fc3d376447
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View File

@ -1,5 +1,10 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals } from "@std/assert";
import {
assert,
assertEquals,
AssertionError,
assertRejects,
} from "@std/assert";
import { generate, validate } from "./v3.ts";
const NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341";
@ -37,3 +42,11 @@ Deno.test("validate() checks if a string is a valid v3 UUID", async () => {
assert(validate(t), `${t} should be valid`);
assert(!validate(n), `${n} should not be valid`);
});
Deno.test("generate() throws on invalid namespace", async () => {
await assertRejects(
async () => await generate("invalid-uuid", new Uint8Array()),
AssertionError,
"namespace must be a valid UUID",
);
});

View File

@ -1,5 +1,10 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals } from "@std/assert";
import {
assert,
assertEquals,
AssertionError,
assertRejects,
} from "@std/assert";
import { generate, validate } from "./v5.ts";
const NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341";
@ -37,3 +42,11 @@ Deno.test("validate() checks if a string is a valid v5 UUID", async () => {
assert(validate(t), `${t} should be valid`);
assert(!validate(n), `${n} should not be valid`);
});
Deno.test("generate() throws on invalid namespace", async () => {
await assertRejects(
async () => await generate("invalid-uuid", new Uint8Array()),
AssertionError,
"namespace must be a valid UUID",
);
});