50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
/**
|
|
* Server helper - starts/stops the registry server for integration and E2E tests
|
|
*/
|
|
|
|
import { StackGalleryRegistry } from '../../ts/registry.ts';
|
|
import { testConfig } from '../test.config.ts';
|
|
|
|
let registry: StackGalleryRegistry | null = null;
|
|
|
|
/**
|
|
* Start the registry server for testing
|
|
*/
|
|
export async function startTestServer(): Promise<StackGalleryRegistry> {
|
|
if (registry) return registry;
|
|
|
|
// Set JWT_SECRET env var so ApiRouter's AuthService uses the same secret
|
|
Deno.env.set('JWT_SECRET', testConfig.jwt.secret);
|
|
|
|
registry = new StackGalleryRegistry({
|
|
mongoUrl: testConfig.mongodb.url,
|
|
mongoDb: testConfig.mongodb.name,
|
|
s3Endpoint: testConfig.s3.endpoint,
|
|
s3AccessKey: testConfig.s3.accessKey,
|
|
s3SecretKey: testConfig.s3.secretKey,
|
|
s3Bucket: testConfig.s3.bucket,
|
|
s3Region: testConfig.s3.region,
|
|
port: testConfig.registry.port,
|
|
jwtSecret: testConfig.jwt.secret,
|
|
});
|
|
await registry.start();
|
|
return registry;
|
|
}
|
|
|
|
/**
|
|
* Stop the registry server
|
|
*/
|
|
export async function stopTestServer(): Promise<void> {
|
|
if (registry) {
|
|
await registry.stop();
|
|
registry = null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the current registry instance
|
|
*/
|
|
export function getTestRegistry(): StackGalleryRegistry | null {
|
|
return registry;
|
|
}
|