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

Function TestGetFileCommandDownloadsAfterMetadata

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

Source from the content-addressed store, hash-verified

548}
549
550func TestGetFileCommandDownloadsAfterMetadata(t *testing.T) {
551 tmpDir := t.TempDir()
552 dst := filepath.Join(tmpDir, "file.txt")
553 var calls []string
554
555 mock := &mockFilesClient{
556 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
557 calls = append(calls, "metadata:"+arg.Path)
558 return &files.FileMetadata{
559 Metadata: files.Metadata{PathDisplay: arg.Path},
560 Size: 4,
561 }, nil
562 },
563 downloadFn: func(arg *files.DownloadArg) (*files.FileMetadata, io.ReadCloser, error) {
564 calls = append(calls, "download:"+arg.Path)
565 return &files.FileMetadata{
566 Metadata: files.Metadata{PathDisplay: arg.Path},
567 Size: 4,
568 }, io.NopCloser(strings.NewReader("data")), nil
569 },
570 }
571 stubFilesClient(t, mock)
572
573 cmd := &cobra.Command{}
574 cmd.Flags().BoolP("recursive", "r", false, "")
575
576 err := get(cmd, []string{"/remote-file.txt", dst})
577 if err != nil {
578 t.Fatalf("get error: %v", err)
579 }
580
581 want := []string{"metadata:/remote-file.txt", "download:/remote-file.txt"}
582 if !reflect.DeepEqual(calls, want) {
583 t.Errorf("calls = %v, want %v", calls, want)
584 }
585 got, err := os.ReadFile(dst)
586 if err != nil {
587 t.Fatalf("failed to read downloaded file: %v", err)
588 }
589 if string(got) != "data" {
590 t.Errorf("downloaded file = %q, want data", got)
591 }
592}
593
594func TestGetJSONFileOutputsDownloadedResult(t *testing.T) {
595 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 2

stubFilesClientFunction · 0.85
getFunction · 0.85

Tested by

no test coverage detected