1package storetest 2 3import ( 4 "reflect" 5 "testing" 6 7 "src.elv.sh/pkg/store" 8 "src.elv.sh/pkg/store/storedefs" 9) 10 11var ( 12 dirsToAdd = []string{"/usr/local", "/usr", "/usr/bin", "/usr"} 13 black = map[string]struct{}{"/usr/local": {}} 14 wantedDirs = []storedefs.Dir{ 15 { 16 Path: "/usr", 17 Score: store.DirScoreIncrement*store.DirScoreDecay*store.DirScoreDecay + store.DirScoreIncrement, 18 }, 19 { 20 Path: "/usr/bin", 21 Score: store.DirScoreIncrement * store.DirScoreDecay, 22 }, 23 } 24 dirToDel = "/usr" 25 wantedDirsAfterDel = []storedefs.Dir{ 26 { 27 Path: "/usr/bin", 28 Score: store.DirScoreIncrement * store.DirScoreDecay, 29 }, 30 } 31) 32 33// TestDir tests the directory history functionality of a Store. 34func TestDir(t *testing.T, tStore storedefs.Store) { 35 for _, path := range dirsToAdd { 36 err := tStore.AddDir(path, 1) 37 if err != nil { 38 t.Errorf("tStore.AddDir(%q) => %v, want <nil>", path, err) 39 } 40 } 41 42 dirs, err := tStore.Dirs(black) 43 if err != nil || !reflect.DeepEqual(dirs, wantedDirs) { 44 t.Errorf(`tStore.ListDirs() => (%v, %v), want (%v, <nil>)`, 45 dirs, err, wantedDirs) 46 } 47 48 tStore.DelDir(dirToDel) 49 dirs, err = tStore.Dirs(black) 50 if err != nil || !reflect.DeepEqual(dirs, wantedDirsAfterDel) { 51 t.Errorf(`After DelDir("/usr"), tStore.ListDirs() => (%v, %v), want (%v, <nil>)`, 52 dirs, err, wantedDirsAfterDel) 53 } 54} 55