(t *testing.T)
| 265 | } |
| 266 | |
| 267 | func TestCpJSONErrorUsesCommandStderr(t *testing.T) { |
| 268 | stubFilesClient(t, &mockFilesClient{ |
| 269 | getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) { |
| 270 | return nil, fmt.Errorf("path/not_found/") |
| 271 | }, |
| 272 | copyV2Fn: func(arg *files.RelocationArg) (*files.RelocationResult, error) { |
| 273 | return nil, fmt.Errorf("path/malformed_path/") |
| 274 | }, |
| 275 | }) |
| 276 | |
| 277 | var stdout bytes.Buffer |
| 278 | var stderr bytes.Buffer |
| 279 | cmd := newRelocationTestCommand(&stdout, &stderr) |
| 280 | |
| 281 | err := cp(cmd, []string{"/src/file.txt", "/dest/file.txt"}) |
| 282 | if err == nil { |
| 283 | t.Fatal("expected cp error") |
| 284 | } |
| 285 | if stdout.String() != "" { |
| 286 | t.Fatalf("stdout = %q, want empty", stdout.String()) |
| 287 | } |
| 288 | if !strings.Contains(stderr.String(), `copy "/src/file.txt" to "/dest/file.txt": path/malformed_path/`) { |
| 289 | t.Fatalf("stderr = %q, want copy API error", stderr.String()) |
| 290 | } |
| 291 | details := jsonErrorDetails(err) |
| 292 | if details["operation"] != "copy" || details["from_path"] != "/src/file.txt" || details["to_path"] != "/dest/file.txt" { |
| 293 | t.Fatalf("details = %#v, want copy from/to paths", details) |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | func TestCpCommandDefinesIfExistsFlag(t *testing.T) { |
| 298 | flag := cpCmd.Flags().Lookup("if-exists") |
nothing calls this directly
no test coverage detected