2018-05-13 04:45:29 +08:00
|
|
|
package memdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
2018-05-28 02:52:26 +08:00
|
|
|
"testing"
|
2018-05-13 04:45:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateAndFind(t *testing.T) {
|
2018-06-01 15:39:39 +08:00
|
|
|
filer := filer2.NewFiler(nil)
|
2018-05-26 18:49:46 +08:00
|
|
|
store := &MemDbStore{}
|
|
|
|
store.Initialize(nil)
|
|
|
|
filer.SetStore(store)
|
2018-05-13 04:45:29 +08:00
|
|
|
filer.DisableDirectoryCache()
|
|
|
|
|
|
|
|
fullpath := filer2.FullPath("/home/chris/this/is/one/file1.jpg")
|
|
|
|
|
|
|
|
entry1 := &filer2.Entry{
|
|
|
|
FullPath: fullpath,
|
|
|
|
Attr: filer2.Attr{
|
|
|
|
Mode: 0440,
|
|
|
|
Uid: 1234,
|
|
|
|
Gid: 5678,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := filer.CreateEntry(entry1); err != nil {
|
|
|
|
t.Errorf("create entry %v: %v", entry1.FullPath, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-26 19:13:50 +08:00
|
|
|
entry, err := filer.FindEntry(fullpath)
|
2018-05-13 04:45:29 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("find entry: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry.FullPath != entry1.FullPath {
|
|
|
|
t.Errorf("find wrong entry: %v", entry.FullPath)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateFileAndList(t *testing.T) {
|
2018-06-01 15:39:39 +08:00
|
|
|
filer := filer2.NewFiler(nil)
|
2018-05-26 18:49:46 +08:00
|
|
|
store := &MemDbStore{}
|
|
|
|
store.Initialize(nil)
|
|
|
|
filer.SetStore(store)
|
2018-05-13 04:45:29 +08:00
|
|
|
filer.DisableDirectoryCache()
|
|
|
|
|
|
|
|
entry1 := &filer2.Entry{
|
|
|
|
FullPath: filer2.FullPath("/home/chris/this/is/one/file1.jpg"),
|
|
|
|
Attr: filer2.Attr{
|
|
|
|
Mode: 0440,
|
|
|
|
Uid: 1234,
|
|
|
|
Gid: 5678,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
entry2 := &filer2.Entry{
|
|
|
|
FullPath: filer2.FullPath("/home/chris/this/is/one/file2.jpg"),
|
|
|
|
Attr: filer2.Attr{
|
|
|
|
Mode: 0440,
|
|
|
|
Uid: 1234,
|
|
|
|
Gid: 5678,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
filer.CreateEntry(entry1)
|
|
|
|
filer.CreateEntry(entry2)
|
|
|
|
|
2018-05-13 04:50:11 +08:00
|
|
|
// checking the 2 files
|
2018-05-14 05:02:29 +08:00
|
|
|
entries, err := filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is/one/"), "", false, 100)
|
2018-05-13 04:45:29 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("list entries: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(entries) != 2 {
|
|
|
|
t.Errorf("list entries count: %v", len(entries))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if entries[0].FullPath != entry1.FullPath {
|
|
|
|
t.Errorf("find wrong entry 1: %v", entries[0].FullPath)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if entries[1].FullPath != entry2.FullPath {
|
|
|
|
t.Errorf("find wrong entry 2: %v", entries[1].FullPath)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-14 05:02:29 +08:00
|
|
|
// checking the offset
|
|
|
|
entries, err = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is/one/"), "file1.jpg", false, 100)
|
|
|
|
if len(entries) != 1 {
|
|
|
|
t.Errorf("list entries count: %v", len(entries))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-13 04:50:11 +08:00
|
|
|
// checking one upper directory
|
2018-05-14 05:02:29 +08:00
|
|
|
entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"), "", false, 100)
|
2018-05-13 04:50:11 +08:00
|
|
|
if len(entries) != 1 {
|
|
|
|
t.Errorf("list entries count: %v", len(entries))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-14 14:56:16 +08:00
|
|
|
// checking root directory
|
|
|
|
entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/"), "", false, 100)
|
|
|
|
if len(entries) != 1 {
|
|
|
|
t.Errorf("list entries count: %v", len(entries))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// add file3
|
2018-05-13 13:42:28 +08:00
|
|
|
file3Path := filer2.FullPath("/home/chris/this/is/file3.jpg")
|
2018-05-13 04:50:11 +08:00
|
|
|
entry3 := &filer2.Entry{
|
2018-05-13 13:42:28 +08:00
|
|
|
FullPath: file3Path,
|
2018-05-13 04:50:11 +08:00
|
|
|
Attr: filer2.Attr{
|
|
|
|
Mode: 0440,
|
|
|
|
Uid: 1234,
|
|
|
|
Gid: 5678,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
filer.CreateEntry(entry3)
|
|
|
|
|
|
|
|
// checking one upper directory
|
2018-05-14 05:02:29 +08:00
|
|
|
entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"), "", false, 100)
|
2018-05-13 04:50:11 +08:00
|
|
|
if len(entries) != 2 {
|
|
|
|
t.Errorf("list entries count: %v", len(entries))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-13 13:42:28 +08:00
|
|
|
// delete file and count
|
2018-05-31 11:24:57 +08:00
|
|
|
filer.DeleteEntryMetaAndData(file3Path)
|
2018-05-14 05:02:29 +08:00
|
|
|
entries, _ = filer.ListDirectoryEntries(filer2.FullPath("/home/chris/this/is"), "", false, 100)
|
2018-05-13 13:42:28 +08:00
|
|
|
if len(entries) != 1 {
|
|
|
|
t.Errorf("list entries count: %v", len(entries))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-13 04:45:29 +08:00
|
|
|
}
|