Skip to content

Commit 4c4abaf

Browse files
committed
WIP QUICConnectionId.test.ts
1 parent e5de149 commit 4c4abaf

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/QUICConnectionId.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import QUICConnectionId from '@/QUICConnectionId';
2+
import { quiche } from '@/native';
3+
import * as testsUtils from './utils';
4+
5+
describe(QUICConnectionId.name, () => {
6+
test('connection ID is a Uint8Array', async () => {
7+
const cidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
8+
await testsUtils.randomBytes(cidBuffer);
9+
const cid = new QUICConnectionId(cidBuffer);
10+
expect(cid).toBeInstanceOf(Uint8Array);
11+
});
12+
test('connection ID encode to hex string and decode from hex string', async () => {
13+
const cidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
14+
await testsUtils.randomBytes(cidBuffer);
15+
const cid = new QUICConnectionId(cidBuffer);
16+
const cidString = cid.toString();
17+
const cid_ = QUICConnectionId.fromString(cidString);
18+
expect(cid).toEqual(cid_);
19+
});
20+
test('connection ID to buffer and from buffer is zero-copy', async () => {
21+
const cidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
22+
await testsUtils.randomBytes(cidBuffer);
23+
const cid = new QUICConnectionId(cidBuffer);
24+
expect(cid.toBuffer().buffer).toBe(cidBuffer);
25+
const cid_ = QUICConnectionId.fromBuffer(cid.toBuffer());
26+
expect(cid_.buffer).toBe(cidBuffer);
27+
});
28+
});

0 commit comments

Comments
 (0)