Skip to content

Commit

Permalink
fix: running tests locally fails
Browse files Browse the repository at this point in the history
Signed-off-by: Alexei Dodon <[email protected]>
  • Loading branch information
adodon2go committed Oct 3, 2023
1 parent ca1c328 commit 092890e
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 128 deletions.
35 changes: 11 additions & 24 deletions pkg/api/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import (
"zotregistry.io/zot/pkg/test/mocks"
ociutils "zotregistry.io/zot/pkg/test/oci-utils"
"zotregistry.io/zot/pkg/test/signature"
tskip "zotregistry.io/zot/pkg/test/skip"
)

const (
Expand Down Expand Up @@ -98,22 +99,6 @@ func getCredString(username, password string) string {
return usernameAndHash
}

func skipIt(t *testing.T) {
t.Helper()

if os.Getenv("S3MOCK_ENDPOINT") == "" {
t.Skip("Skipping testing without AWS S3 mock server")
}
}

func skipDynamo(t *testing.T) {
t.Helper()

if os.Getenv("DYNAMODBMOCK_ENDPOINT") == "" {
t.Skip("Skipping testing without AWS DynamoDB mock server")
}
}

func TestNew(t *testing.T) {
Convey("Make a new controller", t, func() {
conf := config.New()
Expand Down Expand Up @@ -147,8 +132,8 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
driver = storage.CreateCacheDatabaseDriver(conf.Storage.StorageConfig, log)
So(driver, ShouldBeNil)
})
skipDynamo(t)
skipIt(t)
tskip.SkipDynamo(t)
tskip.SkipS3(t)
Convey("Test CreateCacheDatabaseDriver dynamodb", t, func() {
log := log.NewLogger("debug", "")
dir := t.TempDir()
Expand All @@ -166,9 +151,10 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
"skipverify": false,
}

endpoint := os.Getenv("DYNAMODBMOCK_ENDPOINT")
conf.Storage.CacheDriver = map[string]interface{}{
"name": "dynamodb",
"endpoint": "http://localhost:4566",
"endpoint": endpoint,
"region": "us-east-2",
"cacheTablename": "BlobTable",
"repoMetaTablename": "RepoMetadataTable",
Expand All @@ -183,7 +169,7 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {
// negative test cases

conf.Storage.CacheDriver = map[string]interface{}{
"endpoint": "http://localhost:4566",
"endpoint": endpoint,
"region": "us-east-2",
"cacheTablename": "BlobTable",
"repoMetaTablename": "RepoMetadataTable",
Expand All @@ -197,7 +183,7 @@ func TestCreateCacheDatabaseDriver(t *testing.T) {

conf.Storage.CacheDriver = map[string]interface{}{
"name": "dummy",
"endpoint": "http://localhost:4566",
"endpoint": endpoint,
"region": "us-east-2",
"cacheTablename": "BlobTable",
"repoMetaTablename": "RepoMetadataTable",
Expand Down Expand Up @@ -371,7 +357,8 @@ func TestAutoPortSelection(t *testing.T) {
}

func TestObjectStorageController(t *testing.T) {
skipIt(t)
tskip.SkipS3(t)
tskip.SkipDynamo(t)

bucket := "zot-storage-test"

Expand Down Expand Up @@ -438,7 +425,7 @@ func TestObjectStorageController(t *testing.T) {

conf.Storage.CacheDriver = map[string]interface{}{
"name": "dynamodb",
"endpoint": "http://localhost:4566",
"endpoint": os.Getenv("DYNAMODBMOCK_ENDPOINT"),
"region": "us-east-2",
"cachetablename": "test",
"repometatablename": "RepoMetadataTable",
Expand Down Expand Up @@ -493,7 +480,7 @@ func TestObjectStorageController(t *testing.T) {
}

func TestObjectStorageControllerSubPaths(t *testing.T) {
skipIt(t)
tskip.SkipS3(t)

bucket := "zot-storage-test"

Expand Down
11 changes: 2 additions & 9 deletions pkg/extensions/extension_image_trust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
test "zotregistry.io/zot/pkg/test/common"
. "zotregistry.io/zot/pkg/test/image-utils"
"zotregistry.io/zot/pkg/test/signature"
tskip "zotregistry.io/zot/pkg/test/skip"
)

type errReader int
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestSignatureUploadAndVerificationLocal(t *testing.T) {
}

func TestSignatureUploadAndVerificationAWS(t *testing.T) {
skipIt(t)
tskip.SkipDynamo(t)

Convey("test with AWS", t, func() {
uuid, err := guuid.NewV4()
Expand Down Expand Up @@ -1000,11 +1001,3 @@ func RunSignatureUploadAndVerificationTests(t *testing.T, cacheDriverParams map[
So(resp.StatusCode(), ShouldEqual, http.StatusInternalServerError)
})
}

func skipIt(t *testing.T) {
t.Helper()

if os.Getenv("DYNAMODBMOCK_ENDPOINT") == "" {
t.Skip("Skipping testing without AWS mock server")
}
}
11 changes: 2 additions & 9 deletions pkg/extensions/imagetrust/image_trust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
. "zotregistry.io/zot/pkg/test/image-utils"
"zotregistry.io/zot/pkg/test/mocks"
"zotregistry.io/zot/pkg/test/signature"
tskip "zotregistry.io/zot/pkg/test/skip"
)

var (
Expand Down Expand Up @@ -658,7 +659,7 @@ func TestLocalTrustStore(t *testing.T) {
}

func TestAWSTrustStore(t *testing.T) {
skipIt(t)
tskip.SkipDynamo(t)

trustpolicy := "trustpolicy"

Expand Down Expand Up @@ -1336,11 +1337,3 @@ func RunVerificationTests(t *testing.T, dbDriverParams map[string]interface{}) {
})
})
}

func skipIt(t *testing.T) {
t.Helper()

if os.Getenv("DYNAMODBMOCK_ENDPOINT") == "" {
t.Skip("Skipping testing without AWS mock server")
}
}
14 changes: 10 additions & 4 deletions pkg/meta/dynamodb/dynamodb_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dynamodb
import (
"context"
"os"
"strings"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
Expand All @@ -14,13 +15,18 @@ import (

"zotregistry.io/zot/pkg/log" //nolint:go-staticcheck
"zotregistry.io/zot/pkg/meta/version"
tskip "zotregistry.io/zot/pkg/test/skip"
)

func TestWrapperErrors(t *testing.T) {
const (
endpoint = "http://localhost:4566"
region = "us-east-2"
)
tskip.SkipS3(t)

const region = "us-east-2"
endpoint := os.Getenv("S3MOCK_ENDPOINT")

if !strings.HasPrefix(endpoint, "http://") {
endpoint = "http://" + endpoint
}

uuid, err := guuid.NewV4()
if err != nil {
Expand Down
17 changes: 9 additions & 8 deletions pkg/meta/dynamodb/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ import (
mTypes "zotregistry.io/zot/pkg/meta/types"
reqCtx "zotregistry.io/zot/pkg/requestcontext"
. "zotregistry.io/zot/pkg/test/image-utils"
tskip "zotregistry.io/zot/pkg/test/skip"
)

const badTablename = "bad tablename"

func TestIterator(t *testing.T) {
const (
endpoint = "http://localhost:4566"
region = "us-east-2"
)
tskip.SkipDynamo(t)

const region = "us-east-2"
endpoint := os.Getenv("DYNAMODBMOCK_ENDPOINT")

uuid, err := guuid.NewV4()
if err != nil {
Expand Down Expand Up @@ -131,10 +132,10 @@ func TestIteratorErrors(t *testing.T) {
}

func TestWrapperErrors(t *testing.T) {
const (
endpoint = "http://localhost:4566"
region = "us-east-2"
)
tskip.SkipDynamo(t)

const region = "us-east-2"
endpoint := os.Getenv("DYNAMODBMOCK_ENDPOINT")

uuid, err := guuid.NewV4()
if err != nil {
Expand Down
13 changes: 3 additions & 10 deletions pkg/meta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"zotregistry.io/zot/pkg/test/deprecated"
. "zotregistry.io/zot/pkg/test/image-utils"
signature "zotregistry.io/zot/pkg/test/signature"
tskip "zotregistry.io/zot/pkg/test/skip"
)

const (
Expand Down Expand Up @@ -97,7 +98,7 @@ func TestBoltDB(t *testing.T) {
}

func TestDynamoDBWrapper(t *testing.T) {
skipIt(t)
tskip.SkipDynamo(t)

uuid, err := guuid.NewV4()
if err != nil {
Expand Down Expand Up @@ -2688,7 +2689,7 @@ func generateTestImage() ([]byte, []byte, error) {
}

func TestCreateDynamo(t *testing.T) {
skipDynamo(t)
tskip.SkipDynamo(t)

Convey("Create", t, func() {
dynamoDBDriverParams := mdynamodb.DBDriverParameters{
Expand Down Expand Up @@ -2747,11 +2748,3 @@ func TestCreateBoltDB(t *testing.T) {
So(func() { _, _ = meta.Create("boltdb", nil, mdynamodb.DBDriverParameters{}, log) }, ShouldPanic)
})
}

func skipDynamo(t *testing.T) {
t.Helper()

if os.Getenv("DYNAMODBMOCK_ENDPOINT") == "" {
t.Skip("Skipping testing without AWS DynamoDB mock server")
}
}
11 changes: 2 additions & 9 deletions pkg/meta/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
. "zotregistry.io/zot/pkg/test/image-utils"
"zotregistry.io/zot/pkg/test/mocks"
"zotregistry.io/zot/pkg/test/signature"
tskip "zotregistry.io/zot/pkg/test/skip"
)

const repo = "repo"
Expand Down Expand Up @@ -367,7 +368,7 @@ func TestParseStorageWithBoltDB(t *testing.T) {
}

func TestParseStorageDynamoWrapper(t *testing.T) {
skipIt(t)
tskip.SkipS3(t)

Convey("Dynamodb", t, func() {
rootDir := t.TempDir()
Expand Down Expand Up @@ -596,14 +597,6 @@ func TestGetReferredInfo(t *testing.T) {
})
}

func skipIt(t *testing.T) {
t.Helper()

if os.Getenv("S3MOCK_ENDPOINT") == "" {
t.Skip("Skipping testing without AWS S3 mock server")
}
}

func TestGetSignatureLayersInfo(t *testing.T) {
Convey("wrong signature type", t, func() {
layers, err := meta.GetSignatureLayersInfo("repo", "tag", "123", "wrong signature type", []byte{},
Expand Down
10 changes: 4 additions & 6 deletions pkg/meta/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"zotregistry.io/zot/pkg/meta/boltdb"
mdynamodb "zotregistry.io/zot/pkg/meta/dynamodb"
"zotregistry.io/zot/pkg/meta/version"
tskip "zotregistry.io/zot/pkg/test/skip"
)

var ErrTestError = errors.New("test error")
Expand Down Expand Up @@ -113,15 +114,12 @@ func setBoltDBVersion(db *bbolt.DB, vers string) error {
}

func TestVersioningDynamoDB(t *testing.T) {
const (
endpoint = "http://localhost:4566"
region = "us-east-2"
)
tskip.SkipDynamo(t)

Convey("Tests", t, func() {
params := mdynamodb.DBDriverParameters{
Endpoint: endpoint,
Region: region,
Endpoint: os.Getenv("DYNAMODBMOCK_ENDPOINT"),
Region: "us-east-2",
RepoMetaTablename: "RepoMetadataTable",
ManifestDataTablename: "ManifestDataTable",
IndexDataTablename: "IndexDataTable",
Expand Down
11 changes: 2 additions & 9 deletions pkg/storage/cache/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,11 @@ import (
"zotregistry.io/zot/pkg/log"
"zotregistry.io/zot/pkg/storage"
"zotregistry.io/zot/pkg/storage/cache"
tskip "zotregistry.io/zot/pkg/test/skip"
)

func skipIt(t *testing.T) {
t.Helper()

if os.Getenv("DYNAMODBMOCK_ENDPOINT") == "" {
t.Skip("Skipping testing without AWS DynamoDB mock server")
}
}

func TestDynamoDB(t *testing.T) {
skipIt(t)
tskip.SkipDynamo(t)
Convey("Test dynamoDB", t, func(c C) {
log := log.NewLogger("debug", "")
dir := t.TempDir()
Expand Down
Loading

0 comments on commit 092890e

Please sign in to comment.