mirror of
https://github.com/tale/headplane.git
synced 2026-08-27 15:37:04 +00:00
feat: add e2e integration tests and canonical versioning
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import tc from 'testcontainers';
|
||||
|
||||
export interface HeadscaleEnv {
|
||||
container: tc.StartedTestContainer;
|
||||
apiUrl: string;
|
||||
apiKey: string;
|
||||
}
|
||||
|
||||
const cwd = fileURLToPath(import.meta.url);
|
||||
const config = join(cwd, '..', 'config.yaml');
|
||||
|
||||
export async function startHeadscale(version: string): Promise<HeadscaleEnv> {
|
||||
const container = await new tc.GenericContainer(
|
||||
`headscale/headscale:${version}`,
|
||||
)
|
||||
.withExposedPorts(8080)
|
||||
.withWaitStrategy(
|
||||
tc.Wait.forHttp('/health', 8080)
|
||||
.withStartupTimeout(30_000)
|
||||
.forStatusCode(200),
|
||||
)
|
||||
.withCopyFilesToContainer([
|
||||
{
|
||||
source: config,
|
||||
target: '/etc/headscale/config.yaml',
|
||||
},
|
||||
])
|
||||
.withCommand(['serve'])
|
||||
.start();
|
||||
|
||||
const host = container.getHost();
|
||||
const port = container.getMappedPort(8080);
|
||||
const apiUrl = `http://${host}:${port}`;
|
||||
|
||||
const exec = await container.exec([
|
||||
'headscale',
|
||||
'apikeys',
|
||||
'create',
|
||||
'-o',
|
||||
'json',
|
||||
]);
|
||||
|
||||
if (exec.exitCode !== 0) {
|
||||
throw new Error(`headscale apikeys create failed:\n${exec.stderr}`);
|
||||
}
|
||||
|
||||
const apiKey = JSON.parse(exec.stdout.toString());
|
||||
return { container, apiUrl, apiKey };
|
||||
}
|
||||
|
||||
// await startHeadscale('0.26.0');
|
||||
Reference in New Issue
Block a user