mirror of
https://github.com/juanfont/headscale.git
synced 2025-07-10 09:32:25 -04:00
* cmd/hi: add integration test runner CLI tool Add a new CLI tool 'hi' for running headscale integration tests with Docker automation. The tool replaces manual Docker command composition with an automated solution. Features: - Run integration tests in golang:1.24 containers - Docker context detection (supports colima and other contexts) - Test isolation with unique run IDs and isolated control_logs - Automatic Docker image pulling and container management - Comprehensive cleanup operations for containers, networks, images - Docker volume caching for Go modules - Verbose logging and detailed test artifact reporting - Support for PostgreSQL/SQLite selection and various test flags Usage: go run ./cmd/hi run TestPingAllByIP --verbose The tool uses creachadair/command and flax for CLI parsing and provides cleanup subcommands for Docker resource management. Updates flake.nix vendorHash for new Go dependencies. * ci: update integration tests to use hi CLI tool Replace manual Docker command composition in GitHub Actions workflow with the new hi CLI tool for running integration tests. Changes: - Replace complex docker run command with simple 'go run ./cmd/hi run' - Remove manual environment variable setup (handled by hi tool) - Update artifact paths for new timestamped log directory structure - Simplify command from 15+ lines to 3 lines - Maintain all existing functionality (postgres/sqlite, timeout, test patterns) The hi tool automatically handles Docker context detection, container management, volume mounting, and environment variable setup that was previously done manually in the workflow. * makefile: remove test integration Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com> --------- Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
94 lines
2.0 KiB
Go
94 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/creachadair/command"
|
|
"github.com/creachadair/flax"
|
|
)
|
|
|
|
var runConfig RunConfig
|
|
|
|
func main() {
|
|
root := command.C{
|
|
Name: "hi",
|
|
Help: "Headscale Integration test runner",
|
|
Commands: []*command.C{
|
|
{
|
|
Name: "run",
|
|
Help: "Run integration tests",
|
|
Usage: "run [test-pattern] [flags]",
|
|
SetFlags: command.Flags(flax.MustBind, &runConfig),
|
|
Run: runIntegrationTest,
|
|
},
|
|
{
|
|
Name: "doctor",
|
|
Help: "Check system requirements for running integration tests",
|
|
Run: func(env *command.Env) error {
|
|
return runDoctorCheck(env.Context())
|
|
},
|
|
},
|
|
{
|
|
Name: "clean",
|
|
Help: "Clean Docker resources",
|
|
Commands: []*command.C{
|
|
{
|
|
Name: "networks",
|
|
Help: "Prune unused Docker networks",
|
|
Run: func(env *command.Env) error {
|
|
return pruneDockerNetworks(env.Context())
|
|
},
|
|
},
|
|
{
|
|
Name: "images",
|
|
Help: "Clean old test images",
|
|
Run: func(env *command.Env) error {
|
|
return cleanOldImages(env.Context())
|
|
},
|
|
},
|
|
{
|
|
Name: "containers",
|
|
Help: "Kill all test containers",
|
|
Run: func(env *command.Env) error {
|
|
return killTestContainers(env.Context())
|
|
},
|
|
},
|
|
{
|
|
Name: "cache",
|
|
Help: "Clean Go module cache volume",
|
|
Run: func(env *command.Env) error {
|
|
return cleanCacheVolume(env.Context())
|
|
},
|
|
},
|
|
{
|
|
Name: "all",
|
|
Help: "Run all cleanup operations",
|
|
Run: func(env *command.Env) error {
|
|
return cleanAll(env.Context())
|
|
},
|
|
},
|
|
},
|
|
},
|
|
command.HelpCommand(nil),
|
|
},
|
|
}
|
|
|
|
env := root.NewEnv(nil).MergeFlags(true)
|
|
command.RunOrFail(env, os.Args[1:])
|
|
}
|
|
|
|
func cleanAll(ctx context.Context) error {
|
|
if err := killTestContainers(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := pruneDockerNetworks(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := cleanOldImages(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
return cleanCacheVolume(ctx)
|
|
}
|