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