-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
215 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert/strict'; | ||
import { serializePartitionParams } from './partition.utils.js'; | ||
|
||
describe('serializePartitionParams', () => { | ||
|
||
it('serialize 2 numeric id & a uint32 into buffer', () => { | ||
assert.deepEqual( | ||
serializePartitionParams(12, 34, 512).length, | ||
6 + 6 + 4 | ||
); | ||
}); | ||
|
||
it('throw on partition count < 1', () => { | ||
assert.throws( | ||
() => serializePartitionParams(2, 1, 0), | ||
); | ||
}); | ||
|
||
it('throw on partition count > 1000', () => { | ||
assert.throws( | ||
() => serializePartitionParams(1, 1, 1001), | ||
); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert/strict'; | ||
import { LOGIN_WITH_TOKEN } from './login-with-token.command.js'; | ||
|
||
|
||
describe("Login with token Command", () => { | ||
|
||
// @warn use ascii char to keep char.length === byteLength | ||
const token = 'thisIsBigSecretToken123'; | ||
|
||
it("serialize token into a buffer", () => { | ||
assert.deepEqual( | ||
LOGIN_WITH_TOKEN.serialize(token).length, | ||
1 + token.length | ||
); | ||
}); | ||
|
||
it("throw on empty token", () => { | ||
assert.throws( | ||
() => LOGIN_WITH_TOKEN.serialize("") | ||
); | ||
}); | ||
|
||
it("throw on token > 255 bytes", () => { | ||
assert.throws( | ||
() => LOGIN_WITH_TOKEN.serialize("YoLo".repeat(65)) | ||
); | ||
}); | ||
|
||
it("throw on login > 255 bytes - utf8 version", () => { | ||
assert.throws( | ||
() => LOGIN_WITH_TOKEN.serialize("¥Ø£Ø".repeat(33)) | ||
); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert/strict'; | ||
import { CREATE_STREAM } from './create-stream.command.js'; | ||
|
||
describe('CreateStream', () => { | ||
|
||
describe('serialize', () => { | ||
|
||
it('serialize 1 numeric id & 1 name into buffer', () => { | ||
const name = 'test-stream'; | ||
assert.deepEqual( | ||
CREATE_STREAM.serialize(1, name).length, | ||
4 + 1 + name.length | ||
); | ||
}); | ||
|
||
it('throw on name < 1', () => { | ||
assert.throws( | ||
() => CREATE_STREAM.serialize(1, '') | ||
); | ||
}); | ||
|
||
it("throw on name > 255 bytes", () => { | ||
assert.throws( | ||
() => CREATE_STREAM.serialize(1, "YoLo".repeat(65)) | ||
); | ||
}); | ||
|
||
it("throw on name > 255 bytes - utf8 version", () => { | ||
assert.throws( | ||
() => CREATE_STREAM.serialize(3, "¥Ø£Ø".repeat(33)) | ||
); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert/strict'; | ||
import { CREATE_TOKEN } from './create-token.command.js'; | ||
|
||
describe('CreateToken', () => { | ||
|
||
describe('serialize', () => { | ||
|
||
const name = 'test-token'; | ||
const expiry = 1234; | ||
|
||
it('serialize 1 name & 1 uint32 into buffer', () => { | ||
|
||
assert.deepEqual( | ||
CREATE_TOKEN.serialize(name, expiry).length, | ||
4 + 1 + name.length | ||
); | ||
}); | ||
|
||
it('throw on name < 1', () => { | ||
assert.throws( | ||
() => CREATE_TOKEN.serialize('', expiry) | ||
); | ||
}); | ||
|
||
it("throw on name > 255 bytes", () => { | ||
assert.throws( | ||
() => CREATE_TOKEN.serialize("YoLo".repeat(65), expiry) | ||
); | ||
}); | ||
|
||
it("throw on name > 255 bytes - utf8 version", () => { | ||
assert.throws( | ||
() => CREATE_TOKEN.serialize("¥Ø£Ø".repeat(33), expiry) | ||
); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert/strict'; | ||
import { CREATE_TOPIC } from './create-topic.command.js'; | ||
|
||
describe('CreateTopic', () => { | ||
|
||
describe('serialize', () => { | ||
// serialize: ( | ||
// streamId: Id, | ||
// topicId: number, | ||
// name: string, | ||
// partitionCount: number, | ||
// messageExpiry = 0, | ||
// maxTopicSize = 0, | ||
// replicationFactor = 1 | ||
// ) => { ... } | ||
|
||
const name = 'test-topic'; | ||
|
||
it('serialize 1 numeric id & 1 name into buffer', () => { | ||
assert.deepEqual( | ||
CREATE_TOPIC.serialize(1, 2, name, 1, 0, 0, 1).length, | ||
6 + 4 + 4 + 4 + 8 + 1 + 1 + name.length | ||
); | ||
}); | ||
|
||
it('throw on name < 1', () => { | ||
assert.throws( | ||
() => CREATE_TOPIC.serialize(1, 2, '', 1) | ||
); | ||
}); | ||
|
||
it("throw on name > 255 bytes", () => { | ||
assert.throws( | ||
() => CREATE_TOPIC.serialize(1, 2, "YoLo".repeat(65), 1) | ||
); | ||
}); | ||
|
||
it("throw on name > 255 bytes - utf8 version", () => { | ||
assert.throws( | ||
() => CREATE_TOPIC.serialize(1, 3, "¥Ø£Ø".repeat(33), 2) | ||
); | ||
}); | ||
|
||
it('throw on replication_factor < 1', () => { | ||
assert.throws( | ||
() => CREATE_TOPIC.serialize(1, 2, name, 1, 0, 0, 0), | ||
); | ||
}); | ||
|
||
it('throw on replication_factor > 255', () => { | ||
assert.throws( | ||
() => CREATE_TOPIC.serialize(1, 2, name, 1, 0, 0, 256), | ||
); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters