github.com/anuvu/zot@v1.3.4/pkg/storage/cache_test.go (about) 1 package storage_test 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path" 7 "testing" 8 9 "github.com/anuvu/zot/errors" 10 "github.com/anuvu/zot/pkg/log" 11 "github.com/anuvu/zot/pkg/storage" 12 . "github.com/smartystreets/goconvey/convey" 13 ) 14 15 func TestCache(t *testing.T) { 16 Convey("Make a new cache", t, func() { 17 dir, err := ioutil.TempDir("", "cache_test") 18 So(err, ShouldBeNil) 19 So(dir, ShouldNotBeEmpty) 20 defer os.RemoveAll(dir) 21 22 log := log.NewLogger("debug", "") 23 So(log, ShouldNotBeNil) 24 25 So(storage.NewCache("/deadBEEF", "cache_test", log), ShouldBeNil) 26 27 c := storage.NewCache(dir, "cache_test", log) 28 So(c, ShouldNotBeNil) 29 30 v, err := c.GetBlob("key") 31 So(err, ShouldEqual, errors.ErrCacheMiss) 32 So(v, ShouldBeEmpty) 33 34 b := c.HasBlob("key", "value") 35 So(b, ShouldBeFalse) 36 37 err = c.PutBlob("key", path.Join(dir, "value")) 38 So(err, ShouldBeNil) 39 40 b = c.HasBlob("key", "value") 41 So(b, ShouldBeTrue) 42 43 v, err = c.GetBlob("key") 44 So(err, ShouldBeNil) 45 So(v, ShouldNotBeEmpty) 46 47 err = c.DeleteBlob("bogusKey", "bogusValue") 48 So(err, ShouldEqual, errors.ErrCacheMiss) 49 50 err = c.DeleteBlob("key", "bogusValue") 51 So(err, ShouldBeNil) 52 53 // try to insert empty path 54 err = c.PutBlob("key", "") 55 So(err, ShouldNotBeNil) 56 So(err, ShouldEqual, errors.ErrEmptyValue) 57 }) 58 }