Skip to content

Commit 6758bf1

Browse files
committed
chore(crc64-nvme-crt): add tests
1 parent 5f4f0a6 commit 6758bf1

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

packages/crc64-nvme-crt/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"tslib": "^2.6.2"
2828
},
2929
"devDependencies": {
30+
"@smithy/util-base64": "^3.0.0",
3031
"@tsconfig/recommended": "1.0.1",
3132
"concurrently": "7.0.0",
3233
"downlevel-dts": "0.10.1",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { toBase64 } from "@smithy/util-base64";
2+
import { describe, expect, it } from "vitest";
3+
4+
import { CrtCrc64Nvme } from "./CrtCrc64Nvme";
5+
6+
describe(CrtCrc64Nvme.name, () => {
7+
it("should throw an error if digest is called before update", async () => {
8+
const crc64 = new CrtCrc64Nvme();
9+
await expect(crc64.digest()).rejects.toThrowError("No data provided to checksum");
10+
});
11+
12+
it.each([
13+
["", "AAAAAAAAAAA="],
14+
["abc", "BeXKuz/B+us="],
15+
["Hello world", "OOJZ0D8xKts="],
16+
])(`crc64-nvme for "%s" is "%s"`, async (input, output) => {
17+
const crc64 = new CrtCrc64Nvme();
18+
crc64.update(new TextEncoder().encode(input));
19+
const digest = await crc64.digest();
20+
expect(toBase64(digest)).toEqual(output);
21+
});
22+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
include: ["**/*.spec.ts"],
6+
environment: "node",
7+
},
8+
});

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23252,6 +23252,7 @@ __metadata:
2325223252
dependencies:
2325323253
"@aws-sdk/crt-loader": "npm:*"
2325423254
"@aws-sdk/types": "npm:*"
23255+
"@smithy/util-base64": "npm:^3.0.0"
2325523256
"@smithy/util-utf8": "npm:^3.0.0"
2325623257
"@tsconfig/recommended": "npm:1.0.1"
2325723258
concurrently: "npm:7.0.0"

0 commit comments

Comments
 (0)