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

Function TestGetRecursive_DownloadsDirectoryStructure

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

Source from the content-addressed store, hash-verified

316}
317
318func TestGetRecursive_DownloadsDirectoryStructure(t *testing.T) {
319 tmpDir := t.TempDir()
320 dst := filepath.Join(tmpDir, "output")
321
322 mock := &mockFilesClient{
323 listFolderFn: func(arg *files.ListFolderArg) (*files.ListFolderResult, error) {
324 if arg.Path != "/remote" {
325 t.Errorf("ListFolder path = %q, want /remote", arg.Path)
326 }
327 if !arg.Recursive {
328 t.Error("expected Recursive = true")
329 }
330 return &files.ListFolderResult{
331 Entries: []files.IsMetadata{
332 &files.FolderMetadata{Metadata: files.Metadata{PathDisplay: "/remote/sub"}},
333 &files.FileMetadata{Metadata: files.Metadata{PathDisplay: "/remote/root.txt"}, Size: 4},
334 &files.FileMetadata{Metadata: files.Metadata{PathDisplay: "/remote/sub/deep.txt"}, Size: 4},
335 },
336 HasMore: false,
337 }, nil
338 },
339 downloadFn: func(arg *files.DownloadArg) (*files.FileMetadata, io.ReadCloser, error) {
340 meta := &files.FileMetadata{
341 Metadata: files.Metadata{PathDisplay: arg.Path},
342 Size: 4,
343 }
344 return meta, io.NopCloser(strings.NewReader("data")), nil
345 },
346 }
347
348 err := getRecursive(mock, "/remote", dst)
349 if err != nil {
350 t.Fatalf("getRecursive error: %v", err)
351 }
352
353 for _, rel := range []string{"root.txt", "sub/deep.txt"} {
354 p := filepath.Join(dst, filepath.FromSlash(rel))
355 got, err := os.ReadFile(p)
356 if err != nil {
357 t.Errorf("failed to read %s: %v", rel, err)
358 continue
359 }
360 if string(got) != "data" {
361 t.Errorf("%s content = %q, want %q", rel, string(got), "data")
362 }
363 }
364
365 info, err := os.Stat(filepath.Join(dst, "sub"))
366 if err != nil {
367 t.Fatalf("sub directory not created: %v", err)
368 }
369 if !info.IsDir() {
370 t.Error("sub is not a directory")
371 }
372}
373
374func TestGetRecursive_CreatesEmptyDirectories(t *testing.T) {
375 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 2

getRecursiveFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected