feat(api): complete phase 2.4 control plane
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { PinnedHttpRequester, type PinnedDispatchOptions } from './pinned-http-requester.js';
|
||||
|
||||
describe('PinnedHttpRequester', () => {
|
||||
it('pins Node lookup to the validated address and sets bounded request options', async () => {
|
||||
let captured: PinnedDispatchOptions | undefined;
|
||||
const requester = new PinnedHttpRequester({
|
||||
dispatch: async (options) => {
|
||||
captured = options;
|
||||
return { status: 200, headers: {}, body: '' };
|
||||
},
|
||||
});
|
||||
await requester.request(
|
||||
{ url: 'http://device.lan:8080/api/health', method: 'GET', headers: {} },
|
||||
[{ address: '192.168.1.20', family: 4 }],
|
||||
);
|
||||
if (!captured) throw new Error('dispatch was not called');
|
||||
const dispatchOptions = captured;
|
||||
expect(dispatchOptions.followRedirects).toBe(false);
|
||||
expect(dispatchOptions.timeoutMs).toBe(5000);
|
||||
expect(dispatchOptions.maxBodyBytes).toBe(65536);
|
||||
await expect(
|
||||
new Promise((resolve, reject) =>
|
||||
dispatchOptions.lookup('device.lan', { all: false }, (error, address, family) => {
|
||||
if (error) reject(error);
|
||||
else if (Array.isArray(address))
|
||||
reject(new Error('unexpected all-address lookup result'));
|
||||
else resolve({ a: address, f: family });
|
||||
}),
|
||||
),
|
||||
).resolves.toEqual({ a: '192.168.1.20', f: 4 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user