(test *testing.T)
| 219 | } |
| 220 | |
| 221 | func TestWorkspaceCodeAccess(test *testing.T) { |
| 222 | current, previous := comparisonReaders(test) |
| 223 | current.Mode, current.Ref = ModeWorkspace, "" |
| 224 | access, err := NewWorkspaceCodeAccess(current, previous) |
| 225 | if err != nil { |
| 226 | test.Fatal(err) |
| 227 | } |
| 228 | providers := comparisonProviders(¤t, access) |
| 229 | baseline := comparisonProviders(¤t, nil) |
| 230 | var workers sync.WaitGroup |
| 231 | for index, provider := range providers { |
| 232 | args := comparisonArgs(provider.Tool().Name()) |
| 233 | want, err := baseline[index].Execute(context.Background(), args) |
| 234 | if err != nil { |
| 235 | test.Fatal(err) |
| 236 | } |
| 237 | for _, explicit := range []bool{false, true} { |
| 238 | if explicit { |
| 239 | args["side"] = "new" |
| 240 | } |
| 241 | got, err := provider.Execute(context.Background(), args) |
| 242 | if err != nil || got != want { |
| 243 | test.Fatalf("workspace default output changed: %q %v", got, err) |
| 244 | } |
| 245 | } |
| 246 | for _, invalid := range []any{nil, "", "staged", "HEAD", true} { |
| 247 | args["side"] = invalid |
| 248 | if _, err := provider.Execute(context.Background(), args); err == nil { |
| 249 | test.Fatalf("accepted invalid workspace side: %v", invalid) |
| 250 | } |
| 251 | } |
| 252 | for _, side := range []string{"old", "new"} { |
| 253 | workers.Go(func() { |
| 254 | args := comparisonArgs(provider.Tool().Name()) |
| 255 | args["side"] = side |
| 256 | got, err := provider.Execute(context.Background(), args) |
| 257 | want := "workspace-marker" |
| 258 | if side == "old" { |
| 259 | want = "old-marker" |
| 260 | if !strings.HasPrefix(got, "SIDE: old\nREVISION: "+previous.Ref+"\n") { |
| 261 | test.Errorf("old source missing: %q", got) |
| 262 | } |
| 263 | } |
| 264 | if provider.Tool() == FileFind { |
| 265 | want = "after.txt" |
| 266 | if side == "old" { |
| 267 | want = "before.txt" |
| 268 | } |
| 269 | } |
| 270 | if err != nil || !strings.Contains(got, want) { |
| 271 | test.Errorf("%s/%s: %q %v", provider.Tool().Name(), side, got, err) |
| 272 | } |
| 273 | }) |
| 274 | } |
| 275 | } |
| 276 | workers.Wait() |
| 277 | writeTestFile(test, current.RepoDir, "version.txt", "later-marker\n") |
| 278 | got, err := providers[0].Execute(context.Background(), map[string]any{"file_path": "version.txt"}) |
nothing calls this directly
no test coverage detected