(test *testing.T)
| 247 | } |
| 248 | |
| 249 | func TestWorkspaceCodeAccess(test *testing.T) { |
| 250 | current, previous := comparisonReaders(test) |
| 251 | current.Mode, current.Ref = ModeWorkspace, "" |
| 252 | access, err := NewWorkspaceCodeAccess(current, previous) |
| 253 | if err != nil { |
| 254 | test.Fatal(err) |
| 255 | } |
| 256 | providers := comparisonProviders(¤t, access) |
| 257 | baseline := comparisonProviders(¤t, nil) |
| 258 | var workers sync.WaitGroup |
| 259 | for index, provider := range providers { |
| 260 | args := comparisonArgs(provider.Tool().Name()) |
| 261 | want, err := baseline[index].Execute(context.Background(), args) |
| 262 | if err != nil { |
| 263 | test.Fatal(err) |
| 264 | } |
| 265 | for _, explicit := range []bool{false, true} { |
| 266 | if explicit { |
| 267 | args["side"] = "new" |
| 268 | } |
| 269 | got, err := provider.Execute(context.Background(), args) |
| 270 | if err != nil || got != want { |
| 271 | test.Fatalf("workspace default output changed: %q %v", got, err) |
| 272 | } |
| 273 | } |
| 274 | for _, invalid := range []any{nil, "", "staged", "HEAD", true} { |
| 275 | args["side"] = invalid |
| 276 | if _, err := provider.Execute(context.Background(), args); err == nil { |
| 277 | test.Fatalf("accepted invalid workspace side: %v", invalid) |
| 278 | } |
| 279 | } |
| 280 | for _, side := range []string{"old", "new"} { |
| 281 | workers.Go(func() { |
| 282 | args := comparisonArgs(provider.Tool().Name()) |
| 283 | args["side"] = side |
| 284 | got, err := provider.Execute(context.Background(), args) |
| 285 | want := "workspace-marker" |
| 286 | if side == "old" { |
| 287 | want = "old-marker" |
| 288 | if !strings.HasPrefix(got, "SIDE: old\nREVISION: "+previous.Ref+"\n") { |
| 289 | test.Errorf("old source missing: %q", got) |
| 290 | } |
| 291 | } |
| 292 | if provider.Tool() == FileFind { |
| 293 | want = "after.txt" |
| 294 | if side == "old" { |
| 295 | want = "before.txt" |
| 296 | } |
| 297 | } |
| 298 | if err != nil || !strings.Contains(got, want) { |
| 299 | test.Errorf("%s/%s: %q %v", provider.Tool().Name(), side, got, err) |
| 300 | } |
| 301 | }) |
| 302 | } |
| 303 | } |
| 304 | workers.Wait() |
| 305 | writeTestFile(test, current.RepoDir, "version.txt", "later-marker\n") |
| 306 | got, err := providers[0].Execute(context.Background(), map[string]any{"file_path": "version.txt"}) |
nothing calls this directly
no test coverage detected