11 type stringifyVec struct {
16 func TestStringify(T *testing.T) {
19 vec := []stringifyVec{
20 stringifyVec{[]string{"a"}, []cacheKey{"a"}},
22 for i, v := range vec {
23 str := stringify(v.data...)
24 if !reflect.DeepEqual(v.result, str) {
25 T.Errorf("Vector #%d: Expected %v, got %v", i+1, v.result, str)
30 type cachePathVec struct {
35 var testDir = path.Join(os.TempDir(), "testing", "anidb")
37 func init() { SetCacheDir(testDir) }
39 func TestCachePath(T *testing.T) {
42 vec := []cachePathVec{
43 cachePathVec{path.Join(testDir, "a"), []cacheKey{"a"}},
44 cachePathVec{path.Join(testDir, "b", "c", "d"), []cacheKey{"b", "c", "d"}},
46 for i, v := range vec {
47 str := cachePath(v.data...)
50 T.Errorf("Vector #%d: Expected %v, got %v", i+1, v.path, str)
55 type testString string
57 func (_ testString) Touch() {}
58 func (_ testString) IsStale() bool { return false }
61 gob.Register(testString(""))
64 func TestCacheRoundtrip(T *testing.T) {
67 test := testString("some string")
68 _, err := cache.Set(test, "test", "string")
70 T.Fatalf("Error storing: %v", err)
74 err = cache.Get(&t2, "test", "string")
76 T.Errorf("Error reading: %v", err)
80 T.Errorf("Expected %q, got %q", test, t2)