2020-02-17 16:57:15 -05:00
|
|
|
package storage_test
|
|
|
|
|
|
|
|
import (
|
2020-05-27 16:27:35 -05:00
|
|
|
"path"
|
2020-02-17 16:57:15 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2021-12-03 22:50:58 -05:00
|
|
|
"zotregistry.io/zot/errors"
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
|
|
|
"zotregistry.io/zot/pkg/storage"
|
2020-02-17 16:57:15 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCache(t *testing.T) {
|
|
|
|
Convey("Make a new cache", t, func() {
|
2022-03-07 03:55:12 -05:00
|
|
|
dir := t.TempDir()
|
2020-02-17 16:57:15 -05:00
|
|
|
|
|
|
|
log := log.NewLogger("debug", "")
|
|
|
|
So(log, ShouldNotBeNil)
|
|
|
|
|
2022-04-12 05:01:04 -05:00
|
|
|
So(storage.NewCache("/deadBEEF", "cache_test", true, log), ShouldBeNil)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2022-04-12 05:01:04 -05:00
|
|
|
cache := storage.NewCache(dir, "cache_test", true, log)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(cache, ShouldNotBeNil)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
val, err := cache.GetBlob("key")
|
2020-02-17 16:57:15 -05:00
|
|
|
So(err, ShouldEqual, errors.ErrCacheMiss)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(val, ShouldBeEmpty)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
exists := cache.HasBlob("key", "value")
|
|
|
|
So(exists, ShouldBeFalse)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = cache.PutBlob("key", path.Join(dir, "value"))
|
2020-02-17 16:57:15 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-07 13:26:26 -05:00
|
|
|
err = cache.PutBlob("key", "value")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
exists = cache.HasBlob("key", "value")
|
|
|
|
So(exists, ShouldBeTrue)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
val, err = cache.GetBlob("key")
|
2020-02-17 16:57:15 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(val, ShouldNotBeEmpty)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = cache.DeleteBlob("bogusKey", "bogusValue")
|
2020-02-17 16:57:15 -05:00
|
|
|
So(err, ShouldEqual, errors.ErrCacheMiss)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = cache.DeleteBlob("key", "bogusValue")
|
2020-02-17 16:57:15 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-07-20 16:04:10 -05:00
|
|
|
|
|
|
|
// try to insert empty path
|
2021-12-13 14:23:31 -05:00
|
|
|
err = cache.PutBlob("key", "")
|
2021-07-20 16:04:10 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
So(err, ShouldEqual, errors.ErrEmptyValue)
|
2020-02-17 16:57:15 -05:00
|
|
|
})
|
|
|
|
}
|