mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
refactor(repodb): moving common utilities under pkg/meta (#1292)
* refactor(repodb): moving common utilities under pkg/meta Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com> * refactor(repodb): moved update, version components under pkg/meta - updated wrapper initialization to recieve a log object in constructor Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com> * refactor(repodb): moved repodb initialization from controller to pkg/meta/repodb Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com> --------- Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
@@ -20,8 +20,9 @@ import (
|
||||
"zotregistry.io/zot/pkg/extensions/search/convert"
|
||||
cveinfo "zotregistry.io/zot/pkg/extensions/search/cve"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/meta/bolt"
|
||||
"zotregistry.io/zot/pkg/meta/repodb"
|
||||
bolt "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
boltdb_wrapper "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
. "zotregistry.io/zot/pkg/test"
|
||||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
)
|
||||
@@ -30,9 +31,13 @@ var ErrTestError = errors.New("TestError")
|
||||
|
||||
func TestConvertErrors(t *testing.T) {
|
||||
Convey("Convert Errors", t, func() {
|
||||
repoDB, err := bolt.NewBoltDBWrapper(bolt.DBParameters{
|
||||
params := bolt.DBParameters{
|
||||
RootDir: t.TempDir(),
|
||||
})
|
||||
}
|
||||
boltDB, err := bolt.GetBoltDriver(params)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoDB, err := boltdb_wrapper.NewBoltDBWrapper(boltDB, log.NewLogger("debug", ""))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
configBlob, err := json.Marshal(ispec.Image{})
|
||||
|
||||
@@ -29,8 +29,9 @@ import (
|
||||
cveinfo "zotregistry.io/zot/pkg/extensions/search/cve"
|
||||
cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/meta/bolt"
|
||||
"zotregistry.io/zot/pkg/meta/repodb"
|
||||
bolt "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
boltdb_wrapper "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/storage/local"
|
||||
. "zotregistry.io/zot/pkg/test"
|
||||
@@ -312,9 +313,13 @@ func TestImageFormat(t *testing.T) {
|
||||
false, false, log, metrics, nil, nil)
|
||||
storeController := storage.StoreController{DefaultStore: defaultStore}
|
||||
|
||||
repoDB, err := bolt.NewBoltDBWrapper(bolt.DBParameters{
|
||||
params := bolt.DBParameters{
|
||||
RootDir: dbDir,
|
||||
})
|
||||
}
|
||||
boltDriver, err := bolt.GetBoltDriver(params)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoDB, err := boltdb_wrapper.NewBoltDBWrapper(boltDriver, log)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = repodb.ParseStorage(repoDB, storeController, log)
|
||||
@@ -716,9 +721,13 @@ func TestCVESearch(t *testing.T) {
|
||||
|
||||
func TestCVEStruct(t *testing.T) {
|
||||
Convey("Unit test the CVE struct", t, func() {
|
||||
repoDB, err := bolt.NewBoltDBWrapper(bolt.DBParameters{
|
||||
params := bolt.DBParameters{
|
||||
RootDir: t.TempDir(),
|
||||
})
|
||||
}
|
||||
boltDriver, err := bolt.GetBoltDriver(params)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoDB, err := boltdb_wrapper.NewBoltDBWrapper(boltDriver, log.NewLogger("debug", ""))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Create repodb data for scannable image with vulnerabilities
|
||||
|
||||
@@ -17,16 +17,21 @@ import (
|
||||
cveinfo "zotregistry.io/zot/pkg/extensions/search/cve"
|
||||
cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/meta/bolt"
|
||||
"zotregistry.io/zot/pkg/meta/repodb"
|
||||
bolt "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
boltdb_wrapper "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
)
|
||||
|
||||
func TestCVEPagination(t *testing.T) {
|
||||
Convey("CVE Pagination", t, func() {
|
||||
repoDB, err := bolt.NewBoltDBWrapper(bolt.DBParameters{
|
||||
params := bolt.DBParameters{
|
||||
RootDir: t.TempDir(),
|
||||
})
|
||||
}
|
||||
boltDriver, err := bolt.GetBoltDriver(params)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoDB, err := boltdb_wrapper.NewBoltDBWrapper(boltDriver, log.NewLogger("debug", ""))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Create repodb data for scannable image with vulnerabilities
|
||||
|
||||
@@ -18,8 +18,9 @@ import (
|
||||
"zotregistry.io/zot/pkg/extensions/monitoring"
|
||||
"zotregistry.io/zot/pkg/extensions/search/common"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/meta/bolt"
|
||||
"zotregistry.io/zot/pkg/meta/repodb"
|
||||
bolt "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
boltdb_wrapper "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/storage/local"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
@@ -83,9 +84,13 @@ func TestMultipleStoragePath(t *testing.T) {
|
||||
|
||||
storeController.SubStore = subStore
|
||||
|
||||
repoDB, err := bolt.NewBoltDBWrapper(bolt.DBParameters{
|
||||
params := bolt.DBParameters{
|
||||
RootDir: firstRootDir,
|
||||
})
|
||||
}
|
||||
boltDriver, err := bolt.GetBoltDriver(params)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoDB, err := boltdb_wrapper.NewBoltDBWrapper(boltDriver, log)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = repodb.ParseStorage(repoDB, storeController, log)
|
||||
@@ -173,9 +178,14 @@ func TestTrivyLibraryErrors(t *testing.T) {
|
||||
storeController := storage.StoreController{}
|
||||
storeController.DefaultStore = store
|
||||
|
||||
repoDB, err := bolt.NewBoltDBWrapper(bolt.DBParameters{
|
||||
params := bolt.DBParameters{
|
||||
RootDir: rootDir,
|
||||
})
|
||||
}
|
||||
|
||||
boltDriver, err := bolt.GetBoltDriver(params)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoDB, err := boltdb_wrapper.NewBoltDBWrapper(boltDriver, log)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = repodb.ParseStorage(repoDB, storeController, log)
|
||||
@@ -217,9 +227,18 @@ func TestTrivyLibraryErrors(t *testing.T) {
|
||||
func TestImageScannable(t *testing.T) {
|
||||
rootDir := t.TempDir()
|
||||
|
||||
repoDB, err := bolt.NewBoltDBWrapper(bolt.DBParameters{
|
||||
params := bolt.DBParameters{
|
||||
RootDir: rootDir,
|
||||
})
|
||||
}
|
||||
|
||||
boltDriver, err := bolt.GetBoltDriver(params)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log := log.NewLogger("debug", "")
|
||||
|
||||
repoDB, err := boltdb_wrapper.NewBoltDBWrapper(boltDriver, log)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -349,7 +368,6 @@ func TestImageScannable(t *testing.T) {
|
||||
}
|
||||
|
||||
// Continue with initializing the objects the scanner depends on
|
||||
log := log.NewLogger("debug", "")
|
||||
metrics := monitoring.NewMetricsServer(false, log)
|
||||
|
||||
store := local.NewImageStore(rootDir, false, storage.DefaultGCDelay, false, false, log, metrics, nil, nil)
|
||||
@@ -419,9 +437,14 @@ func TestDefaultTrivyDBUrl(t *testing.T) {
|
||||
storeController := storage.StoreController{}
|
||||
storeController.DefaultStore = store
|
||||
|
||||
repoDB, err := bolt.NewBoltDBWrapper(bolt.DBParameters{
|
||||
params := bolt.DBParameters{
|
||||
RootDir: rootDir,
|
||||
})
|
||||
}
|
||||
|
||||
boltDriver, err := bolt.GetBoltDriver(params)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoDB, err := boltdb_wrapper.NewBoltDBWrapper(boltDriver, log)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = repodb.ParseStorage(repoDB, storeController, log)
|
||||
|
||||
@@ -20,8 +20,9 @@ import (
|
||||
cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model"
|
||||
"zotregistry.io/zot/pkg/extensions/search/gql_generated"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/meta/bolt"
|
||||
"zotregistry.io/zot/pkg/meta/repodb"
|
||||
bolt "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
boltdb_wrapper "zotregistry.io/zot/pkg/meta/repodb/boltdb-wrapper"
|
||||
localCtx "zotregistry.io/zot/pkg/requestcontext"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
@@ -1892,9 +1893,18 @@ func TestQueryResolverErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCVEResolvers(t *testing.T) { //nolint:gocyclo
|
||||
repoDB, err := bolt.NewBoltDBWrapper(bolt.DBParameters{
|
||||
params := bolt.DBParameters{
|
||||
RootDir: t.TempDir(),
|
||||
})
|
||||
}
|
||||
|
||||
boltDriver, err := bolt.GetBoltDriver(params)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log := log.NewLogger("debug", "")
|
||||
|
||||
repoDB, err := boltdb_wrapper.NewBoltDBWrapper(boltDriver, log)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -2125,8 +2135,6 @@ func TestCVEResolvers(t *testing.T) { //nolint:gocyclo
|
||||
},
|
||||
}
|
||||
|
||||
log := log.NewLogger("debug", "")
|
||||
|
||||
cveInfo := &cveinfo.BaseCveInfo{
|
||||
Log: log,
|
||||
Scanner: scanner,
|
||||
|
||||
Reference in New Issue
Block a user