Skip to content

Commit

Permalink
chore(crc64-nvme-crt): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Dec 16, 2024
1 parent 5f4f0a6 commit 6758bf1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/crc64-nvme-crt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"@smithy/util-base64": "^3.0.0",
"@tsconfig/recommended": "1.0.1",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
Expand Down
22 changes: 22 additions & 0 deletions packages/crc64-nvme-crt/src/CrtCrc64Nvme.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { toBase64 } from "@smithy/util-base64";
import { describe, expect, it } from "vitest";

import { CrtCrc64Nvme } from "./CrtCrc64Nvme";

describe(CrtCrc64Nvme.name, () => {
it("should throw an error if digest is called before update", async () => {
const crc64 = new CrtCrc64Nvme();
await expect(crc64.digest()).rejects.toThrowError("No data provided to checksum");
});

it.each([
["", "AAAAAAAAAAA="],
["abc", "BeXKuz/B+us="],
["Hello world", "OOJZ0D8xKts="],
])(`crc64-nvme for "%s" is "%s"`, async (input, output) => {
const crc64 = new CrtCrc64Nvme();
crc64.update(new TextEncoder().encode(input));
const digest = await crc64.digest();
expect(toBase64(digest)).toEqual(output);
});
});
8 changes: 8 additions & 0 deletions packages/crc64-nvme-crt/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: ["**/*.spec.ts"],
environment: "node",
},
});
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23252,6 +23252,7 @@ __metadata:
dependencies:
"@aws-sdk/crt-loader": "npm:*"
"@aws-sdk/types": "npm:*"
"@smithy/util-base64": "npm:^3.0.0"
"@smithy/util-utf8": "npm:^3.0.0"
"@tsconfig/recommended": "npm:1.0.1"
concurrently: "npm:7.0.0"
Expand Down

0 comments on commit 6758bf1

Please sign in to comment.