mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 12:58:02 +08:00
9cc990d7ca
Initial code was contributed by Bogdan BIVOLARU <104334+bogdanbiv@users.noreply.github.com> Moved implementation from a separate db to repodb by Andrei Aaron <aaaron@luxoft.com> Not done yet: - run/test dynamodb implementation, only boltdb was tested - add additional coverage for existing functionality - add web-based APIs to toggle the stars/bookmarks on/off Initially graphql mutation was discussed for the missing API but we decided REST endpoints would be better suited for configuration feat(userdb): complete functionality for userdb integration - dynamodb rollback changes to user starred repos in case increasing the total star count fails - dynamodb increment/decrement repostars in repometa when user stars/unstars a repo - dynamodb check anonymous user permissions are working as intendend - common test handle anonymous users - RepoMeta2RepoSummary set IsStarred and IsBookmarked feat(userdb): rest api calls for toggling stars/bookmarks on/off test(userdb): blackbox tests test(userdb): move preferences tests in a different file with specific build tags feat(repodb): add is-starred and is-bookmarked fields to repo-meta - removed duplicated logic for determining if a repo is starred/bookmarked Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com> Co-authored-by: Andrei Aaron <aaaron@luxoft.com>
84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
package repodbfactory_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
|
"zotregistry.io/zot/pkg/meta/bolt"
|
|
"zotregistry.io/zot/pkg/meta/dynamo"
|
|
"zotregistry.io/zot/pkg/meta/repodb/repodbfactory"
|
|
)
|
|
|
|
func TestCreateDynamo(t *testing.T) {
|
|
skipDynamo(t)
|
|
|
|
Convey("Create", t, func() {
|
|
dynamoDBDriverParams := dynamo.DBDriverParameters{
|
|
Endpoint: os.Getenv("DYNAMODBMOCK_ENDPOINT"),
|
|
RepoMetaTablename: "RepoMetadataTable",
|
|
ManifestDataTablename: "ManifestDataTable",
|
|
IndexDataTablename: "IndexDataTable",
|
|
ArtifactDataTablename: "ArtifactDataTable",
|
|
UserDataTablename: "UserDataTable",
|
|
VersionTablename: "Version",
|
|
Region: "us-east-2",
|
|
}
|
|
|
|
client, err := dynamo.GetDynamoClient(dynamoDBDriverParams)
|
|
So(err, ShouldBeNil)
|
|
|
|
log := log.NewLogger("debug", "")
|
|
|
|
repoDB, err := repodbfactory.Create("dynamodb", client, dynamoDBDriverParams, log)
|
|
So(repoDB, ShouldNotBeNil)
|
|
So(err, ShouldBeNil)
|
|
})
|
|
|
|
Convey("Fails", t, func() {
|
|
log := log.NewLogger("debug", "")
|
|
|
|
So(func() { _, _ = repodbfactory.Create("dynamodb", nil, bolt.DBParameters{RootDir: "root"}, log) }, ShouldPanic)
|
|
|
|
So(func() { _, _ = repodbfactory.Create("dynamodb", &dynamodb.Client{}, "bad", log) }, ShouldPanic)
|
|
|
|
repoDB, err := repodbfactory.Create("random", nil, bolt.DBParameters{RootDir: "root"}, log)
|
|
So(repoDB, ShouldBeNil)
|
|
So(err, ShouldNotBeNil)
|
|
})
|
|
}
|
|
|
|
func TestCreateBoltDB(t *testing.T) {
|
|
Convey("Create", t, func() {
|
|
rootDir := t.TempDir()
|
|
params := bolt.DBParameters{
|
|
RootDir: rootDir,
|
|
}
|
|
boltDriver, err := bolt.GetBoltDriver(params)
|
|
So(err, ShouldBeNil)
|
|
|
|
log := log.NewLogger("debug", "")
|
|
|
|
repoDB, err := repodbfactory.Create("boltdb", boltDriver, params, log)
|
|
So(repoDB, ShouldNotBeNil)
|
|
So(err, ShouldBeNil)
|
|
})
|
|
|
|
Convey("fails", t, func() {
|
|
log := log.NewLogger("debug", "")
|
|
|
|
So(func() { _, _ = repodbfactory.Create("boltdb", nil, dynamo.DBDriverParameters{}, log) }, ShouldPanic)
|
|
})
|
|
}
|
|
|
|
func skipDynamo(t *testing.T) {
|
|
t.Helper()
|
|
|
|
if os.Getenv("DYNAMODBMOCK_ENDPOINT") == "" {
|
|
t.Skip("Skipping testing without AWS DynamoDB mock server")
|
|
}
|
|
}
|