Skip to content

Commit

Permalink
test: use @kakang/unit instead of node:assert
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Apr 14, 2024
1 parent 6ce6f53 commit f189159
Show file tree
Hide file tree
Showing 30 changed files with 925 additions and 959 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci-crypto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build @kakang/unit
run: pnpm --filter "./packages/unit" run build

- name: Run tests
run: pnpm --filter "./packages/crypto" run test
3 changes: 3 additions & 0 deletions .github/workflows/ci-eventemitter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build @kakang/unit
run: pnpm --filter "./packages/unit" run build

- name: Run tests
run: pnpm --filter "./packages/eventemitter" run test
3 changes: 3 additions & 0 deletions .github/workflows/ci-utils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build @kakang/unit
run: pnpm --filter "./packages/unit" run build

- name: Run tests
run: pnpm --filter "./packages/utils" run test
3 changes: 3 additions & 0 deletions .github/workflows/ci-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build @kakang/unit
run: pnpm --filter "./packages/unit" run build

- name: Run tests
run: pnpm --filter "./packages/validator" run test
3 changes: 3 additions & 0 deletions .github/workflows/ci-worker-pool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build @kakang/unit
run: pnpm --filter "./packages/unit" run build

- name: Run tests
run: pnpm --filter "./packages/worker-pool" run test
123 changes: 61 additions & 62 deletions packages/crypto/test/aes.test.ts
Original file line number Diff line number Diff line change
@@ -1,109 +1,108 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { test } from '@kakang/unit'
import * as AES from '../lib/aes'

test('computeKeySize()', async function (t) {
await t.test('default', function (t) {
assert.equal(AES.computeKeySize(), 32)
t.test('default', function (t) {
t.equal(AES.computeKeySize(), 32)
})

await t.test('aes-256-ccm', function (t) {
assert.equal(AES.computeKeySize('aes-256-ccm'), 32)
t.test('aes-256-ccm', function (t) {
t.equal(AES.computeKeySize('aes-256-ccm'), 32)
})

await t.test('aes-256-gcm', function (t) {
assert.equal(AES.computeKeySize('aes-256-gcm'), 32)
t.test('aes-256-gcm', function (t) {
t.equal(AES.computeKeySize('aes-256-gcm'), 32)
})

await t.test('chacha20-poly1305', function (t) {
assert.equal(AES.computeKeySize('chacha20-poly1305'), 32)
t.test('chacha20-poly1305', function (t) {
t.equal(AES.computeKeySize('chacha20-poly1305'), 32)
})

await t.test('aes-192-ccm', function (t) {
assert.equal(AES.computeKeySize('aes-192-ccm'), 24)
t.test('aes-192-ccm', function (t) {
t.equal(AES.computeKeySize('aes-192-ccm'), 24)
})

await t.test('aes-192-gcm', function (t) {
assert.equal(AES.computeKeySize('aes-192-gcm'), 24)
t.test('aes-192-gcm', function (t) {
t.equal(AES.computeKeySize('aes-192-gcm'), 24)
})

await t.test('aes-128-ccm', function (t) {
assert.equal(AES.computeKeySize('aes-128-ccm'), 16)
t.test('aes-128-ccm', function (t) {
t.equal(AES.computeKeySize('aes-128-ccm'), 16)
})

await t.test('aes-128-gcm', function (t) {
assert.equal(AES.computeKeySize('aes-128-gcm'), 16)
t.test('aes-128-gcm', function (t) {
t.equal(AES.computeKeySize('aes-128-gcm'), 16)
})
})

test('computeIVSize()', async function (t) {
await t.test('default', function (t) {
assert.equal(AES.computeIVSize(), 16)
t.test('default', function (t) {
t.equal(AES.computeIVSize(), 16)
})

await t.test('aes-256-ccm', function (t) {
assert.equal(AES.computeIVSize('aes-256-ccm'), 16)
t.test('aes-256-ccm', function (t) {
t.equal(AES.computeIVSize('aes-256-ccm'), 16)
})

await t.test('aes-256-gcm', function (t) {
assert.equal(AES.computeIVSize('aes-256-gcm'), 16)
t.test('aes-256-gcm', function (t) {
t.equal(AES.computeIVSize('aes-256-gcm'), 16)
})

await t.test('chacha20-poly1305', function (t) {
assert.equal(AES.computeIVSize('chacha20-poly1305'), 12)
t.test('chacha20-poly1305', function (t) {
t.equal(AES.computeIVSize('chacha20-poly1305'), 12)
})

await t.test('aes-192-ccm', function (t) {
assert.equal(AES.computeIVSize('aes-192-ccm'), 16)
t.test('aes-192-ccm', function (t) {
t.equal(AES.computeIVSize('aes-192-ccm'), 16)
})

await t.test('aes-192-gcm', function (t) {
assert.equal(AES.computeIVSize('aes-192-gcm'), 16)
t.test('aes-192-gcm', function (t) {
t.equal(AES.computeIVSize('aes-192-gcm'), 16)
})

await t.test('aes-128-ccm', function (t) {
assert.equal(AES.computeIVSize('aes-128-ccm'), 16)
t.test('aes-128-ccm', function (t) {
t.equal(AES.computeIVSize('aes-128-ccm'), 16)
})

await t.test('aes-128-gcm', function (t) {
assert.equal(AES.computeIVSize('aes-128-gcm'), 16)
t.test('aes-128-gcm', function (t) {
t.equal(AES.computeIVSize('aes-128-gcm'), 16)
})
})

test('encrypt()', async function (t) {
const SECRET = 'bar'
const SALT = 'baz'

await t.test('encrypt(foo)', function (t) {
t.test('encrypt(foo)', function (t) {
const encrypted = AES.encrypt('foo')
assert.equal('value' in encrypted, true)
assert.equal('iv' in encrypted, true)
assert.equal('authTag' in encrypted, true)
assert.equal('secret' in encrypted, true)
assert.equal('salt' in encrypted, true)
t.equal('value' in encrypted, true)
t.equal('iv' in encrypted, true)
t.equal('authTag' in encrypted, true)
t.equal('secret' in encrypted, true)
t.equal('salt' in encrypted, true)
})

await t.test('encrypt(foo, aes-256-gcm, bar, baz)', function (t) {
t.test('encrypt(foo, aes-256-gcm, bar, baz)', function (t) {
const encrypted = AES.encrypt('foo', 'aes-256-gcm', SECRET, SALT)
assert.equal('value' in encrypted, true)
assert.equal('iv' in encrypted, true)
assert.equal('authTag' in encrypted, true)
assert.equal('secret' in encrypted, true)
assert.equal('salt' in encrypted, true)
t.equal('value' in encrypted, true)
t.equal('iv' in encrypted, true)
t.equal('authTag' in encrypted, true)
t.equal('secret' in encrypted, true)
t.equal('salt' in encrypted, true)
})

await t.test('encrypt(foo, chacha20-poly1305, bar, baz)', function (t) {
t.test('encrypt(foo, chacha20-poly1305, bar, baz)', function (t) {
const encrypted = AES.encrypt('foo', 'chacha20-poly1305', SECRET, SALT)
assert.equal('value' in encrypted, true)
assert.equal('iv' in encrypted, true)
assert.equal('authTag' in encrypted, true)
assert.equal('secret' in encrypted, true)
assert.equal('salt' in encrypted, true)
t.equal('value' in encrypted, true)
t.equal('iv' in encrypted, true)
t.equal('authTag' in encrypted, true)
t.equal('secret' in encrypted, true)
t.equal('salt' in encrypted, true)
})
})

test('decrypt()', async function (t) {
await t.test('decrypt(foo)', function (t) {
t.test('decrypt(foo)', function (t) {
const encrypted = AES.encrypt('foo')
const decrypted = AES.decrypt(
encrypted.value,
Expand All @@ -113,10 +112,10 @@ test('decrypt()', async function (t) {
encrypted.secret,
encrypted.salt
)
assert.equal(decrypted, 'foo')
t.equal(decrypted, 'foo')
})

await t.test('decrypt(foo, aes-128-gcm)', function (t) {
t.test('decrypt(foo, aes-128-gcm)', function (t) {
const encrypted = AES.encrypt('foo', 'aes-128-gcm')
const decrypted = AES.decrypt(
encrypted.value,
Expand All @@ -126,10 +125,10 @@ test('decrypt()', async function (t) {
encrypted.secret,
encrypted.salt
)
assert.equal(decrypted, 'foo')
t.equal(decrypted, 'foo')
})

await t.test('decrypt(foo, aes-192-gcm)', function (t) {
t.test('decrypt(foo, aes-192-gcm)', function (t) {
const encrypted = AES.encrypt('foo', 'aes-192-gcm')
const decrypted = AES.decrypt(
encrypted.value,
Expand All @@ -139,10 +138,10 @@ test('decrypt()', async function (t) {
encrypted.secret,
encrypted.salt
)
assert.equal(decrypted, 'foo')
t.equal(decrypted, 'foo')
})

await t.test('decrypt(foo, aes-256-gcm)', function (t) {
t.test('decrypt(foo, aes-256-gcm)', function (t) {
const encrypted = AES.encrypt('foo', 'aes-256-gcm')
const decrypted = AES.decrypt(
encrypted.value,
Expand All @@ -152,10 +151,10 @@ test('decrypt()', async function (t) {
encrypted.secret,
encrypted.salt
)
assert.equal(decrypted, 'foo')
t.equal(decrypted, 'foo')
})

await t.test('decrypt(foo, chacha20-poly1305)', function (t) {
t.test('decrypt(foo, chacha20-poly1305)', function (t) {
const encrypted = AES.encrypt('foo', 'chacha20-poly1305')
const decrypted = AES.decrypt(
encrypted.value,
Expand All @@ -165,6 +164,6 @@ test('decrypt()', async function (t) {
encrypted.secret,
encrypted.salt
)
assert.equal(decrypted, 'foo')
t.equal(decrypted, 'foo')
})
})
Loading

0 comments on commit f189159

Please sign in to comment.