2020-02-17 16:57:15 -05:00
|
|
|
package storage_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2020-05-27 16:27:35 -05:00
|
|
|
"path"
|
2020-02-17 16:57:15 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/anuvu/zot/errors"
|
|
|
|
"github.com/anuvu/zot/pkg/log"
|
|
|
|
"github.com/anuvu/zot/pkg/storage"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCache(t *testing.T) {
|
|
|
|
Convey("Make a new cache", t, func() {
|
|
|
|
dir, err := ioutil.TempDir("", "cache_test")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(dir, ShouldNotBeEmpty)
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
log := log.NewLogger("debug", "")
|
|
|
|
So(log, ShouldNotBeNil)
|
|
|
|
|
|
|
|
So(storage.NewCache("/deadBEEF", "cache_test", log), ShouldBeNil)
|
|
|
|
|
|
|
|
c := storage.NewCache(dir, "cache_test", log)
|
|
|
|
So(c, ShouldNotBeNil)
|
|
|
|
|
|
|
|
v, err := c.GetBlob("key")
|
|
|
|
So(err, ShouldEqual, errors.ErrCacheMiss)
|
|
|
|
So(v, ShouldBeEmpty)
|
|
|
|
|
|
|
|
b := c.HasBlob("key", "value")
|
|
|
|
So(b, ShouldBeFalse)
|
|
|
|
|
2020-05-27 16:27:35 -05:00
|
|
|
err = c.PutBlob("key", path.Join(dir, "value"))
|
2020-02-17 16:57:15 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
b = c.HasBlob("key", "value")
|
|
|
|
So(b, ShouldBeTrue)
|
|
|
|
|
|
|
|
v, err = c.GetBlob("key")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(v, ShouldNotBeEmpty)
|
|
|
|
|
|
|
|
err = c.DeleteBlob("bogusKey", "bogusValue")
|
|
|
|
So(err, ShouldEqual, errors.ErrCacheMiss)
|
|
|
|
|
|
|
|
err = c.DeleteBlob("key", "bogusValue")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
})
|
|
|
|
}
|