mirror of
https://github.com/project-zot/zot.git
synced 2025-01-06 22:40:28 -05:00
25f5a45296
As the number of repos and layers increases, the greater the probability that layers are duplicated. We dedupe using hard links when content is the same. This is intended to be purely a storage layer optimization. Access control when available is orthogonal this optimization. Add a durable cache to help speed up layer lookups. Update README. Add more unit tests.
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package storage_test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"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)
|
|
|
|
err = c.PutBlob("key", "value")
|
|
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)
|
|
})
|
|
}
|