You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

  1. package store_test
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/filer"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. "github.com/stretchr/testify/assert"
  8. "os"
  9. "testing"
  10. )
  11. func TestFilerStore(t *testing.T, store filer.FilerStore) {
  12. ctx := context.Background()
  13. store.InsertEntry(ctx, makeEntry(util.FullPath("/"), true))
  14. store.InsertEntry(ctx, makeEntry(util.FullPath("/a"), true))
  15. store.InsertEntry(ctx, makeEntry(util.FullPath("/a/b"), true))
  16. store.InsertEntry(ctx, makeEntry(util.FullPath("/a/b/c"), true))
  17. for i := 0; i < 2000; i++ {
  18. store.InsertEntry(ctx, makeEntry(util.FullPath(fmt.Sprintf("/a/b/c/f%05d", i)), false))
  19. }
  20. {
  21. var counter int
  22. lastFileName, err := store.ListDirectoryEntries(ctx, util.FullPath("/a/b/c"), "", false, 3, func(entry *filer.Entry) bool {
  23. counter++
  24. return true
  25. })
  26. assert.Nil(t, err, "list directory")
  27. assert.Equal(t, 3, counter, "directory list counter")
  28. assert.Equal(t, "f00003", lastFileName, "directory list last file")
  29. lastFileName, err = store.ListDirectoryEntries(ctx, util.FullPath("/a/b/c"), lastFileName, false, 1024, func(entry *filer.Entry) bool {
  30. counter++
  31. return true
  32. })
  33. assert.Nil(t, err, "list directory")
  34. assert.Equal(t, 1027, counter, "directory list counter")
  35. assert.Equal(t, "f01027", lastFileName, "directory list last file")
  36. }
  37. }
  38. func makeEntry(fullPath util.FullPath, isDirectory bool) *filer.Entry {
  39. var mode os.FileMode
  40. if isDirectory {
  41. mode = os.ModeDir
  42. }
  43. return &filer.Entry{
  44. FullPath: fullPath,
  45. Attr: filer.Attr{
  46. Mode: mode,
  47. },
  48. }
  49. }