aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/fscache_test.go
blob: 06ef7c4545e8a8cc349d8ada2cc744f7a9361263 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package filesys

import (
	"testing"

	"github.com/chrislusf/seaweedfs/weed/util"
)

func TestPathSplit(t *testing.T) {
	parts := util.FullPath("/").Split()
	if len(parts) != 0 {
		t.Errorf("expecting an empty list, but getting %d", len(parts))
	}
}

func TestFsCache(t *testing.T) {

	cache := newFsCache(nil)

	x := cache.GetFsNode(util.FullPath("/y/x"))
	if x != nil {
		t.Errorf("wrong node!")
	}

	p := util.FullPath("/a/b/c")
	cache.SetFsNode(p, &File{Name: "cc"})
	tNode := cache.GetFsNode(p)
	tFile := tNode.(*File)
	if tFile.Name != "cc" {
		t.Errorf("expecting a FsNode")
	}

	cache.SetFsNode(util.FullPath("/a/b/d"), &File{Name: "dd"})
	cache.SetFsNode(util.FullPath("/a/b/e"), &File{Name: "ee"})
	cache.SetFsNode(util.FullPath("/a/b/f"), &File{Name: "ff"})
	cache.SetFsNode(util.FullPath("/z"), &File{Name: "zz"})
	cache.SetFsNode(util.FullPath("/a"), &File{Name: "aa"})

	b := cache.GetFsNode(util.FullPath("/a/b"))
	if b != nil {
		t.Errorf("unexpected node!")
	}

	a := cache.GetFsNode(util.FullPath("/a"))
	if a == nil {
		t.Errorf("missing node!")
	}

	cache.DeleteFsNode(util.FullPath("/a"))
	if b != nil {
		t.Errorf("unexpected node!")
	}

	a = cache.GetFsNode(util.FullPath("/a"))
	if a != nil {
		t.Errorf("wrong DeleteFsNode!")
	}

	z := cache.GetFsNode(util.FullPath("/z"))
	if z == nil {
		t.Errorf("missing node!")
	}

	y := cache.GetFsNode(util.FullPath("/x/y"))
	if y != nil {
		t.Errorf("wrong node!")
	}

}

func TestFsCacheMove(t *testing.T) {

	cache := newFsCache(nil)

	cache.SetFsNode(util.FullPath("/a/b/d"), &File{Name: "dd"})
	cache.SetFsNode(util.FullPath("/a/b/e"), &File{Name: "ee"})
	cache.SetFsNode(util.FullPath("/z"), &File{Name: "zz"})
	cache.SetFsNode(util.FullPath("/a"), &File{Name: "aa"})

	cache.Move(util.FullPath("/a/b"), util.FullPath("/z/x"))

	d := cache.GetFsNode(util.FullPath("/z/x/d"))
	if d == nil {
		t.Errorf("unexpected nil node!")
	}
	if d.(*File).Name != "dd" {
		t.Errorf("unexpected non dd node!")
	}

}