| 1 | //go:build linux |
| 2 | |
| 3 | package host |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "github.com/carlosframework/platform/internal/provision" |
| 8 | "os" |
| 9 | "path/filepath" |
| 10 | "strconv" |
| 11 | "syscall" |
| 12 | "testing" |
| 13 | ) |
| 14 | |
| 15 | func TestPlan11Fix1NoProcessDerivesCoverage(t *testing.T) { |
| 16 | for _, name := range []string{"db", "wal", "shm", "journal", "container"} { |
| 17 | t.Run(name, func(t *testing.T) { |
| 18 | fx := newWritersKernelFixture(t) |
| 19 | fx.dropAgentHolds(t) |
| 20 | db := provision.NestedDBPath(fx.dataRoot, fx.target.Host) |
| 21 | path := db |
| 22 | switch name { |
| 23 | case "wal": |
| 24 | path += "-wal" |
| 25 | case "shm": |
| 26 | path += "-shm" |
| 27 | case "journal": |
| 28 | path += "-journal" |
| 29 | case "container": |
| 30 | path = filepath.Join(filepath.Dir(db), "nested", "state") |
| 31 | } |
| 32 | if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | f, err := os.Create(path) |
| 36 | if err != nil { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | defer f.Close() |
| 40 | pid := strconv.Itoa(os.Getpid()) |
| 41 | if err := os.Symlink(filepath.Join("/proc", pid), filepath.Join(fx.proc, pid)); err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | rel, err := filepath.Rel(fx.dataRoot, filepath.Join(filepath.Dir(db), "nonexistent")) |
| 45 | if err != nil { |
| 46 | t.Fatal(err) |
| 47 | } |
| 48 | fx.inv.Entries = []StopInventoryEntry{{Kind: "path", ManagedRoot: "data", RelativePath: rel, Type: syscall.S_IFDIR, Materialization: "intended"}} |
| 49 | if _, err := fx.noProcess(t, false); !errors.Is(err, ErrClaimStopIdentity) { |
| 50 | t.Fatalf("inventory omitted real %s holder: %v", name, err) |
| 51 | } |
| 52 | }) |
| 53 | } |
| 54 | } |
| 55 | |