MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestWorkspaceCodeAccess

Function TestWorkspaceCodeAccess

internal/tool/code_access_test.go:249–356  ·  view source on GitHub ↗
(test *testing.T)

Source from the content-addressed store, hash-verified

247}
248
249func 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(&current, access)
257 baseline := comparisonProviders(&current, 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"})

Callers

nothing calls this directly

Calls 9

comparisonReadersFunction · 0.85
NewWorkspaceCodeAccessFunction · 0.85
comparisonProvidersFunction · 0.85
comparisonArgsFunction · 0.85
writeTestFileFunction · 0.85
ToolMethod · 0.65
ExecuteMethod · 0.65
NameMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected