aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/rocksdb/rocksdb_store_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/filer/rocksdb/rocksdb_store_test.go')
-rw-r--r--weed/filer/rocksdb/rocksdb_store_test.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/weed/filer/rocksdb/rocksdb_store_test.go b/weed/filer/rocksdb/rocksdb_store_test.go
index 4bec0d8fc..35181d601 100644
--- a/weed/filer/rocksdb/rocksdb_store_test.go
+++ b/weed/filer/rocksdb/rocksdb_store_test.go
@@ -11,6 +11,7 @@ import (
"time"
"github.com/seaweedfs/seaweedfs/weed/filer"
+ "github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/util"
)
@@ -112,3 +113,73 @@ func BenchmarkInsertEntry(b *testing.B) {
store.InsertEntry(ctx, entry)
}
}
+
+func TestListDirectoryWithPrefix(t *testing.T) {
+ testFiler := filer.NewFiler(pb.ServerDiscovery{}, nil, "", "", "", "", "", 255, nil)
+ dir := t.TempDir()
+ store := &RocksDBStore{}
+ store.initialize(dir)
+ testFiler.SetStore(store)
+
+ ctx := context.Background()
+
+ files := []string{
+ "/bucket1/test-prefix1/file1.txt",
+ "/bucket1/test-prefix1/file2.txt",
+ "/bucket1/test-prefix1-extra.txt",
+ }
+
+ expected1 := []string{
+ "/bucket1/test-prefix1",
+ "/bucket1/test-prefix1-extra.txt",
+ }
+
+ expected2 := []string{
+ "/bucket1/test-prefix1/file1.txt",
+ "/bucket1/test-prefix1/file2.txt",
+ }
+
+ for _, file := range files {
+ fullpath := util.FullPath(file)
+ entry := &filer.Entry{
+ FullPath: fullpath,
+ Attr: filer.Attr{
+ Mode: 0644,
+ Uid: 1,
+ Gid: 1,
+ },
+ }
+ if err := testFiler.CreateEntry(ctx, entry, false, false, nil, false, testFiler.MaxFilenameLength); err != nil {
+ t.Fatalf("Failed to create entry %s: %v", fullpath, err)
+ }
+ }
+
+ prefix1 := "test-prefix1"
+ entries1, _, err := testFiler.ListDirectoryEntries(ctx, util.FullPath("/bucket1"), "", false, 100, prefix1, "", "")
+ if err != nil {
+ t.Fatalf("Failed to list entries with prefix %s: %v", prefix1, err)
+ }
+ if len(entries1) != 2 {
+ t.Errorf("Expected 2 entries with prefix %s, got %d", prefix1, len(entries1))
+ } else {
+ t.Logf("Found %d entries with prefix %s", len(entries1), prefix1)
+ }
+ for i, entry := range entries1 {
+ if string(entry.FullPath) != expected1[i] {
+ t.Errorf("Expected entry %s, got %s", expected1[i], entry.FullPath)
+ }
+ }
+
+ entries2, _, err := testFiler.ListDirectoryEntries(ctx, util.FullPath("/bucket1/test-prefix1"), "", false, 100, "", "", "")
+ if err != nil {
+ t.Fatalf("Failed to list entries with prefix %s: %v", prefix1, err)
+ }
+ if len(entries2) != 2 {
+ t.Errorf("Expected 2 entries with prefix %s, got %d", prefix1, len(entries1))
+ }
+ for i, entry := range entries2 {
+ if string(entry.FullPath) != expected2[i] {
+ t.Errorf("Expected entry %s, got %s", expected2[i], entry.FullPath)
+ }
+ }
+}