-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathQUICConnectionId.test.ts
28 lines (27 loc) · 1.18 KB
/
QUICConnectionId.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import * as testsUtils from './utils.js';
import QUICConnectionId from '#QUICConnectionId.js';
import quiche from '#native/quiche.js';
describe(QUICConnectionId.name, () => {
test('connection ID is a Uint8Array', async () => {
const cidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
await testsUtils.randomBytes(cidBuffer);
const cid = new QUICConnectionId(cidBuffer);
expect(cid).toBeInstanceOf(Uint8Array);
});
test('connection ID encode to hex string and decode from hex string', async () => {
const cidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
await testsUtils.randomBytes(cidBuffer);
const cid = new QUICConnectionId(cidBuffer);
const cidString = cid.toString();
const cid_ = QUICConnectionId.fromString(cidString);
expect(cid).toEqual(cid_);
});
test('connection ID to buffer and from buffer is zero-copy', async () => {
const cidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
await testsUtils.randomBytes(cidBuffer);
const cid = new QUICConnectionId(cidBuffer);
expect(cid.toBuffer().buffer).toBe(cidBuffer);
const cid_ = QUICConnectionId.fromBuffer(cid.toBuffer());
expect(cid_.buffer).toBe(cidBuffer);
});
});