feat(dcrouter): add managed local dcrouter mode with status controls and gateway integration
This commit is contained in:
@@ -164,6 +164,49 @@ Deno.test('ExternalGatewayManager syncs service routes to dcrouter gatewayClient
|
||||
assertEquals(syncRequest.requestData.enabled, true);
|
||||
});
|
||||
|
||||
Deno.test('ExternalGatewayManager uses managed dcrouter local target in managed mode', async () => {
|
||||
const oneboxRef = makeOneboxRef();
|
||||
(oneboxRef as any).managedDcRouter = {
|
||||
getMode: () => 'managed',
|
||||
getGatewayUrl: () => 'http://127.0.0.1:3300',
|
||||
getAdminToken: async () => 'dcr-managed-token',
|
||||
ensureGatewayClientId: () => 'onebox-managed',
|
||||
getRouteTarget: () => ({ host: 'onebox-smartproxy', port: 80 }),
|
||||
};
|
||||
|
||||
const service: IService = {
|
||||
id: 1,
|
||||
name: 'hello',
|
||||
image: 'nginx:latest',
|
||||
envVars: {},
|
||||
port: 3000,
|
||||
domain: 'hello.example.com',
|
||||
status: 'running',
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
};
|
||||
|
||||
let syncRequest: Record<string, unknown> | null = null;
|
||||
const manager = new ExternalGatewayManager(oneboxRef as any);
|
||||
(manager as any).fireDcRouterRequest = async (method: string, requestData: Record<string, unknown>, config: any) => {
|
||||
if (method === 'exportCertificate') {
|
||||
return { success: false };
|
||||
}
|
||||
assertEquals(config.url, 'http://127.0.0.1:3300');
|
||||
assertEquals(config.apiToken, 'dcr-managed-token');
|
||||
syncRequest = requestData;
|
||||
return { success: true, action: 'created', routeId: 'route-1' };
|
||||
};
|
||||
|
||||
await manager.syncServiceRoute(service);
|
||||
|
||||
assert(syncRequest);
|
||||
const route = (syncRequest as Record<string, unknown>).route as any;
|
||||
const ownership = (syncRequest as Record<string, unknown>).ownership as any;
|
||||
assertEquals(ownership.gatewayClientId, 'onebox-managed');
|
||||
assertEquals(route.action.targets, [{ host: 'onebox-smartproxy', port: 80 }]);
|
||||
});
|
||||
|
||||
Deno.test('ExternalGatewayManager deletes service routes through dcrouter gatewayClient API', async () => {
|
||||
const oneboxRef = makeOneboxRef();
|
||||
const manager = new ExternalGatewayManager(oneboxRef as any);
|
||||
|
||||
Reference in New Issue
Block a user