From 735f777215abf2b787731c1e243322fa30f128ae Mon Sep 17 00:00:00 2001 From: Tosone Date: Mon, 8 Apr 2024 20:09:19 +0800 Subject: [PATCH] :sparkles: Add test params (#354) --- .github/workflows/test.yml | 12 +-- pkg/modules/locker/definition/definition.go | 3 + pkg/modules/locker/definition/mocks/lock.go | 74 +++++++++++++++++++ pkg/modules/locker/definition/mocks/locker.go | 71 ++++++++++++++++++ pkg/signing/definition/definition.go | 3 + pkg/signing/definition/mocks/signing.go | 54 ++++++++++++++ pkg/signing/definition/mocks/verifying.go | 53 +++++++++++++ pkg/tests/middleware.go | 4 - 8 files changed, 264 insertions(+), 10 deletions(-) create mode 100644 pkg/modules/locker/definition/mocks/lock.go create mode 100644 pkg/modules/locker/definition/mocks/locker.go create mode 100644 pkg/signing/definition/mocks/signing.go create mode 100644 pkg/signing/definition/mocks/verifying.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7666148f..00c34385 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -81,7 +81,7 @@ jobs: OSS_SK: ${{ secrets.OSS_SK }} OSS_BUCKET: ${{ secrets.OSS_BUCKET_SQLITE }} run: | - CI_DATABASE_TYPE=sqlite3 go test -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks"` + CI_DATABASE_TYPE=sqlite3 go test -parallel 1 -failfast -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks"` - name: Run tests if: ${{ github.event_name == 'pull_request' }} env: @@ -93,7 +93,7 @@ jobs: OSS_SK: ${{ secrets.OSS_SK }} OSS_BUCKET: ${{ secrets.OSS_BUCKET_SQLITE }} run: | - CI_DATABASE_TYPE=sqlite3 go test -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks" | grep -v "pkg/storage/cos" | grep -v "pkg/storage/oss"` + CI_DATABASE_TYPE=sqlite3 go test -parallel 1 -failfast -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks" | grep -v "pkg/storage/cos" | grep -v "pkg/storage/oss"` - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 with: @@ -170,7 +170,7 @@ jobs: OSS_SK: ${{ secrets.OSS_SK }} OSS_BUCKET: ${{ secrets.OSS_BUCKET_POSTGRESQL }} run: | - CI_DATABASE_TYPE=postgresql go test -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks"` + CI_DATABASE_TYPE=postgresql go test -parallel 1 -failfast -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks"` - name: Run tests if: ${{ github.event_name == 'pull_request' }} env: @@ -182,7 +182,7 @@ jobs: OSS_SK: ${{ secrets.OSS_SK }} OSS_BUCKET: ${{ secrets.OSS_BUCKET_POSTGRESQL }} run: | - CI_DATABASE_TYPE=postgresql go test -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks" | grep -v "pkg/storage/cos" | grep -v "pkg/storage/oss"` + CI_DATABASE_TYPE=postgresql go test -parallel 1 -failfast -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks" | grep -v "pkg/storage/cos" | grep -v "pkg/storage/oss"` - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 with: @@ -260,7 +260,7 @@ jobs: OSS_SK: ${{ secrets.OSS_SK }} OSS_BUCKET: ${{ secrets.OSS_BUCKET_MYSQL }} run: | - CI_DATABASE_TYPE=mysql go test -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks"` + CI_DATABASE_TYPE=mysql go test -parallel 1 -failfast -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks"` - name: Run tests if: ${{ github.event_name == 'pull_request' }} env: @@ -272,7 +272,7 @@ jobs: OSS_SK: ${{ secrets.OSS_SK }} OSS_BUCKET: ${{ secrets.OSS_BUCKET_MYSQL }} run: | - CI_DATABASE_TYPE=mysql go test -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks" | grep -v "pkg/storage/cos" | grep -v "pkg/storage/oss"` + CI_DATABASE_TYPE=mysql go test -parallel 1 -failfast -tags "timetzdata,exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp" -timeout 30m -v -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v "pkg/tests" | grep -v "pkg/dal/query" | grep -v "pkg/dal/cmd" | grep -v "pkg/types/enums" | grep -v "pkg/handlers/apidocs" | grep -v "pkg/utils/token/mocks" | grep -v "pkg/utils/password/mocks" | grep -v "pkg/handlers/distribution/clients/mocks" | grep -v "pkg/storage/cos" | grep -v "pkg/storage/oss"` - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 with: diff --git a/pkg/modules/locker/definition/definition.go b/pkg/modules/locker/definition/definition.go index bd6cede8..2c867e69 100644 --- a/pkg/modules/locker/definition/definition.go +++ b/pkg/modules/locker/definition/definition.go @@ -14,6 +14,9 @@ package definition +//go:generate mockgen -destination=mocks/lock.go -package=mocks github.com/go-sigma/sigma/pkg/modules/locker/definition Lock +//go:generate mockgen -destination=mocks/locker.go -package=mocks github.com/go-sigma/sigma/pkg/modules/locker/definition Locker + import ( "context" "errors" diff --git a/pkg/modules/locker/definition/mocks/lock.go b/pkg/modules/locker/definition/mocks/lock.go new file mode 100644 index 00000000..6ce0bf1f --- /dev/null +++ b/pkg/modules/locker/definition/mocks/lock.go @@ -0,0 +1,74 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/go-sigma/sigma/pkg/modules/locker/definition (interfaces: Lock) +// +// Generated by this command: +// +// mockgen -destination=mocks/lock.go -package=mocks github.com/go-sigma/sigma/pkg/modules/locker/definition Lock +// + +// Package mocks is a generated GoMock package. +package mocks + +import ( + context "context" + reflect "reflect" + time "time" + + gomock "go.uber.org/mock/gomock" +) + +// MockLock is a mock of Lock interface. +type MockLock struct { + ctrl *gomock.Controller + recorder *MockLockMockRecorder +} + +// MockLockMockRecorder is the mock recorder for MockLock. +type MockLockMockRecorder struct { + mock *MockLock +} + +// NewMockLock creates a new mock instance. +func NewMockLock(ctrl *gomock.Controller) *MockLock { + mock := &MockLock{ctrl: ctrl} + mock.recorder = &MockLockMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLock) EXPECT() *MockLockMockRecorder { + return m.recorder +} + +// Renew mocks base method. +func (m *MockLock) Renew(arg0 context.Context, arg1 ...time.Duration) error { + m.ctrl.T.Helper() + varargs := []any{arg0} + for _, a := range arg1 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Renew", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Renew indicates an expected call of Renew. +func (mr *MockLockMockRecorder) Renew(arg0 any, arg1 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]any{arg0}, arg1...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Renew", reflect.TypeOf((*MockLock)(nil).Renew), varargs...) +} + +// Unlock mocks base method. +func (m *MockLock) Unlock(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Unlock", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Unlock indicates an expected call of Unlock. +func (mr *MockLockMockRecorder) Unlock(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unlock", reflect.TypeOf((*MockLock)(nil).Unlock), arg0) +} diff --git a/pkg/modules/locker/definition/mocks/locker.go b/pkg/modules/locker/definition/mocks/locker.go new file mode 100644 index 00000000..d4702b0a --- /dev/null +++ b/pkg/modules/locker/definition/mocks/locker.go @@ -0,0 +1,71 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/go-sigma/sigma/pkg/modules/locker/definition (interfaces: Locker) +// +// Generated by this command: +// +// mockgen -destination=mocks/locker.go -package=mocks github.com/go-sigma/sigma/pkg/modules/locker/definition Locker +// + +// Package mocks is a generated GoMock package. +package mocks + +import ( + context "context" + reflect "reflect" + time "time" + + definition "github.com/go-sigma/sigma/pkg/modules/locker/definition" + gomock "go.uber.org/mock/gomock" +) + +// MockLocker is a mock of Locker interface. +type MockLocker struct { + ctrl *gomock.Controller + recorder *MockLockerMockRecorder +} + +// MockLockerMockRecorder is the mock recorder for MockLocker. +type MockLockerMockRecorder struct { + mock *MockLocker +} + +// NewMockLocker creates a new mock instance. +func NewMockLocker(ctrl *gomock.Controller) *MockLocker { + mock := &MockLocker{ctrl: ctrl} + mock.recorder = &MockLockerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLocker) EXPECT() *MockLockerMockRecorder { + return m.recorder +} + +// Acquire mocks base method. +func (m *MockLocker) Acquire(arg0 context.Context, arg1 string, arg2, arg3 time.Duration) (definition.Lock, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Acquire", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(definition.Lock) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Acquire indicates an expected call of Acquire. +func (mr *MockLockerMockRecorder) Acquire(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Acquire", reflect.TypeOf((*MockLocker)(nil).Acquire), arg0, arg1, arg2, arg3) +} + +// AcquireWithRenew mocks base method. +func (m *MockLocker) AcquireWithRenew(arg0 context.Context, arg1 string, arg2, arg3 time.Duration) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AcquireWithRenew", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(error) + return ret0 +} + +// AcquireWithRenew indicates an expected call of AcquireWithRenew. +func (mr *MockLockerMockRecorder) AcquireWithRenew(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AcquireWithRenew", reflect.TypeOf((*MockLocker)(nil).AcquireWithRenew), arg0, arg1, arg2, arg3) +} diff --git a/pkg/signing/definition/definition.go b/pkg/signing/definition/definition.go index e7fe9dfc..6eaabfe3 100644 --- a/pkg/signing/definition/definition.go +++ b/pkg/signing/definition/definition.go @@ -16,6 +16,9 @@ package definition import "context" +//go:generate mockgen -destination=mocks/signing.go -package=mocks github.com/go-sigma/sigma/pkg/signing/definition Signing +//go:generate mockgen -destination=mocks/verifying.go -package=mocks github.com/go-sigma/sigma/pkg/signing/definition Verifying + // Signing ... type Signing interface { Sign(ctx context.Context, token, priKey, ref string) error diff --git a/pkg/signing/definition/mocks/signing.go b/pkg/signing/definition/mocks/signing.go new file mode 100644 index 00000000..d81e72f7 --- /dev/null +++ b/pkg/signing/definition/mocks/signing.go @@ -0,0 +1,54 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/go-sigma/sigma/pkg/signing/definition (interfaces: Signing) +// +// Generated by this command: +// +// mockgen -destination=mocks/signing.go -package=mocks github.com/go-sigma/sigma/pkg/signing/definition Signing +// + +// Package mocks is a generated GoMock package. +package mocks + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockSigning is a mock of Signing interface. +type MockSigning struct { + ctrl *gomock.Controller + recorder *MockSigningMockRecorder +} + +// MockSigningMockRecorder is the mock recorder for MockSigning. +type MockSigningMockRecorder struct { + mock *MockSigning +} + +// NewMockSigning creates a new mock instance. +func NewMockSigning(ctrl *gomock.Controller) *MockSigning { + mock := &MockSigning{ctrl: ctrl} + mock.recorder = &MockSigningMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSigning) EXPECT() *MockSigningMockRecorder { + return m.recorder +} + +// Sign mocks base method. +func (m *MockSigning) Sign(arg0 context.Context, arg1, arg2, arg3 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Sign", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(error) + return ret0 +} + +// Sign indicates an expected call of Sign. +func (mr *MockSigningMockRecorder) Sign(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sign", reflect.TypeOf((*MockSigning)(nil).Sign), arg0, arg1, arg2, arg3) +} diff --git a/pkg/signing/definition/mocks/verifying.go b/pkg/signing/definition/mocks/verifying.go new file mode 100644 index 00000000..fb0951bd --- /dev/null +++ b/pkg/signing/definition/mocks/verifying.go @@ -0,0 +1,53 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/go-sigma/sigma/pkg/signing/definition (interfaces: Verifying) +// +// Generated by this command: +// +// mockgen -destination=mocks/verifying.go -package=mocks github.com/go-sigma/sigma/pkg/signing/definition Verifying +// + +// Package mocks is a generated GoMock package. +package mocks + +import ( + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockVerifying is a mock of Verifying interface. +type MockVerifying struct { + ctrl *gomock.Controller + recorder *MockVerifyingMockRecorder +} + +// MockVerifyingMockRecorder is the mock recorder for MockVerifying. +type MockVerifyingMockRecorder struct { + mock *MockVerifying +} + +// NewMockVerifying creates a new mock instance. +func NewMockVerifying(ctrl *gomock.Controller) *MockVerifying { + mock := &MockVerifying{ctrl: ctrl} + mock.recorder = &MockVerifyingMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockVerifying) EXPECT() *MockVerifyingMockRecorder { + return m.recorder +} + +// Verify mocks base method. +func (m *MockVerifying) Verify(arg0, arg1 string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Verify", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Verify indicates an expected call of Verify. +func (mr *MockVerifyingMockRecorder) Verify(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Verify", reflect.TypeOf((*MockVerifying)(nil).Verify), arg0, arg1) +} diff --git a/pkg/tests/middleware.go b/pkg/tests/middleware.go index e06860fa..dad19c45 100644 --- a/pkg/tests/middleware.go +++ b/pkg/tests/middleware.go @@ -19,7 +19,6 @@ import ( "strings" "testing" - "github.com/alicebob/miniredis/v2" "github.com/spf13/viper" "github.com/go-sigma/sigma/pkg/types/enums" @@ -58,9 +57,6 @@ func Initialize(t *testing.T) error { viper.AutomaticEnv() viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - miniRedis := miniredis.RunT(t) - viper.SetDefault("redis.url", "redis://"+miniRedis.Addr()) - typ := viper.GetString("ci.database.type") if typ == "" { typ = enums.DatabaseSqlite3.String()