From 135f6edbd9389bc4783f13c26aed0a74d3c8aca0 Mon Sep 17 00:00:00 2001 From: James O'Doherty Date: Fri, 22 May 2026 16:17:55 -0400 Subject: 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 --- internal/namespace/pinning_test.go | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 internal/namespace/pinning_test.go (limited to 'internal/namespace/pinning_test.go') diff --git a/internal/namespace/pinning_test.go b/internal/namespace/pinning_test.go new file mode 100644 index 0000000..c65e1b1 --- /dev/null +++ b/internal/namespace/pinning_test.go @@ -0,0 +1,53 @@ +package namespace + +import ( + "os" + "path/filepath" + "testing" + + "git.theodohertyfamily.com/tools/wg-wrap/internal/paths" +) + +func TestUnpinNamespace(t *testing.T) { + tmpDir := t.TempDir() + pm := paths.NewPathManager("", tmpDir) + profile := "test-profile" + nsPath := GetProfileNamespacePath(pm, profile) + + // Create the base profiles directory first + profilesDir := filepath.Dir(nsPath) + if err := os.MkdirAll(profilesDir, 0755); err != nil { + t.Fatalf("failed to create profiles dir: %v", err) + } + + // Create dummy namespace file + if err := os.WriteFile(nsPath, []byte("dummy"), 0644); err != nil { + t.Fatalf("failed to create ns file: %v", err) + } + + pidsDir := GetPidsDirPath(pm, profile) + if err := os.MkdirAll(pidsDir, 0755); err != nil { + t.Fatalf("failed to create pids dir: %v", err) + } + + t.Run("successfully unpins", func(t *testing.T) { + err := UnpinNamespace(pm, profile) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + if _, err := os.Stat(nsPath); !os.IsNotExist(err) { + t.Errorf("namespace file should have been deleted") + } + if _, err := os.Stat(pidsDir); !os.IsNotExist(err) { + t.Errorf("pids directory should have been deleted") + } + }) + + t.Run("handles non-existent namespace", func(t *testing.T) { + err := UnpinNamespace(pm, profile) + if err != nil { + t.Errorf("unexpected error when unpinning non-existent namespace: %v", err) + } + }) +} -- cgit v1.2.3