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

Function TestWorkspaceCodeAccess

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

Source from the content-addressed store, hash-verified

221}
222
223func 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(&current, access)
231 baseline := comparisonProviders(&current, 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()

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected