MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestCpIfExistsSkipMultipleSourcesAppliesPerTarget

Function TestCpIfExistsSkipMultipleSourcesAppliesPerTarget

cmd/cp_test.go:457–496  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

455}
456
457func TestCpIfExistsSkipMultipleSourcesAppliesPerTarget(t *testing.T) {
458 var copied []string
459 stubFilesClient(t, &mockFilesClient{
460 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
461 switch arg.Path {
462 case "/dest/a.txt":
463 return relocationTestFileMetadata(arg.Path, 1), nil
464 case "/dest/b.txt":
465 return nil, relocationTestGetMetadataNotFoundError()
466 default:
467 t.Fatalf("unexpected metadata path %q", arg.Path)
468 return nil, nil
469 }
470 },
471 copyV2Fn: func(arg *files.RelocationArg) (*files.RelocationResult, error) {
472 copied = append(copied, arg.ToPath)
473 return files.NewRelocationResult(relocationTestFileMetadata(arg.ToPath, 2)), nil
474 },
475 })
476
477 var stdout bytes.Buffer
478 cmd := newRelocationTestCommand(&stdout, nil)
479 if err := cmd.Flags().Set("if-exists", relocationIfExistsSkip); err != nil {
480 t.Fatal(err)
481 }
482
483 if err := cp(cmd, []string{"/src/a.txt", "/src/b.txt", "/dest"}); err != nil {
484 t.Fatalf("cp error: %v", err)
485 }
486 if len(copied) != 1 || copied[0] != "/dest/b.txt" {
487 t.Fatalf("copied = %#v, want only /dest/b.txt", copied)
488 }
489 got := decodeRelocationOutput(t, stdout.Bytes())
490 if len(got.Results) != 2 {
491 t.Fatalf("results = %d, want 2", len(got.Results))
492 }
493 if got.Results[0].Status != relocationJSONStatusSkipped || got.Results[1].Status != relocationJSONStatusCopied {
494 t.Fatalf("statuses = %q, %q; want skipped, copied", got.Results[0].Status, got.Results[1].Status)
495 }
496}
497
498func TestCpIfExistsSkipTextModeQuiet(t *testing.T) {
499 stubFilesClient(t, &mockFilesClient{

Callers

nothing calls this directly

Calls 6

stubFilesClientFunction · 0.85
newRelocationTestCommandFunction · 0.85
cpFunction · 0.85
decodeRelocationOutputFunction · 0.85

Tested by

no test coverage detected