diff options
| author | James O'Doherty <james@theodohertyfamily.com> | 2026-05-22 16:17:55 -0400 |
|---|---|---|
| committer | James O'Doherty <james@theodohertyfamily.com> | 2026-05-22 16:17:55 -0400 |
| commit | 135f6edbd9389bc4783f13c26aed0a74d3c8aca0 (patch) | |
| tree | 41a8e80b0dcf2c42b045bc91d9101deceb049f47 /internal/namespace/lifecycle_test.go | |
| parent | 2e3a1d07b43e6e942e51ba263c6fcdc2351afc0d (diff) | |
refactor: unify path management and complete profile management system
- Create internal/paths package for unified config and runtime directory resolution
- Implement robust WireGuard config parsing in pkg/wgconf
- Implement profile management subcommands: list, import, configure, delete, stop
- Fix namespace pinning path collisions (separating .ns files from pids directories)
- Implement and verify namespace unpinning logic
- Fix linting errors and improve error handling across the project
Diffstat (limited to 'internal/namespace/lifecycle_test.go')
| -rw-r--r-- | internal/namespace/lifecycle_test.go | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/internal/namespace/lifecycle_test.go b/internal/namespace/lifecycle_test.go index db04e67..230e93a 100644 --- a/internal/namespace/lifecycle_test.go +++ b/internal/namespace/lifecycle_test.go @@ -5,27 +5,30 @@ import ( "path/filepath" "strconv" "testing" + + "git.theodohertyfamily.com/tools/wg-wrap/internal/paths" ) func TestLifecycleReferenceCounting(t *testing.T) { // Use a temporary directory to avoid polluting the system tmpDir := t.TempDir() + pm := paths.NewPathManager("", tmpDir) profile := "test-vpn" t.Run("RegisterAndUnregister", func(t *testing.T) { - err := RegisterProcess(tmpDir, profile) + err := RegisterProcess(pm, profile) if err != nil { t.Fatalf("failed to register: %v", err) } - pidsDir := GetPidsDirPath(tmpDir, profile) + pidsDir := GetPidsDirPath(pm, profile) pidFile := filepath.Join(pidsDir, strconv.Itoa(os.Getpid())) if _, err := os.Stat(pidFile); os.IsNotExist(err) { t.Errorf("PID file should exist at %s", pidFile) } - err = UnregisterProcess(tmpDir, profile) + err = UnregisterProcess(pm, profile) if err != nil { t.Fatalf("failed to unregister: %v", err) } @@ -36,20 +39,22 @@ func TestLifecycleReferenceCounting(t *testing.T) { }) t.Run("PruneStalePids", func(t *testing.T) { - pidsDir := GetPidsDirPath(tmpDir, profile) + pidsDir := GetPidsDirPath(pm, profile) if err := os.MkdirAll(pidsDir, 0755); err != nil { t.Fatal(err) } - fakePid := "9999999" + fakePid := "9999999" fakePidFile := filepath.Join(pidsDir, fakePid) if err := os.WriteFile(fakePidFile, []byte(""), 0644); err != nil { t.Fatal(err) } - RegisterProcess(tmpDir, profile) + if err := RegisterProcess(pm, profile); err != nil { + t.Fatal(err) + } - err := PruneStalePids(tmpDir, profile) + err := PruneStalePids(pm, profile) if err != nil { t.Fatalf("prune failed: %v", err) } @@ -62,27 +67,35 @@ func TestLifecycleReferenceCounting(t *testing.T) { if _, err := os.Stat(currentPidFile); os.IsNotExist(err) { t.Errorf("Current PID file %s should not have been pruned", currentPidFile) } - - UnregisterProcess(tmpDir, profile) + + if err := UnregisterProcess(pm, profile); err != nil { + t.Fatal(err) + } }) t.Run("IsLastProcess", func(t *testing.T) { - pidsDir := GetPidsDirPath(tmpDir, profile) - os.RemoveAll(pidsDir) // Reset + pidsDir := GetPidsDirPath(pm, profile) + if err := os.RemoveAll(pidsDir); err != nil { + t.Fatal(err) + } - isLast, err := IsLastProcess(tmpDir, profile) + isLast, err := IsLastProcess(pm, profile) if err != nil || !isLast { t.Errorf("Expected IsLastProcess to be true for empty profile, got %v, err: %v", isLast, err) } - RegisterProcess(tmpDir, profile) - isLast, err = IsLastProcess(tmpDir, profile) + if err := RegisterProcess(pm, profile); err != nil { + t.Fatal(err) + } + isLast, err = IsLastProcess(pm, profile) if err != nil || !isLast { t.Errorf("Expected IsLastProcess to be true for single process, got %v, err: %v", isLast, err) } - os.WriteFile(filepath.Join(pidsDir, "1234567"), []byte(""), 0644) - isLast, err = IsLastProcess(tmpDir, profile) + if err := os.WriteFile(filepath.Join(pidsDir, "1234567"), []byte(""), 0644); err != nil { + t.Fatal(err) + } + isLast, err = IsLastProcess(pm, profile) if err != nil || !isLast { t.Errorf("Expected IsLastProcess to be true because 1234567 is dead, got %v, err: %v", isLast, err) } |
