(t *testing.T)
| 455 | } |
| 456 | |
| 457 | func 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 | |
| 498 | func TestCpIfExistsSkipTextModeQuiet(t *testing.T) { |
| 499 | stubFilesClient(t, &mockFilesClient{ |
nothing calls this directly
no test coverage detected