4 "github.com/Kovensky/go-fscache"
11 rand.Seed(time.Now().UnixNano())
14 func TestCache_Stat(T *testing.T) {
15 cd, err := fscache.NewCacheDir(".testdir")
21 err = cd.Touch("test", "stat")
27 stat, err := cd.Stat("test", "stat")
33 T.Log("IsDir:", stat.IsDir())
34 T.Log("ModTime:", stat.ModTime())
35 T.Log("Name: " + stat.Name())
36 T.Log("Size:", stat.Size(), "bytes")
38 if stat.IsDir() || stat.ModTime().IsZero() || stat.Name() != "stat" || stat.Size() != 0 {
39 T.Error("Stat returned unexpected data")
43 func TestCache_Touch(T *testing.T) {
44 cd, err := fscache.NewCacheDir(".testdir")
50 err = cd.Touch("test", "touch", "file")
56 stat, err := cd.Stat("test", "touch")
63 T.Error("Expected touch to be a dir, file found")
66 // can be anything -- just make a nonblank file
67 size, err := cd.Set(stat.ModTime(), "test", "touch", "subdir", "file")
73 stat, err = cd.Stat("test", "touch", "subdir", "file")
78 if stat.Size() != size {
79 panic("File modified outside of test")
83 time.Sleep(5 * time.Millisecond)
85 err = cd.Touch("test", "touch", "subdir", "file")
89 stat2, err := cd.Stat("test", "touch", "subdir", "file")
91 if stat.Size() != stat2.Size() {
92 T.Errorf("Touch modified the size")
94 if !stat2.ModTime().After(stat.ModTime()) {
95 T.Errorf("Touch did not update timestamp (FAT filesystem?)")
99 func TestCache_Chtime(T *testing.T) {
100 cd, err := fscache.NewCacheDir(".testdir")
106 err = cd.Touch("test", "chtime")
112 stat, err := cd.Stat("test", "chtime")
118 newTime := stat.ModTime().Add(-1 * 7 * 24 * time.Hour)
120 err = cd.Chtime(newTime, "test", "chtime")
126 stat, err = cd.Stat("test", "chtime")
132 if mtime := stat.ModTime(); !mtime.Equal(newTime) {
133 T.Errorf("Expected mtime %q, got mtime %q", newTime, mtime)