From 29621ecbd1e77e6e1a70b6b3ea8fbe3a56e47df3 Mon Sep 17 00:00:00 2001 From: James O'Doherty Date: Sat, 13 Jun 2026 11:51:04 -0400 Subject: refactor: implement dependency injection and enable parallel testing This commit refactors the core system operations to use a manager-based dependency injection pattern, eliminating global state and resolving data races in the test suite. Architecture: - Introduced NetworkManager and NetworkOps interface in internal/network to abstract netlink calls. - Introduced MountOps and FileSystem interfaces in internal/namespace to abstract mount and filesystem operations. - Introduced TunnelManager in internal/wireguard to coordinate tunnel lifecycle using the new abstractions. - Updated internal/cli and internal/manager to use these managers. Testing: - Restored t.Parallel() to unit tests in internal/network and internal/wireguard. - Implemented setupParallelEnv and an enhanced mockFS in wireguard_unit_test.go to ensure complete test isolation. - Added bootstrap_test.go to verify launcher preparation logic in internal/namespace without requiring syscall.Exec. - Resolved data races in internal/network tests. CLI: - Added support for -h, --help, and -help flags for the main command. Verification: - Passed all tests (unit, integration, E2E). - Verified zero data races with 'go test -race'. - Passed golangci-lint and go vet. --- internal/cli/cli.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'internal/cli/cli.go') diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 5beb989..b38d0d9 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -56,7 +56,13 @@ func (a *App) Route() error { return fmt.Errorf("no command provided") } - switch a.Args[1] { + firstArg := a.Args[1] + if firstArg == "-h" || firstArg == "--help" || firstArg == "-help" { + a.printUsage() + return nil + } + + switch firstArg { case "show-config": return a.showConfig() case "profile": @@ -71,7 +77,7 @@ func (a *App) Route() error { return a.testLifecycle() default: a.printUsage() - return fmt.Errorf("unknown command: %s", a.Args[1]) + return fmt.Errorf("unknown command: %s", firstArg) } } -- cgit v1.2.3