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

Function TestCpJSONErrorUsesCommandStderr

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

Source from the content-addressed store, hash-verified

265}
266
267func 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
297func TestCpCommandDefinesIfExistsFlag(t *testing.T) {
298 flag := cpCmd.Flags().Lookup("if-exists")

Callers

nothing calls this directly

Calls 4

stubFilesClientFunction · 0.85
newRelocationTestCommandFunction · 0.85
cpFunction · 0.85
jsonErrorDetailsFunction · 0.85

Tested by

no test coverage detected