test: add docker and proc e2e testing

This commit is contained in:
Aarnav Tale
2026-03-19 12:06:14 -04:00
parent 7403ebea06
commit 246bb90ef0
14 changed files with 488 additions and 276 deletions
+43 -40
View File
@@ -1,51 +1,54 @@
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import tc from 'testcontainers';
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import tc from "testcontainers";
export interface HeadscaleEnv {
container: tc.StartedTestContainer;
apiUrl: string;
apiKey: string;
container: tc.StartedTestContainer;
apiUrl: string;
apiKey: string;
}
export interface HeadscaleOptions {
labels?: Record<string, string>;
}
const cwd = fileURLToPath(import.meta.url);
const config = join(cwd, '..', 'config.yaml');
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();
export async function startHeadscale(
version: string,
options?: HeadscaleOptions,
): Promise<HeadscaleEnv> {
let builder = 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"]);
const host = container.getHost();
const port = container.getMappedPort(8080);
const apiUrl = `http://${host}:${port}`;
if (options?.labels) {
builder = builder.withLabels(options.labels);
}
const exec = await container.exec([
'headscale',
'apikeys',
'create',
'-o',
'json',
]);
const container = await builder.start();
if (exec.exitCode !== 0) {
throw new Error(`headscale apikeys create failed:\n${exec.stderr}`);
}
const host = container.getHost();
const port = container.getMappedPort(8080);
const apiUrl = `http://${host}:${port}`;
const apiKey = JSON.parse(exec.stdout.toString());
return { container, apiUrl, apiKey };
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 };
}