From 955f6a4ae31870e1a5d465b9368ebb539fa0fade Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Thu, 26 Jun 2025 17:20:18 +0200 Subject: [PATCH] chore: add mockery v3 Signed-off-by: Miguel Martinez --- app/controlplane/pkg/biz/.mockery.yml | 17 + app/controlplane/pkg/biz/mocks_test.go | 468 +++++++++++++++++++++++++ common.mk | 2 +- 3 files changed, 486 insertions(+), 1 deletion(-) create mode 100644 app/controlplane/pkg/biz/.mockery.yml create mode 100644 app/controlplane/pkg/biz/mocks_test.go diff --git a/app/controlplane/pkg/biz/.mockery.yml b/app/controlplane/pkg/biz/.mockery.yml new file mode 100644 index 000000000..5bef01cbc --- /dev/null +++ b/app/controlplane/pkg/biz/.mockery.yml @@ -0,0 +1,17 @@ +all: false +dir: '{{.InterfaceDir}}' +filename: mocks_test.go +force-file-write: true +formatter: goimports +include-auto-generated: false +log-level: info +structname: '{{.Mock}}{{.InterfaceName}}' +pkgname: '{{.SrcPackageName}}' +recursive: false +require-template-schema-exists: true +template: testify +template-schema: '{{.Template}}.schema.json' +packages: + github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz: + interfaces: + APITokenRepo: diff --git a/app/controlplane/pkg/biz/mocks_test.go b/app/controlplane/pkg/biz/mocks_test.go new file mode 100644 index 000000000..0f7844cdd --- /dev/null +++ b/app/controlplane/pkg/biz/mocks_test.go @@ -0,0 +1,468 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package biz + +import ( + "context" + "time" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockAPITokenRepo creates a new instance of MockAPITokenRepo. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockAPITokenRepo(t interface { + mock.TestingT + Cleanup(func()) +}) *MockAPITokenRepo { + mock := &MockAPITokenRepo{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +// MockAPITokenRepo is an autogenerated mock type for the APITokenRepo type +type MockAPITokenRepo struct { + mock.Mock +} + +type MockAPITokenRepo_Expecter struct { + mock *mock.Mock +} + +func (_m *MockAPITokenRepo) EXPECT() *MockAPITokenRepo_Expecter { + return &MockAPITokenRepo_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockAPITokenRepo +func (_mock *MockAPITokenRepo) Create(ctx context.Context, name string, description *string, expiresAt *time.Time, organizationID uuid.UUID) (*APIToken, error) { + ret := _mock.Called(ctx, name, description, expiresAt, organizationID) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *APIToken + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, *string, *time.Time, uuid.UUID) (*APIToken, error)); ok { + return returnFunc(ctx, name, description, expiresAt, organizationID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, *string, *time.Time, uuid.UUID) *APIToken); ok { + r0 = returnFunc(ctx, name, description, expiresAt, organizationID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*APIToken) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, *string, *time.Time, uuid.UUID) error); ok { + r1 = returnFunc(ctx, name, description, expiresAt, organizationID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAPITokenRepo_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockAPITokenRepo_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - name string +// - description *string +// - expiresAt *time.Time +// - organizationID uuid.UUID +func (_e *MockAPITokenRepo_Expecter) Create(ctx interface{}, name interface{}, description interface{}, expiresAt interface{}, organizationID interface{}) *MockAPITokenRepo_Create_Call { + return &MockAPITokenRepo_Create_Call{Call: _e.mock.On("Create", ctx, name, description, expiresAt, organizationID)} +} + +func (_c *MockAPITokenRepo_Create_Call) Run(run func(ctx context.Context, name string, description *string, expiresAt *time.Time, organizationID uuid.UUID)) *MockAPITokenRepo_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + var arg2 *string + if args[2] != nil { + arg2 = args[2].(*string) + } + var arg3 *time.Time + if args[3] != nil { + arg3 = args[3].(*time.Time) + } + var arg4 uuid.UUID + if args[4] != nil { + arg4 = args[4].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + arg3, + arg4, + ) + }) + return _c +} + +func (_c *MockAPITokenRepo_Create_Call) Return(aPIToken *APIToken, err error) *MockAPITokenRepo_Create_Call { + _c.Call.Return(aPIToken, err) + return _c +} + +func (_c *MockAPITokenRepo_Create_Call) RunAndReturn(run func(ctx context.Context, name string, description *string, expiresAt *time.Time, organizationID uuid.UUID) (*APIToken, error)) *MockAPITokenRepo_Create_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function for the type MockAPITokenRepo +func (_mock *MockAPITokenRepo) FindByID(ctx context.Context, ID uuid.UUID) (*APIToken, error) { + ret := _mock.Called(ctx, ID) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 *APIToken + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (*APIToken, error)); ok { + return returnFunc(ctx, ID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) *APIToken); ok { + r0 = returnFunc(ctx, ID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*APIToken) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { + r1 = returnFunc(ctx, ID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAPITokenRepo_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockAPITokenRepo_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - ID uuid.UUID +func (_e *MockAPITokenRepo_Expecter) FindByID(ctx interface{}, ID interface{}) *MockAPITokenRepo_FindByID_Call { + return &MockAPITokenRepo_FindByID_Call{Call: _e.mock.On("FindByID", ctx, ID)} +} + +func (_c *MockAPITokenRepo_FindByID_Call) Run(run func(ctx context.Context, ID uuid.UUID)) *MockAPITokenRepo_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockAPITokenRepo_FindByID_Call) Return(aPIToken *APIToken, err error) *MockAPITokenRepo_FindByID_Call { + _c.Call.Return(aPIToken, err) + return _c +} + +func (_c *MockAPITokenRepo_FindByID_Call) RunAndReturn(run func(ctx context.Context, ID uuid.UUID) (*APIToken, error)) *MockAPITokenRepo_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// FindByNameInOrg provides a mock function for the type MockAPITokenRepo +func (_mock *MockAPITokenRepo) FindByNameInOrg(ctx context.Context, orgID uuid.UUID, name string) (*APIToken, error) { + ret := _mock.Called(ctx, orgID, name) + + if len(ret) == 0 { + panic("no return value specified for FindByNameInOrg") + } + + var r0 *APIToken + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) (*APIToken, error)); ok { + return returnFunc(ctx, orgID, name) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) *APIToken); ok { + r0 = returnFunc(ctx, orgID, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*APIToken) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, string) error); ok { + r1 = returnFunc(ctx, orgID, name) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAPITokenRepo_FindByNameInOrg_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByNameInOrg' +type MockAPITokenRepo_FindByNameInOrg_Call struct { + *mock.Call +} + +// FindByNameInOrg is a helper method to define mock.On call +// - ctx context.Context +// - orgID uuid.UUID +// - name string +func (_e *MockAPITokenRepo_Expecter) FindByNameInOrg(ctx interface{}, orgID interface{}, name interface{}) *MockAPITokenRepo_FindByNameInOrg_Call { + return &MockAPITokenRepo_FindByNameInOrg_Call{Call: _e.mock.On("FindByNameInOrg", ctx, orgID, name)} +} + +func (_c *MockAPITokenRepo_FindByNameInOrg_Call) Run(run func(ctx context.Context, orgID uuid.UUID, name string)) *MockAPITokenRepo_FindByNameInOrg_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 string + if args[2] != nil { + arg2 = args[2].(string) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockAPITokenRepo_FindByNameInOrg_Call) Return(aPIToken *APIToken, err error) *MockAPITokenRepo_FindByNameInOrg_Call { + _c.Call.Return(aPIToken, err) + return _c +} + +func (_c *MockAPITokenRepo_FindByNameInOrg_Call) RunAndReturn(run func(ctx context.Context, orgID uuid.UUID, name string) (*APIToken, error)) *MockAPITokenRepo_FindByNameInOrg_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function for the type MockAPITokenRepo +func (_mock *MockAPITokenRepo) List(ctx context.Context, orgID *uuid.UUID, includeRevoked bool) ([]*APIToken, error) { + ret := _mock.Called(ctx, orgID, includeRevoked) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []*APIToken + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, bool) ([]*APIToken, error)); ok { + return returnFunc(ctx, orgID, includeRevoked) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, bool) []*APIToken); ok { + r0 = returnFunc(ctx, orgID, includeRevoked) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*APIToken) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, *uuid.UUID, bool) error); ok { + r1 = returnFunc(ctx, orgID, includeRevoked) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAPITokenRepo_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type MockAPITokenRepo_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - orgID *uuid.UUID +// - includeRevoked bool +func (_e *MockAPITokenRepo_Expecter) List(ctx interface{}, orgID interface{}, includeRevoked interface{}) *MockAPITokenRepo_List_Call { + return &MockAPITokenRepo_List_Call{Call: _e.mock.On("List", ctx, orgID, includeRevoked)} +} + +func (_c *MockAPITokenRepo_List_Call) Run(run func(ctx context.Context, orgID *uuid.UUID, includeRevoked bool)) *MockAPITokenRepo_List_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *uuid.UUID + if args[1] != nil { + arg1 = args[1].(*uuid.UUID) + } + var arg2 bool + if args[2] != nil { + arg2 = args[2].(bool) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockAPITokenRepo_List_Call) Return(aPITokens []*APIToken, err error) *MockAPITokenRepo_List_Call { + _c.Call.Return(aPITokens, err) + return _c +} + +func (_c *MockAPITokenRepo_List_Call) RunAndReturn(run func(ctx context.Context, orgID *uuid.UUID, includeRevoked bool) ([]*APIToken, error)) *MockAPITokenRepo_List_Call { + _c.Call.Return(run) + return _c +} + +// Revoke provides a mock function for the type MockAPITokenRepo +func (_mock *MockAPITokenRepo) Revoke(ctx context.Context, orgID uuid.UUID, ID uuid.UUID) error { + ret := _mock.Called(ctx, orgID, ID) + + if len(ret) == 0 { + panic("no return value specified for Revoke") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) error); ok { + r0 = returnFunc(ctx, orgID, ID) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockAPITokenRepo_Revoke_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Revoke' +type MockAPITokenRepo_Revoke_Call struct { + *mock.Call +} + +// Revoke is a helper method to define mock.On call +// - ctx context.Context +// - orgID uuid.UUID +// - ID uuid.UUID +func (_e *MockAPITokenRepo_Expecter) Revoke(ctx interface{}, orgID interface{}, ID interface{}) *MockAPITokenRepo_Revoke_Call { + return &MockAPITokenRepo_Revoke_Call{Call: _e.mock.On("Revoke", ctx, orgID, ID)} +} + +func (_c *MockAPITokenRepo_Revoke_Call) Run(run func(ctx context.Context, orgID uuid.UUID, ID uuid.UUID)) *MockAPITokenRepo_Revoke_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockAPITokenRepo_Revoke_Call) Return(err error) *MockAPITokenRepo_Revoke_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockAPITokenRepo_Revoke_Call) RunAndReturn(run func(ctx context.Context, orgID uuid.UUID, ID uuid.UUID) error) *MockAPITokenRepo_Revoke_Call { + _c.Call.Return(run) + return _c +} + +// UpdateExpiration provides a mock function for the type MockAPITokenRepo +func (_mock *MockAPITokenRepo) UpdateExpiration(ctx context.Context, ID uuid.UUID, expiresAt time.Time) error { + ret := _mock.Called(ctx, ID, expiresAt) + + if len(ret) == 0 { + panic("no return value specified for UpdateExpiration") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, time.Time) error); ok { + r0 = returnFunc(ctx, ID, expiresAt) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockAPITokenRepo_UpdateExpiration_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateExpiration' +type MockAPITokenRepo_UpdateExpiration_Call struct { + *mock.Call +} + +// UpdateExpiration is a helper method to define mock.On call +// - ctx context.Context +// - ID uuid.UUID +// - expiresAt time.Time +func (_e *MockAPITokenRepo_Expecter) UpdateExpiration(ctx interface{}, ID interface{}, expiresAt interface{}) *MockAPITokenRepo_UpdateExpiration_Call { + return &MockAPITokenRepo_UpdateExpiration_Call{Call: _e.mock.On("UpdateExpiration", ctx, ID, expiresAt)} +} + +func (_c *MockAPITokenRepo_UpdateExpiration_Call) Run(run func(ctx context.Context, ID uuid.UUID, expiresAt time.Time)) *MockAPITokenRepo_UpdateExpiration_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 time.Time + if args[2] != nil { + arg2 = args[2].(time.Time) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockAPITokenRepo_UpdateExpiration_Call) Return(err error) *MockAPITokenRepo_UpdateExpiration_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockAPITokenRepo_UpdateExpiration_Call) RunAndReturn(run func(ctx context.Context, ID uuid.UUID, expiresAt time.Time) error) *MockAPITokenRepo_UpdateExpiration_Call { + _c.Call.Return(run) + return _c +} diff --git a/common.mk b/common.mk index 809ff6cd9..53ac388a7 100644 --- a/common.mk +++ b/common.mk @@ -4,7 +4,7 @@ VERSION=$(shell git describe --tags --always) # init env init: init-api-tools go install github.com/google/wire/cmd/wire@latest - go install github.com/vektra/mockery/v2@v2.53.4 + go install github.com/vektra/mockery/v3@v3.5.0 # using binary release for atlas, since ent schema handler is not included # in the community version anymore https://github.com/ariga/atlas/issues/2388#issuecomment-1864287189 curl -sSf https://atlasgo.sh | ATLAS_VERSION=v0.35.0 sh -s -- -y