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

Function TestGetJSONFileOutputsDownloadedResult

cmd/get_test.go:594–646  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

592}
593
594func TestGetJSONFileOutputsDownloadedResult(t *testing.T) {
595 tmpDir := t.TempDir()
596 dst := filepath.Join(tmpDir, "file.txt")
597
598 mock := &mockFilesClient{
599 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
600 return getTestFileMetadata(arg.Path, 4), nil
601 },
602 downloadFn: func(arg *files.DownloadArg) (*files.FileMetadata, io.ReadCloser, error) {
603 if arg.Path != "/remote/file.txt" {
604 t.Fatalf("download path = %q, want /remote/file.txt", arg.Path)
605 }
606 return getTestFileMetadata(arg.Path, 4), io.NopCloser(strings.NewReader("data")), nil
607 },
608 }
609 stubFilesClient(t, mock)
610
611 var stdout, stderr bytes.Buffer
612 cmd := testGetJSONCmd(&stdout, &stderr)
613 if err := get(cmd, []string{"/remote/file.txt", dst}); err != nil {
614 t.Fatalf("get error: %v", err)
615 }
616
617 got := decodeGetOutput(t, &stdout)
618 if got.Input.Source != "/remote/file.txt" || got.Input.Target != dst || got.Input.Recursive || got.Input.Stdout {
619 t.Fatalf("input = %+v", got.Input)
620 }
621 if len(got.Results) != 1 {
622 t.Fatalf("results len = %d, want 1", len(got.Results))
623 }
624 result := got.Results[0]
625 if result.Status != getStatusDownloaded || result.Kind != getKindFile {
626 t.Fatalf("result status/kind = %s/%s", result.Status, result.Kind)
627 }
628 if result.Input.Source != "/remote/file.txt" || result.Input.Target != dst {
629 t.Fatalf("result input = %+v", result.Input)
630 }
631 if result.Result == nil || result.Result.Type != "file" || result.Result.PathDisplay != "/remote/file.txt" {
632 t.Fatalf("metadata = %+v", result.Result)
633 }
634 if result.Result.Size == nil || *result.Result.Size != 4 {
635 t.Fatalf("size = %v, want 4", result.Result.Size)
636 }
637 if strings.Contains(stdout.String(), "Downloading ") {
638 t.Fatalf("stdout contains progress: %q", stdout.String())
639 }
640 if !strings.Contains(stderr.String(), "Downloading ") {
641 t.Fatalf("stderr = %q, want download progress", stderr.String())
642 }
643 if content, err := os.ReadFile(dst); err != nil || string(content) != "data" {
644 t.Fatalf("downloaded file = %q, %v; want data", string(content), err)
645 }
646}
647
648func TestGetJSONDefaultTargetUsesBasename(t *testing.T) {
649 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 5

getTestFileMetadataFunction · 0.85
stubFilesClientFunction · 0.85
testGetJSONCmdFunction · 0.85
getFunction · 0.85
decodeGetOutputFunction · 0.85

Tested by

no test coverage detected