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

Function TestWorkspaceCodeAccess

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

Source from the content-addressed store, hash-verified

219}
220
221func 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(&current, access)
229 baseline := comparisonProviders(&current, 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"})

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