(t *testing.T)
| 178 | } |
| 179 | |
| 180 | func TestIsRunningInvalidPIDInputs(t *testing.T) { |
| 181 | tests := []struct { |
| 182 | name string |
| 183 | pidContent string |
| 184 | writePID bool |
| 185 | }{ |
| 186 | {name: "missing pid file", writePID: false}, |
| 187 | {name: "invalid pid format", pidContent: "NaN", writePID: true}, |
| 188 | {name: "nonexistent pid", pidContent: "999999", writePID: true}, |
| 189 | } |
| 190 | |
| 191 | for _, tt := range tests { |
| 192 | t.Run(tt.name, func(t *testing.T) { |
| 193 | root := t.TempDir() |
| 194 | codemapDir := filepath.Join(root, ".codemap") |
| 195 | if err := os.MkdirAll(codemapDir, 0o755); err != nil { |
| 196 | t.Fatal(err) |
| 197 | } |
| 198 | if tt.writePID { |
| 199 | if err := os.WriteFile(filepath.Join(codemapDir, "watch.pid"), []byte(tt.pidContent), 0o644); err != nil { |
| 200 | t.Fatal(err) |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | if IsRunning(root) { |
| 205 | t.Fatalf("IsRunning(root=%q, pidContent=%q) = true, want false", root, tt.pidContent) |
| 206 | } |
| 207 | }) |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | func TestStopWithoutPIDFileReturnsNoDaemonError(t *testing.T) { |
| 212 | root := t.TempDir() |
nothing calls this directly
no test coverage detected