-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
dir.go
54 lines (48 loc) · 1.31 KB
/
dir.go
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
package storetest
import (
"reflect"
"testing"
"src.elv.sh/pkg/store"
"src.elv.sh/pkg/store/storedefs"
)
var (
dirsToAdd = []string{"/usr/local", "/usr", "/usr/bin", "/usr"}
black = map[string]struct{}{"/usr/local": {}}
wantedDirs = []storedefs.Dir{
{
Path: "/usr",
Score: store.DirScoreIncrement*store.DirScoreDecay*store.DirScoreDecay + store.DirScoreIncrement,
},
{
Path: "/usr/bin",
Score: store.DirScoreIncrement * store.DirScoreDecay,
},
}
dirToDel = "/usr"
wantedDirsAfterDel = []storedefs.Dir{
{
Path: "/usr/bin",
Score: store.DirScoreIncrement * store.DirScoreDecay,
},
}
)
// TestDir tests the directory history functionality of a Store.
func TestDir(t *testing.T, tStore storedefs.Store) {
for _, path := range dirsToAdd {
err := tStore.AddDir(path, 1)
if err != nil {
t.Errorf("tStore.AddDir(%q) => %v, want <nil>", path, err)
}
}
dirs, err := tStore.Dirs(black)
if err != nil || !reflect.DeepEqual(dirs, wantedDirs) {
t.Errorf(`tStore.ListDirs() => (%v, %v), want (%v, <nil>)`,
dirs, err, wantedDirs)
}
tStore.DelDir(dirToDel)
dirs, err = tStore.Dirs(black)
if err != nil || !reflect.DeepEqual(dirs, wantedDirsAfterDel) {
t.Errorf(`After DelDir("/usr"), tStore.ListDirs() => (%v, %v), want (%v, <nil>)`,
dirs, err, wantedDirsAfterDel)
}
}