Skip to content

Commit

Permalink
added a test and updated the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
syhol committed Mar 6, 2024
1 parent 31d1239 commit 3651a3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion uuid/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function generate(
}

if (node.length < 6) {
throw new Error("Uuid node needs to have at least 6 numbers");
throw new Error("Can't create a uuid with a node of less than 6 numbers");
}

_lastMSecs = msecs;
Expand Down
18 changes: 18 additions & 0 deletions uuid/v1_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ Deno.test("generate() can fill the UUID into a buffer", () => {
assertEquals(buf, uuid);
});

Deno.test("generate() throws when node is passed with less than 6 numbers", () => {
const buf: number[] = [];
const v1options = {
node: [0x01, 0x23, 0x45, 0x67, 0x89],
clockseq: 0x1234,
msecs: new Date("2011-11-01").getTime(),
nsecs: 5678,
};

assertThrows(
() => {
generate(v1options, buf, 0);
},
Error,
"Can't create a uuid with a node of less than 6 numbers",
);
});

Deno.test("generate() throws when create more than 10M uuids/sec", () => {
assertThrows(
() => {
Expand Down

0 comments on commit 3651a3c

Please sign in to comment.