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

Function TestGetJSONRecursiveErrorEmitsNoSuccessJSON

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

Source from the content-addressed store, hash-verified

834}
835
836func TestGetJSONRecursiveErrorEmitsNoSuccessJSON(t *testing.T) {
837 tmpDir := t.TempDir()
838 dst := filepath.Join(tmpDir, "out")
839
840 mock := &mockFilesClient{
841 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
842 return getTestFolderMetadata(arg.Path), nil
843 },
844 listFolderFn: func(arg *files.ListFolderArg) (*files.ListFolderResult, error) {
845 return &files.ListFolderResult{
846 Entries: []files.IsMetadata{
847 getTestFileMetadata("/remote/good.txt", 4),
848 getTestFileMetadata("/remote/bad.txt", 4),
849 },
850 HasMore: false,
851 }, nil
852 },
853 downloadFn: func(arg *files.DownloadArg) (*files.FileMetadata, io.ReadCloser, error) {
854 if strings.Contains(arg.Path, "bad.txt") {
855 return nil, nil, &files.DownloadAPIError{}
856 }
857 return getTestFileMetadata(arg.Path, 4), io.NopCloser(strings.NewReader("data")), nil
858 },
859 }
860 stubFilesClient(t, mock)
861
862 var stdout bytes.Buffer
863 cmd := testGetJSONCmd(&stdout, nil)
864 if err := cmd.Flags().Set("recursive", "true"); err != nil {
865 t.Fatal(err)
866 }
867 err := get(cmd, []string{"/remote", dst})
868 if err == nil {
869 t.Fatal("expected recursive error")
870 }
871 details := jsonErrorDetails(err)
872 if details["operation"] != "download" || details["path"] != "/remote" {
873 t.Fatalf("details = %#v, want download operation and source path", details)
874 }
875 if stdout.Len() != 0 {
876 t.Fatalf("stdout = %q, want empty on recursive error", stdout.String())
877 }
878 if _, statErr := os.Stat(filepath.Join(dst, "good.txt")); statErr != nil {
879 t.Fatalf("good file was not downloaded before failure: %v", statErr)
880 }
881}
882
883func TestGetRecursive_AppendsSourceBaseWhenDstIsDirectory(t *testing.T) {
884 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 6

getTestFolderMetadataFunction · 0.85
getTestFileMetadataFunction · 0.85
stubFilesClientFunction · 0.85
testGetJSONCmdFunction · 0.85
getFunction · 0.85
jsonErrorDetailsFunction · 0.85

Tested by

no test coverage detected