From 92a274195027bec78a0fad9e90e07ef99360c3aa Mon Sep 17 00:00:00 2001 From: Allisson Azevedo Date: Fri, 17 Jul 2026 17:35:13 -0300 Subject: [PATCH] refactor(keyring): fold master-key/KMS lifecycle into the deep module Extends ADR-0013: the envelope-encryption data plane was already a deep module, but the master-key/KMS lifecycle around it was a shallow, exported control surface that leaked and could not be tested. - Hide root-key material: unexport the master-key type and its bytes; only the opaque MasterKeyChain handle crosses the package boundary. Add MasterKeyChain.Has for presence checks without leaking material. - Make bootstrap testable: extract bootstrapWith behind the kek/dek store seams so KEK loading is unit-tested without a database. Public Bootstrap / NewKekUseCase signatures and di wiring are unchanged. - Honest KMS seam: add Encrypt to KMSKeeper so the create/rotate master-key CLI commands drop their runtime type assertions; add an exported keyring.FakeKMSService as a real second adapter and cover loadMasterKeyChainFromKMS in-package. - Delete the unused internal/tokenization/testing helper. Also reconcile .mockery.yaml with the current package layout (it still referenced the deleted crypto/auth-service packages): repository mocks now generate beside their domain interfaces, KekUseCase under keyring. Verified: make lint, make test, and make test-all (incl. the DB-backed integration suite) all pass. Co-Authored-By: Claude Opus 4.8 (1M context) --- .mockery.yaml | 42 +- CHANGELOG.md | 5 + CONTEXT.md | 13 +- cmd/app/commands/master_key.go | 12 +- cmd/app/commands/master_key_test.go | 50 +- cmd/app/commands/rotate_master_key.go | 12 +- cmd/app/commands/rotate_master_key_test.go | 38 +- internal/app/di_test.go | 20 +- internal/auth/domain/mocks/mocks.go | 1139 ++++++++++++++++ internal/auth/usecase/client_usecase_test.go | 37 +- internal/auth/usecase/mocks/mocks.go | 1159 +---------------- internal/auth/usecase/token_usecase_test.go | 85 +- internal/database/mocks/mocks.go | 2 +- internal/keyring/bootstrap.go | 19 +- internal/keyring/bootstrap_test.go | 61 + internal/keyring/fake_kms.go | 70 + internal/keyring/kek_usecase.go | 14 +- internal/keyring/kek_usecase_test.go | 79 ++ internal/keyring/key_manager.go | 14 +- internal/keyring/kms.go | 8 +- internal/keyring/master_key.go | 35 +- internal/keyring/master_key_test.go | 105 ++ .../mocks/{mock_kek_usecase.go => mocks.go} | 46 +- internal/keyring/store_fakes_test.go | 80 ++ internal/secrets/domain/mocks/mocks.go | 442 +++++++ internal/secrets/usecase/mocks/mocks.go | 442 +------ .../secrets/usecase/secret_usecase_test.go | 2 +- internal/tokenization/domain/mocks/mocks.go | 1051 +++++++++++++++ internal/tokenization/testing/helpers.go | 14 - internal/tokenization/usecase/mocks/mocks.go | 1065 +-------------- .../usecase/tokenization_key_usecase_test.go | 2 +- .../usecase/tokenization_usecase_test.go | 2 +- internal/transit/domain/mocks/mocks.go | 516 ++++++++ internal/transit/usecase/mocks/mocks.go | 520 +------- .../usecase/transit_key_usecase_test.go | 2 +- test/integration/helpers_test.go | 35 +- test/integration/kms_flow_test.go | 27 +- 37 files changed, 3834 insertions(+), 3431 deletions(-) create mode 100644 internal/auth/domain/mocks/mocks.go create mode 100644 internal/keyring/bootstrap_test.go create mode 100644 internal/keyring/fake_kms.go create mode 100644 internal/keyring/kek_usecase_test.go create mode 100644 internal/keyring/master_key_test.go rename internal/keyring/mocks/{mock_kek_usecase.go => mocks.go} (66%) create mode 100644 internal/keyring/store_fakes_test.go create mode 100644 internal/secrets/domain/mocks/mocks.go create mode 100644 internal/tokenization/domain/mocks/mocks.go delete mode 100644 internal/tokenization/testing/helpers.go create mode 100644 internal/transit/domain/mocks/mocks.go diff --git a/.mockery.yaml b/.mockery.yaml index b674007..36d2907 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -6,43 +6,39 @@ template: testify template-data: unroll-variadic: true packages: - github.com/allisson/secrets/internal/auth/service: + github.com/allisson/secrets/internal/database: interfaces: - SecretService: {} - TokenService: {} - AuditSigner: {} - github.com/allisson/secrets/internal/auth/usecase: + TxManager: {} + github.com/allisson/secrets/internal/keyring: + interfaces: + KekUseCase: {} + github.com/allisson/secrets/internal/auth/domain: interfaces: AuditLogRepository: {} - AuditLogUseCase: {} ClientRepository: {} - ClientUseCase: {} TokenRepository: {} - TokenUseCase: {} - github.com/allisson/secrets/internal/crypto/service: - interfaces: - AEAD: {} - AEADManager: {} - KeyManager: {} - github.com/allisson/secrets/internal/crypto/usecase: + github.com/allisson/secrets/internal/auth/usecase: interfaces: - KekRepository: {} - KekUseCase: {} - github.com/allisson/secrets/internal/database: + AuditLogUseCase: {} + ClientUseCase: {} + TokenUseCase: {} + github.com/allisson/secrets/internal/secrets/domain: interfaces: - TxManager: {} + SecretRepository: {} github.com/allisson/secrets/internal/secrets/usecase: interfaces: - SecretRepository: {} SecretUseCase: {} - github.com/allisson/secrets/internal/transit/usecase: + github.com/allisson/secrets/internal/transit/domain: interfaces: TransitKeyRepository: {} + github.com/allisson/secrets/internal/transit/usecase: + interfaces: TransitKeyUseCase: {} - github.com/allisson/secrets/internal/tokenization/usecase: + github.com/allisson/secrets/internal/tokenization/domain: interfaces: TokenizationKeyRepository: {} - TokenizationKeyUseCase: {} TokenRepository: {} + github.com/allisson/secrets/internal/tokenization/usecase: + interfaces: + TokenizationKeyUseCase: {} TokenizationUseCase: {} - HashService: {} diff --git a/CHANGELOG.md b/CHANGELOG.md index 34e1a31..ca01cb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Security + +- Master-key material is no longer reachable outside the `keyring` package. The `MasterKey` type and its key bytes are unexported; only the opaque `MasterKeyChain` handle crosses the package boundary, so no caller can read a root key's bytes. + ### Changed - Internal refactors with no API change: consolidated the six retention-sweep CLI commands (`purge-secrets`, `purge-transit-keys`, `purge-tokenization-keys`, `clean-expired-tokens`, `clean-audit-logs`, `purge-auth-tokens`) behind a single `RunRetentionSweep` module, and relocated the interactive policy-prompt helpers from `internal/ui` into the CLI commands package (#141). +- Folded the master-key/KMS lifecycle into the `keyring` deep module. KEK loading (`bootstrapWith`) and the KMS decrypt path are now unit-testable without a database or live KMS; `KMSKeeper` gained an explicit `Encrypt` operation so the create/rotate-master-key CLI commands no longer type-assert the concrete keeper; added an in-memory `keyring.FakeKMSService` test double and removed the unused `internal/tokenization/testing` helper. ### Fixed diff --git a/CONTEXT.md b/CONTEXT.md index 7785a4e..29e28cf 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -15,7 +15,9 @@ See [ADR-0001](docs/adr/0001-envelope-encryption-model.md). A symmetric key held outside this service in a KMS (AWS, GCP, Azure, or `localsecrets://` for development). Never stored in the database. Loaded at boot via `KMSKeeper.Decrypt` and held in a `MasterKeyChain` for the process -lifetime. +lifetime. The raw key material is unexported — it never leaves the `keyring` +package. `MasterKeyChain` is the opaque handle features and the composition +root pass around; callers cannot read a master key's bytes. ### KEK — Key Encryption Key A symmetric key that exists only to encrypt DEKs. Persisted in the `keks` @@ -60,6 +62,15 @@ calls behind it. Call sites do not know KEK from DEK. - `Rewrap(ctx, dekID)` — rewrap a DEK under the active KEK. Used by the rotation worker. +### KMS keeper +The seam `keyring` uses to reach an external KMS, `KMSKeeper`. Three operations: +`Decrypt` (the boot path — unwrap persisted master keys), `Encrypt` (the +operator path — the create/rotate-master-key CLI commands wrap a fresh key), +and `Close`. The running service only ever calls `Decrypt`; `Encrypt` lives on +the interface so the CLI needs no runtime type assertion. Two adapters make it +a real seam: `gocloud.dev/secrets` in production and `FakeKMSService` (a +deterministic in-memory double) in tests. + ### Envelope The value returned by `Keyring.Encrypt`. Contains `DekID`, `Ciphertext`, `Nonce`, and `Algorithm`. Features persist all four fields; nothing else diff --git a/cmd/app/commands/master_key.go b/cmd/app/commands/master_key.go index 56148cf..37ae41a 100644 --- a/cmd/app/commands/master_key.go +++ b/cmd/app/commands/master_key.go @@ -62,24 +62,16 @@ func RunCreateMasterKey( _, _ = fmt.Fprintln(writer) // Open keeper - keeperInterface, err := kmsService.OpenKeeper(ctx, kmsKeyURI) + keeper, err := kmsService.OpenKeeper(ctx, kmsKeyURI) if err != nil { return fmt.Errorf("failed to open KMS keeper: %w", err) } defer func() { - if closeErr := keeperInterface.Close(); closeErr != nil { + if closeErr := keeper.Close(); closeErr != nil { _, _ = fmt.Fprintf(writer, "Warning: failed to close KMS keeper: %v\n", closeErr) } }() - // Type assert to get Encrypt method (needed for encryption) - keeper, ok := keeperInterface.(interface { - Encrypt(ctx context.Context, plaintext []byte) ([]byte, error) - }) - if !ok { - return fmt.Errorf("KMS keeper does not support encryption") - } - // Encrypt master key with KMS ciphertext, err := keeper.Encrypt(ctx, masterKey) if err != nil { diff --git a/cmd/app/commands/master_key_test.go b/cmd/app/commands/master_key_test.go index 427e8b9..fec37a7 100644 --- a/cmd/app/commands/master_key_test.go +++ b/cmd/app/commands/master_key_test.go @@ -8,59 +8,20 @@ import ( "log/slog" "testing" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/allisson/secrets/internal/keyring" ) -// Manual mocks for KMS since they might not be generated in all environments -type MockKMSService struct { - mock.Mock -} - -func (m *MockKMSService) OpenKeeper(ctx context.Context, uri string) (keyring.KMSKeeper, error) { - args := m.Called(ctx, uri) - if args.Get(0) == nil { - return nil, args.Error(1) - } - return args.Get(0).(keyring.KMSKeeper), args.Error(1) -} - -type MockKMSKeeper struct { - mock.Mock -} - -func (m *MockKMSKeeper) Encrypt(ctx context.Context, plaintext []byte) ([]byte, error) { - args := m.Called(ctx, plaintext) - return args.Get(0).([]byte), args.Error(1) -} - -func (m *MockKMSKeeper) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) { - args := m.Called(ctx, ciphertext) - return args.Get(0).([]byte), args.Error(1) -} - -func (m *MockKMSKeeper) Close() error { - return m.Called().Error(0) -} - func TestRunCreateMasterKey(t *testing.T) { ctx := context.Background() logger := slog.New(slog.NewTextHandler(io.Discard, nil)) t.Run("success", func(t *testing.T) { - mockService := &MockKMSService{} - mockKeeper := &MockKMSKeeper{} - - mockService.On("OpenKeeper", ctx, "base64key://...").Return(mockKeeper, nil) - mockKeeper.On("Encrypt", ctx, mock.AnythingOfType("[]uint8")).Return([]byte("encrypted"), nil) - mockKeeper.On("Close").Return(nil) - var out bytes.Buffer err := RunCreateMasterKey( ctx, - mockService, + keyring.NewFakeKMSService(), logger, &out, "test-key", @@ -69,9 +30,6 @@ func TestRunCreateMasterKey(t *testing.T) { ) require.NoError(t, err) require.Contains(t, out.String(), "MASTER_KEYS=\"test-key:") - - mockService.AssertExpectations(t) - mockKeeper.AssertExpectations(t) }) t.Run("missing-parameters", func(t *testing.T) { @@ -81,12 +39,10 @@ func TestRunCreateMasterKey(t *testing.T) { }) t.Run("kms-error", func(t *testing.T) { - mockService := &MockKMSService{} - mockService.On("OpenKeeper", ctx, "invalid").Return(nil, errors.New("kms error")) - + svc := &keyring.FakeKMSService{FailOpen: errors.New("kms error")} err := RunCreateMasterKey( ctx, - mockService, + svc, logger, &bytes.Buffer{}, "test-key", diff --git a/cmd/app/commands/rotate_master_key.go b/cmd/app/commands/rotate_master_key.go index 260238c..36b545b 100644 --- a/cmd/app/commands/rotate_master_key.go +++ b/cmd/app/commands/rotate_master_key.go @@ -66,24 +66,16 @@ func RunRotateMasterKey( _, _ = fmt.Fprintln(writer) // Create KMS service and open keeper - keeperInterface, err := kmsService.OpenKeeper(ctx, kmsKeyURI) + keeper, err := kmsService.OpenKeeper(ctx, kmsKeyURI) if err != nil { return fmt.Errorf("failed to open KMS keeper: %w", err) } defer func() { - if closeErr := keeperInterface.Close(); closeErr != nil { + if closeErr := keeper.Close(); closeErr != nil { _, _ = fmt.Fprintf(writer, "Warning: failed to close KMS keeper: %v\n", closeErr) } }() - // Type assert to get Encrypt method - keeper, ok := keeperInterface.(interface { - Encrypt(ctx context.Context, plaintext []byte) ([]byte, error) - }) - if !ok { - return fmt.Errorf("KMS keeper does not support encryption") - } - // Encrypt master key with KMS ciphertext, err := keeper.Encrypt(ctx, masterKey) if err != nil { diff --git a/cmd/app/commands/rotate_master_key_test.go b/cmd/app/commands/rotate_master_key_test.go index c2add3c..7bcb7d4 100644 --- a/cmd/app/commands/rotate_master_key_test.go +++ b/cmd/app/commands/rotate_master_key_test.go @@ -6,8 +6,9 @@ import ( "log/slog" "testing" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + + "github.com/allisson/secrets/internal/keyring" ) func TestRunRotateMasterKey(t *testing.T) { @@ -19,17 +20,10 @@ func TestRunRotateMasterKey(t *testing.T) { existingActiveKeyID := "old-key" t.Run("success", func(t *testing.T) { - mockKMSService := &MockKMSService{} - mockKeeper := &MockKMSKeeper{} - - mockKMSService.On("OpenKeeper", ctx, kmsKeyURI).Return(mockKeeper, nil) - mockKeeper.On("Encrypt", ctx, mock.Anything).Return([]byte("new-ciphertext"), nil) - mockKeeper.On("Close").Return(nil) - var out bytes.Buffer err := RunRotateMasterKey( ctx, - mockKMSService, + keyring.NewFakeKMSService(), logger, &out, "new-key", @@ -40,25 +34,34 @@ func TestRunRotateMasterKey(t *testing.T) { ) require.NoError(t, err) - require.Contains(t, out.String(), "MASTER_KEYS=\"old-key:ciphertext,new-key:bmV3LWNpcGhlcnRleHQ=\"") + // The freshly generated master key is random, so the appended ciphertext + // is non-deterministic; assert the structure preserves the existing keys + // and appends the new one as active. + require.Contains(t, out.String(), "MASTER_KEYS=\"old-key:ciphertext,new-key:") require.Contains(t, out.String(), "ACTIVE_MASTER_KEY_ID=\"new-key\"") - mockKMSService.AssertExpectations(t) - mockKeeper.AssertExpectations(t) }) t.Run("missing-kms-params", func(t *testing.T) { - mockKMSService := &MockKMSService{} - err := RunRotateMasterKey(ctx, mockKMSService, logger, &bytes.Buffer{}, "new-key", "", "", "", "") + err := RunRotateMasterKey( + ctx, + keyring.NewFakeKMSService(), + logger, + &bytes.Buffer{}, + "new-key", + "", + "", + "", + "", + ) require.Error(t, err) require.Contains(t, err.Error(), "KMS_PROVIDER and KMS_KEY_URI are required") }) t.Run("missing-existing-keys", func(t *testing.T) { - mockKMSService := &MockKMSService{} err := RunRotateMasterKey( ctx, - mockKMSService, + keyring.NewFakeKMSService(), logger, &bytes.Buffer{}, "new-key", @@ -73,10 +76,9 @@ func TestRunRotateMasterKey(t *testing.T) { }) t.Run("invalid-active-key-id", func(t *testing.T) { - mockKMSService := &MockKMSService{} err := RunRotateMasterKey( ctx, - mockKMSService, + keyring.NewFakeKMSService(), logger, &bytes.Buffer{}, "new-key", diff --git a/internal/app/di_test.go b/internal/app/di_test.go index 2fe141a..d21c988 100644 --- a/internal/app/di_test.go +++ b/internal/app/di_test.go @@ -483,27 +483,11 @@ func TestContainerMasterKeyChainMultipleKeys(t *testing.T) { t.Fatal("expected non-nil master key chain") } - // Verify active key ID + // Verify active key ID. Per-key presence of a multi-key chain is covered + // by the keyring package's loadMasterKeyChainFromKMS tests (no DB needed). if masterKeyChain.ActiveMasterKeyID() != "key2" { t.Errorf("expected active key ID 'key2', got '%s'", masterKeyChain.ActiveMasterKeyID()) } - - // Verify both keys are accessible - key1Obj, ok := masterKeyChain.Get("key1") - if !ok { - t.Error("expected to find key1 in master key chain") - } - if key1Obj == nil { - t.Error("expected non-nil key1") - } - - key2Obj, ok := masterKeyChain.Get("key2") - if !ok { - t.Error("expected to find key2 in master key chain") - } - if key2Obj == nil { - t.Error("expected non-nil key2") - } } // TestContainerShutdownWithMasterKeyChain verifies that shutdown properly closes the master key chain. diff --git a/internal/auth/domain/mocks/mocks.go b/internal/auth/domain/mocks/mocks.go new file mode 100644 index 0000000..7b7c35b --- /dev/null +++ b/internal/auth/domain/mocks/mocks.go @@ -0,0 +1,1139 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "time" + + "github.com/allisson/secrets/internal/auth/domain" + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockClientRepository creates a new instance of MockClientRepository. 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 NewMockClientRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockClientRepository { + mock := &MockClientRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +// MockClientRepository is an autogenerated mock type for the ClientRepository type +type MockClientRepository struct { + mock.Mock +} + +type MockClientRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockClientRepository) EXPECT() *MockClientRepository_Expecter { + return &MockClientRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockClientRepository +func (_mock *MockClientRepository) Create(ctx context.Context, client *domain.Client) error { + ret := _mock.Called(ctx, client) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Client) error); ok { + r0 = returnFunc(ctx, client) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockClientRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockClientRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - client *domain.Client +func (_e *MockClientRepository_Expecter) Create(ctx any, client any) *MockClientRepository_Create_Call { + return &MockClientRepository_Create_Call{Call: _e.mock.On("Create", ctx, client)} +} + +func (_c *MockClientRepository_Create_Call) Run(run func(ctx context.Context, client *domain.Client)) *MockClientRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *domain.Client + if args[1] != nil { + arg1 = args[1].(*domain.Client) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockClientRepository_Create_Call) Return(err error) *MockClientRepository_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockClientRepository_Create_Call) RunAndReturn(run func(ctx context.Context, client *domain.Client) error) *MockClientRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function for the type MockClientRepository +func (_mock *MockClientRepository) Get(ctx context.Context, clientID uuid.UUID) (*domain.Client, error) { + ret := _mock.Called(ctx, clientID) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *domain.Client + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (*domain.Client, error)); ok { + return returnFunc(ctx, clientID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) *domain.Client); ok { + r0 = returnFunc(ctx, clientID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.Client) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { + r1 = returnFunc(ctx, clientID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockClientRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockClientRepository_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - clientID uuid.UUID +func (_e *MockClientRepository_Expecter) Get(ctx any, clientID any) *MockClientRepository_Get_Call { + return &MockClientRepository_Get_Call{Call: _e.mock.On("Get", ctx, clientID)} +} + +func (_c *MockClientRepository_Get_Call) Run(run func(ctx context.Context, clientID uuid.UUID)) *MockClientRepository_Get_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 *MockClientRepository_Get_Call) Return(client *domain.Client, err error) *MockClientRepository_Get_Call { + _c.Call.Return(client, err) + return _c +} + +func (_c *MockClientRepository_Get_Call) RunAndReturn(run func(ctx context.Context, clientID uuid.UUID) (*domain.Client, error)) *MockClientRepository_Get_Call { + _c.Call.Return(run) + return _c +} + +// ListCursor provides a mock function for the type MockClientRepository +func (_mock *MockClientRepository) ListCursor(ctx context.Context, afterID *uuid.UUID, limit int) ([]*domain.Client, error) { + ret := _mock.Called(ctx, afterID, limit) + + if len(ret) == 0 { + panic("no return value specified for ListCursor") + } + + var r0 []*domain.Client + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, int) ([]*domain.Client, error)); ok { + return returnFunc(ctx, afterID, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, int) []*domain.Client); ok { + r0 = returnFunc(ctx, afterID, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*domain.Client) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, *uuid.UUID, int) error); ok { + r1 = returnFunc(ctx, afterID, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockClientRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' +type MockClientRepository_ListCursor_Call struct { + *mock.Call +} + +// ListCursor is a helper method to define mock.On call +// - ctx context.Context +// - afterID *uuid.UUID +// - limit int +func (_e *MockClientRepository_Expecter) ListCursor(ctx any, afterID any, limit any) *MockClientRepository_ListCursor_Call { + return &MockClientRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterID, limit)} +} + +func (_c *MockClientRepository_ListCursor_Call) Run(run func(ctx context.Context, afterID *uuid.UUID, limit int)) *MockClientRepository_ListCursor_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 int + if args[2] != nil { + arg2 = args[2].(int) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockClientRepository_ListCursor_Call) Return(clients []*domain.Client, err error) *MockClientRepository_ListCursor_Call { + _c.Call.Return(clients, err) + return _c +} + +func (_c *MockClientRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterID *uuid.UUID, limit int) ([]*domain.Client, error)) *MockClientRepository_ListCursor_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function for the type MockClientRepository +func (_mock *MockClientRepository) Update(ctx context.Context, client *domain.Client) error { + ret := _mock.Called(ctx, client) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Client) error); ok { + r0 = returnFunc(ctx, client) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockClientRepository_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockClientRepository_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - client *domain.Client +func (_e *MockClientRepository_Expecter) Update(ctx any, client any) *MockClientRepository_Update_Call { + return &MockClientRepository_Update_Call{Call: _e.mock.On("Update", ctx, client)} +} + +func (_c *MockClientRepository_Update_Call) Run(run func(ctx context.Context, client *domain.Client)) *MockClientRepository_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *domain.Client + if args[1] != nil { + arg1 = args[1].(*domain.Client) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockClientRepository_Update_Call) Return(err error) *MockClientRepository_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockClientRepository_Update_Call) RunAndReturn(run func(ctx context.Context, client *domain.Client) error) *MockClientRepository_Update_Call { + _c.Call.Return(run) + return _c +} + +// UpdateLockState provides a mock function for the type MockClientRepository +func (_mock *MockClientRepository) UpdateLockState(ctx context.Context, clientID uuid.UUID, failedAttempts int, lockedUntil *time.Time) error { + ret := _mock.Called(ctx, clientID, failedAttempts, lockedUntil) + + if len(ret) == 0 { + panic("no return value specified for UpdateLockState") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, int, *time.Time) error); ok { + r0 = returnFunc(ctx, clientID, failedAttempts, lockedUntil) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockClientRepository_UpdateLockState_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateLockState' +type MockClientRepository_UpdateLockState_Call struct { + *mock.Call +} + +// UpdateLockState is a helper method to define mock.On call +// - ctx context.Context +// - clientID uuid.UUID +// - failedAttempts int +// - lockedUntil *time.Time +func (_e *MockClientRepository_Expecter) UpdateLockState(ctx any, clientID any, failedAttempts any, lockedUntil any) *MockClientRepository_UpdateLockState_Call { + return &MockClientRepository_UpdateLockState_Call{Call: _e.mock.On("UpdateLockState", ctx, clientID, failedAttempts, lockedUntil)} +} + +func (_c *MockClientRepository_UpdateLockState_Call) Run(run func(ctx context.Context, clientID uuid.UUID, failedAttempts int, lockedUntil *time.Time)) *MockClientRepository_UpdateLockState_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 int + if args[2] != nil { + arg2 = args[2].(int) + } + var arg3 *time.Time + if args[3] != nil { + arg3 = args[3].(*time.Time) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockClientRepository_UpdateLockState_Call) Return(err error) *MockClientRepository_UpdateLockState_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockClientRepository_UpdateLockState_Call) RunAndReturn(run func(ctx context.Context, clientID uuid.UUID, failedAttempts int, lockedUntil *time.Time) error) *MockClientRepository_UpdateLockState_Call { + _c.Call.Return(run) + return _c +} + +// NewMockTokenRepository creates a new instance of MockTokenRepository. 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 NewMockTokenRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockTokenRepository { + mock := &MockTokenRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +// MockTokenRepository is an autogenerated mock type for the TokenRepository type +type MockTokenRepository struct { + mock.Mock +} + +type MockTokenRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockTokenRepository) EXPECT() *MockTokenRepository_Expecter { + return &MockTokenRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) Create(ctx context.Context, token *domain.Token) error { + ret := _mock.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Token) error); ok { + r0 = returnFunc(ctx, token) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTokenRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockTokenRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - token *domain.Token +func (_e *MockTokenRepository_Expecter) Create(ctx any, token any) *MockTokenRepository_Create_Call { + return &MockTokenRepository_Create_Call{Call: _e.mock.On("Create", ctx, token)} +} + +func (_c *MockTokenRepository_Create_Call) Run(run func(ctx context.Context, token *domain.Token)) *MockTokenRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *domain.Token + if args[1] != nil { + arg1 = args[1].(*domain.Token) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_Create_Call) Return(err error) *MockTokenRepository_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTokenRepository_Create_Call) RunAndReturn(run func(ctx context.Context, token *domain.Token) error) *MockTokenRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) Get(ctx context.Context, tokenID uuid.UUID) (*domain.Token, error) { + ret := _mock.Called(ctx, tokenID) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *domain.Token + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (*domain.Token, error)); ok { + return returnFunc(ctx, tokenID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) *domain.Token); ok { + r0 = returnFunc(ctx, tokenID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.Token) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { + r1 = returnFunc(ctx, tokenID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockTokenRepository_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - tokenID uuid.UUID +func (_e *MockTokenRepository_Expecter) Get(ctx any, tokenID any) *MockTokenRepository_Get_Call { + return &MockTokenRepository_Get_Call{Call: _e.mock.On("Get", ctx, tokenID)} +} + +func (_c *MockTokenRepository_Get_Call) Run(run func(ctx context.Context, tokenID uuid.UUID)) *MockTokenRepository_Get_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 *MockTokenRepository_Get_Call) Return(token *domain.Token, err error) *MockTokenRepository_Get_Call { + _c.Call.Return(token, err) + return _c +} + +func (_c *MockTokenRepository_Get_Call) RunAndReturn(run func(ctx context.Context, tokenID uuid.UUID) (*domain.Token, error)) *MockTokenRepository_Get_Call { + _c.Call.Return(run) + return _c +} + +// GetByTokenHash provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) GetByTokenHash(ctx context.Context, tokenHash string) (*domain.Token, error) { + ret := _mock.Called(ctx, tokenHash) + + if len(ret) == 0 { + panic("no return value specified for GetByTokenHash") + } + + var r0 *domain.Token + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.Token, error)); ok { + return returnFunc(ctx, tokenHash) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.Token); ok { + r0 = returnFunc(ctx, tokenHash) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.Token) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, tokenHash) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenRepository_GetByTokenHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByTokenHash' +type MockTokenRepository_GetByTokenHash_Call struct { + *mock.Call +} + +// GetByTokenHash is a helper method to define mock.On call +// - ctx context.Context +// - tokenHash string +func (_e *MockTokenRepository_Expecter) GetByTokenHash(ctx any, tokenHash any) *MockTokenRepository_GetByTokenHash_Call { + return &MockTokenRepository_GetByTokenHash_Call{Call: _e.mock.On("GetByTokenHash", ctx, tokenHash)} +} + +func (_c *MockTokenRepository_GetByTokenHash_Call) Run(run func(ctx context.Context, tokenHash string)) *MockTokenRepository_GetByTokenHash_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_GetByTokenHash_Call) Return(token *domain.Token, err error) *MockTokenRepository_GetByTokenHash_Call { + _c.Call.Return(token, err) + return _c +} + +func (_c *MockTokenRepository_GetByTokenHash_Call) RunAndReturn(run func(ctx context.Context, tokenHash string) (*domain.Token, error)) *MockTokenRepository_GetByTokenHash_Call { + _c.Call.Return(run) + return _c +} + +// PurgeExpiredAndRevoked provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) PurgeExpiredAndRevoked(ctx context.Context, olderThan time.Time) (int64, error) { + ret := _mock.Called(ctx, olderThan) + + if len(ret) == 0 { + panic("no return value specified for PurgeExpiredAndRevoked") + } + + var r0 int64 + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) (int64, error)); ok { + return returnFunc(ctx, olderThan) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) int64); ok { + r0 = returnFunc(ctx, olderThan) + } else { + r0 = ret.Get(0).(int64) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time) error); ok { + r1 = returnFunc(ctx, olderThan) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenRepository_PurgeExpiredAndRevoked_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PurgeExpiredAndRevoked' +type MockTokenRepository_PurgeExpiredAndRevoked_Call struct { + *mock.Call +} + +// PurgeExpiredAndRevoked is a helper method to define mock.On call +// - ctx context.Context +// - olderThan time.Time +func (_e *MockTokenRepository_Expecter) PurgeExpiredAndRevoked(ctx any, olderThan any) *MockTokenRepository_PurgeExpiredAndRevoked_Call { + return &MockTokenRepository_PurgeExpiredAndRevoked_Call{Call: _e.mock.On("PurgeExpiredAndRevoked", ctx, olderThan)} +} + +func (_c *MockTokenRepository_PurgeExpiredAndRevoked_Call) Run(run func(ctx context.Context, olderThan time.Time)) *MockTokenRepository_PurgeExpiredAndRevoked_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 time.Time + if args[1] != nil { + arg1 = args[1].(time.Time) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_PurgeExpiredAndRevoked_Call) Return(n int64, err error) *MockTokenRepository_PurgeExpiredAndRevoked_Call { + _c.Call.Return(n, err) + return _c +} + +func (_c *MockTokenRepository_PurgeExpiredAndRevoked_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time) (int64, error)) *MockTokenRepository_PurgeExpiredAndRevoked_Call { + _c.Call.Return(run) + return _c +} + +// RevokeByClientID provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) RevokeByClientID(ctx context.Context, clientID uuid.UUID) error { + ret := _mock.Called(ctx, clientID) + + if len(ret) == 0 { + panic("no return value specified for RevokeByClientID") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) error); ok { + r0 = returnFunc(ctx, clientID) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTokenRepository_RevokeByClientID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RevokeByClientID' +type MockTokenRepository_RevokeByClientID_Call struct { + *mock.Call +} + +// RevokeByClientID is a helper method to define mock.On call +// - ctx context.Context +// - clientID uuid.UUID +func (_e *MockTokenRepository_Expecter) RevokeByClientID(ctx any, clientID any) *MockTokenRepository_RevokeByClientID_Call { + return &MockTokenRepository_RevokeByClientID_Call{Call: _e.mock.On("RevokeByClientID", ctx, clientID)} +} + +func (_c *MockTokenRepository_RevokeByClientID_Call) Run(run func(ctx context.Context, clientID uuid.UUID)) *MockTokenRepository_RevokeByClientID_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 *MockTokenRepository_RevokeByClientID_Call) Return(err error) *MockTokenRepository_RevokeByClientID_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTokenRepository_RevokeByClientID_Call) RunAndReturn(run func(ctx context.Context, clientID uuid.UUID) error) *MockTokenRepository_RevokeByClientID_Call { + _c.Call.Return(run) + return _c +} + +// RevokeByTokenID provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) RevokeByTokenID(ctx context.Context, tokenID uuid.UUID) error { + ret := _mock.Called(ctx, tokenID) + + if len(ret) == 0 { + panic("no return value specified for RevokeByTokenID") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) error); ok { + r0 = returnFunc(ctx, tokenID) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTokenRepository_RevokeByTokenID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RevokeByTokenID' +type MockTokenRepository_RevokeByTokenID_Call struct { + *mock.Call +} + +// RevokeByTokenID is a helper method to define mock.On call +// - ctx context.Context +// - tokenID uuid.UUID +func (_e *MockTokenRepository_Expecter) RevokeByTokenID(ctx any, tokenID any) *MockTokenRepository_RevokeByTokenID_Call { + return &MockTokenRepository_RevokeByTokenID_Call{Call: _e.mock.On("RevokeByTokenID", ctx, tokenID)} +} + +func (_c *MockTokenRepository_RevokeByTokenID_Call) Run(run func(ctx context.Context, tokenID uuid.UUID)) *MockTokenRepository_RevokeByTokenID_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 *MockTokenRepository_RevokeByTokenID_Call) Return(err error) *MockTokenRepository_RevokeByTokenID_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTokenRepository_RevokeByTokenID_Call) RunAndReturn(run func(ctx context.Context, tokenID uuid.UUID) error) *MockTokenRepository_RevokeByTokenID_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) Update(ctx context.Context, token *domain.Token) error { + ret := _mock.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Token) error); ok { + r0 = returnFunc(ctx, token) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTokenRepository_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockTokenRepository_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - token *domain.Token +func (_e *MockTokenRepository_Expecter) Update(ctx any, token any) *MockTokenRepository_Update_Call { + return &MockTokenRepository_Update_Call{Call: _e.mock.On("Update", ctx, token)} +} + +func (_c *MockTokenRepository_Update_Call) Run(run func(ctx context.Context, token *domain.Token)) *MockTokenRepository_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *domain.Token + if args[1] != nil { + arg1 = args[1].(*domain.Token) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_Update_Call) Return(err error) *MockTokenRepository_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTokenRepository_Update_Call) RunAndReturn(run func(ctx context.Context, token *domain.Token) error) *MockTokenRepository_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockAuditLogRepository creates a new instance of MockAuditLogRepository. 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 NewMockAuditLogRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockAuditLogRepository { + mock := &MockAuditLogRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +// MockAuditLogRepository is an autogenerated mock type for the AuditLogRepository type +type MockAuditLogRepository struct { + mock.Mock +} + +type MockAuditLogRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockAuditLogRepository) EXPECT() *MockAuditLogRepository_Expecter { + return &MockAuditLogRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockAuditLogRepository +func (_mock *MockAuditLogRepository) Create(ctx context.Context, auditLog *domain.AuditLog) error { + ret := _mock.Called(ctx, auditLog) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.AuditLog) error); ok { + r0 = returnFunc(ctx, auditLog) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockAuditLogRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockAuditLogRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - auditLog *domain.AuditLog +func (_e *MockAuditLogRepository_Expecter) Create(ctx any, auditLog any) *MockAuditLogRepository_Create_Call { + return &MockAuditLogRepository_Create_Call{Call: _e.mock.On("Create", ctx, auditLog)} +} + +func (_c *MockAuditLogRepository_Create_Call) Run(run func(ctx context.Context, auditLog *domain.AuditLog)) *MockAuditLogRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *domain.AuditLog + if args[1] != nil { + arg1 = args[1].(*domain.AuditLog) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockAuditLogRepository_Create_Call) Return(err error) *MockAuditLogRepository_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockAuditLogRepository_Create_Call) RunAndReturn(run func(ctx context.Context, auditLog *domain.AuditLog) error) *MockAuditLogRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// DeleteOlderThan provides a mock function for the type MockAuditLogRepository +func (_mock *MockAuditLogRepository) DeleteOlderThan(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error) { + ret := _mock.Called(ctx, olderThan, dryRun) + + if len(ret) == 0 { + panic("no return value specified for DeleteOlderThan") + } + + var r0 int64 + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) (int64, error)); ok { + return returnFunc(ctx, olderThan, dryRun) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) int64); ok { + r0 = returnFunc(ctx, olderThan, dryRun) + } else { + r0 = ret.Get(0).(int64) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, bool) error); ok { + r1 = returnFunc(ctx, olderThan, dryRun) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAuditLogRepository_DeleteOlderThan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteOlderThan' +type MockAuditLogRepository_DeleteOlderThan_Call struct { + *mock.Call +} + +// DeleteOlderThan is a helper method to define mock.On call +// - ctx context.Context +// - olderThan time.Time +// - dryRun bool +func (_e *MockAuditLogRepository_Expecter) DeleteOlderThan(ctx any, olderThan any, dryRun any) *MockAuditLogRepository_DeleteOlderThan_Call { + return &MockAuditLogRepository_DeleteOlderThan_Call{Call: _e.mock.On("DeleteOlderThan", ctx, olderThan, dryRun)} +} + +func (_c *MockAuditLogRepository_DeleteOlderThan_Call) Run(run func(ctx context.Context, olderThan time.Time, dryRun bool)) *MockAuditLogRepository_DeleteOlderThan_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 time.Time + if args[1] != nil { + arg1 = args[1].(time.Time) + } + var arg2 bool + if args[2] != nil { + arg2 = args[2].(bool) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockAuditLogRepository_DeleteOlderThan_Call) Return(n int64, err error) *MockAuditLogRepository_DeleteOlderThan_Call { + _c.Call.Return(n, err) + return _c +} + +func (_c *MockAuditLogRepository_DeleteOlderThan_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)) *MockAuditLogRepository_DeleteOlderThan_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function for the type MockAuditLogRepository +func (_mock *MockAuditLogRepository) Get(ctx context.Context, id uuid.UUID) (*domain.AuditLog, error) { + ret := _mock.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *domain.AuditLog + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (*domain.AuditLog, error)); ok { + return returnFunc(ctx, id) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) *domain.AuditLog); ok { + r0 = returnFunc(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.AuditLog) + } + } + 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 +} + +// MockAuditLogRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockAuditLogRepository_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - id uuid.UUID +func (_e *MockAuditLogRepository_Expecter) Get(ctx any, id any) *MockAuditLogRepository_Get_Call { + return &MockAuditLogRepository_Get_Call{Call: _e.mock.On("Get", ctx, id)} +} + +func (_c *MockAuditLogRepository_Get_Call) Run(run func(ctx context.Context, id uuid.UUID)) *MockAuditLogRepository_Get_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 *MockAuditLogRepository_Get_Call) Return(auditLog *domain.AuditLog, err error) *MockAuditLogRepository_Get_Call { + _c.Call.Return(auditLog, err) + return _c +} + +func (_c *MockAuditLogRepository_Get_Call) RunAndReturn(run func(ctx context.Context, id uuid.UUID) (*domain.AuditLog, error)) *MockAuditLogRepository_Get_Call { + _c.Call.Return(run) + return _c +} + +// ListCursor provides a mock function for the type MockAuditLogRepository +func (_mock *MockAuditLogRepository) ListCursor(ctx context.Context, afterID *uuid.UUID, limit int, createdAtFrom *time.Time, createdAtTo *time.Time, clientID *uuid.UUID) ([]*domain.AuditLog, error) { + ret := _mock.Called(ctx, afterID, limit, createdAtFrom, createdAtTo, clientID) + + if len(ret) == 0 { + panic("no return value specified for ListCursor") + } + + var r0 []*domain.AuditLog + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, int, *time.Time, *time.Time, *uuid.UUID) ([]*domain.AuditLog, error)); ok { + return returnFunc(ctx, afterID, limit, createdAtFrom, createdAtTo, clientID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, int, *time.Time, *time.Time, *uuid.UUID) []*domain.AuditLog); ok { + r0 = returnFunc(ctx, afterID, limit, createdAtFrom, createdAtTo, clientID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*domain.AuditLog) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, *uuid.UUID, int, *time.Time, *time.Time, *uuid.UUID) error); ok { + r1 = returnFunc(ctx, afterID, limit, createdAtFrom, createdAtTo, clientID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAuditLogRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' +type MockAuditLogRepository_ListCursor_Call struct { + *mock.Call +} + +// ListCursor is a helper method to define mock.On call +// - ctx context.Context +// - afterID *uuid.UUID +// - limit int +// - createdAtFrom *time.Time +// - createdAtTo *time.Time +// - clientID *uuid.UUID +func (_e *MockAuditLogRepository_Expecter) ListCursor(ctx any, afterID any, limit any, createdAtFrom any, createdAtTo any, clientID any) *MockAuditLogRepository_ListCursor_Call { + return &MockAuditLogRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterID, limit, createdAtFrom, createdAtTo, clientID)} +} + +func (_c *MockAuditLogRepository_ListCursor_Call) Run(run func(ctx context.Context, afterID *uuid.UUID, limit int, createdAtFrom *time.Time, createdAtTo *time.Time, clientID *uuid.UUID)) *MockAuditLogRepository_ListCursor_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 int + if args[2] != nil { + arg2 = args[2].(int) + } + var arg3 *time.Time + if args[3] != nil { + arg3 = args[3].(*time.Time) + } + var arg4 *time.Time + if args[4] != nil { + arg4 = args[4].(*time.Time) + } + var arg5 *uuid.UUID + if args[5] != nil { + arg5 = args[5].(*uuid.UUID) + } + run( + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + ) + }) + return _c +} + +func (_c *MockAuditLogRepository_ListCursor_Call) Return(auditLogs []*domain.AuditLog, err error) *MockAuditLogRepository_ListCursor_Call { + _c.Call.Return(auditLogs, err) + return _c +} + +func (_c *MockAuditLogRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterID *uuid.UUID, limit int, createdAtFrom *time.Time, createdAtTo *time.Time, clientID *uuid.UUID) ([]*domain.AuditLog, error)) *MockAuditLogRepository_ListCursor_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/auth/usecase/client_usecase_test.go b/internal/auth/usecase/client_usecase_test.go index 047783f..1fe1885 100644 --- a/internal/auth/usecase/client_usecase_test.go +++ b/internal/auth/usecase/client_usecase_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/mock" authDomain "github.com/allisson/secrets/internal/auth/domain" + domainMocks "github.com/allisson/secrets/internal/auth/domain/mocks" "github.com/allisson/secrets/internal/auth/usecase" usecaseMocks "github.com/allisson/secrets/internal/auth/usecase/mocks" databaseMocks "github.com/allisson/secrets/internal/database/mocks" @@ -21,8 +22,8 @@ func TestClientUseCase_Create(t *testing.T) { t.Run("Success_CreateNewClient", func(t *testing.T) { // Setup mocks mockTxManager := databaseMocks.NewMockTxManager(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) var capturedPlain string @@ -69,8 +70,8 @@ func TestClientUseCase_Update(t *testing.T) { t.Run("Success_UpdateClient", func(t *testing.T) { mockTxManager := databaseMocks.NewMockTxManager(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) hashSecret := func(plain string) (string, error) { return "hashed:" + plain, nil } @@ -106,8 +107,8 @@ func TestClientUseCase_Get(t *testing.T) { t.Run("Success_GetClient", func(t *testing.T) { mockTxManager := databaseMocks.NewMockTxManager(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) hashSecret := func(plain string) (string, error) { return "hashed:" + plain, nil } @@ -138,8 +139,8 @@ func TestClientUseCase_RevokeTokens(t *testing.T) { t.Run("Success_RevokeTokens", func(t *testing.T) { mockTxManager := databaseMocks.NewMockTxManager(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) hashSecret := func(plain string) (string, error) { return "hashed:" + plain, nil } uc := usecase.NewClientUseCase( @@ -165,8 +166,8 @@ func TestClientUseCase_RevokeTokens(t *testing.T) { t.Run("Error_ClientNotFound", func(t *testing.T) { mockTxManager := databaseMocks.NewMockTxManager(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) hashSecret := func(plain string) (string, error) { return "hashed:" + plain, nil } uc := usecase.NewClientUseCase( @@ -190,8 +191,8 @@ func TestClientUseCase_Delete(t *testing.T) { t.Run("Success_SoftDeleteClient", func(t *testing.T) { mockTxManager := databaseMocks.NewMockTxManager(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) hashSecret := func(plain string) (string, error) { return "hashed:" + plain, nil } @@ -223,8 +224,8 @@ func TestClientUseCase_Unlock(t *testing.T) { t.Run("Success", func(t *testing.T) { mockTxManager := databaseMocks.NewMockTxManager(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) hashSecret := func(plain string) (string, error) { return "hashed:" + plain, nil } @@ -254,8 +255,8 @@ func TestClientUseCase_RotateSecret(t *testing.T) { t.Run("Success_RotateClientSecret", func(t *testing.T) { mockTxManager := databaseMocks.NewMockTxManager(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) var capturedPlain string @@ -306,8 +307,8 @@ func TestClientUseCase_RotateSecret(t *testing.T) { t.Run("Error_ClientNotFound", func(t *testing.T) { mockTxManager := databaseMocks.NewMockTxManager(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) hashSecret := func(plain string) (string, error) { return "hashed:" + plain, nil } diff --git a/internal/auth/usecase/mocks/mocks.go b/internal/auth/usecase/mocks/mocks.go index c3f39ae..a1f01f3 100644 --- a/internal/auth/usecase/mocks/mocks.go +++ b/internal/auth/usecase/mocks/mocks.go @@ -14,1131 +14,6 @@ import ( mock "github.com/stretchr/testify/mock" ) -// NewMockClientRepository creates a new instance of MockClientRepository. 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 NewMockClientRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *MockClientRepository { - mock := &MockClientRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - -// MockClientRepository is an autogenerated mock type for the ClientRepository type -type MockClientRepository struct { - mock.Mock -} - -type MockClientRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *MockClientRepository) EXPECT() *MockClientRepository_Expecter { - return &MockClientRepository_Expecter{mock: &_m.Mock} -} - -// Create provides a mock function for the type MockClientRepository -func (_mock *MockClientRepository) Create(ctx context.Context, client *domain.Client) error { - ret := _mock.Called(ctx, client) - - if len(ret) == 0 { - panic("no return value specified for Create") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Client) error); ok { - r0 = returnFunc(ctx, client) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockClientRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' -type MockClientRepository_Create_Call struct { - *mock.Call -} - -// Create is a helper method to define mock.On call -// - ctx context.Context -// - client *domain.Client -func (_e *MockClientRepository_Expecter) Create(ctx interface{}, client interface{}) *MockClientRepository_Create_Call { - return &MockClientRepository_Create_Call{Call: _e.mock.On("Create", ctx, client)} -} - -func (_c *MockClientRepository_Create_Call) Run(run func(ctx context.Context, client *domain.Client)) *MockClientRepository_Create_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *domain.Client - if args[1] != nil { - arg1 = args[1].(*domain.Client) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockClientRepository_Create_Call) Return(err error) *MockClientRepository_Create_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockClientRepository_Create_Call) RunAndReturn(run func(ctx context.Context, client *domain.Client) error) *MockClientRepository_Create_Call { - _c.Call.Return(run) - return _c -} - -// Get provides a mock function for the type MockClientRepository -func (_mock *MockClientRepository) Get(ctx context.Context, clientID uuid.UUID) (*domain.Client, error) { - ret := _mock.Called(ctx, clientID) - - if len(ret) == 0 { - panic("no return value specified for Get") - } - - var r0 *domain.Client - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (*domain.Client, error)); ok { - return returnFunc(ctx, clientID) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) *domain.Client); ok { - r0 = returnFunc(ctx, clientID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.Client) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { - r1 = returnFunc(ctx, clientID) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockClientRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' -type MockClientRepository_Get_Call struct { - *mock.Call -} - -// Get is a helper method to define mock.On call -// - ctx context.Context -// - clientID uuid.UUID -func (_e *MockClientRepository_Expecter) Get(ctx interface{}, clientID interface{}) *MockClientRepository_Get_Call { - return &MockClientRepository_Get_Call{Call: _e.mock.On("Get", ctx, clientID)} -} - -func (_c *MockClientRepository_Get_Call) Run(run func(ctx context.Context, clientID uuid.UUID)) *MockClientRepository_Get_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 *MockClientRepository_Get_Call) Return(client *domain.Client, err error) *MockClientRepository_Get_Call { - _c.Call.Return(client, err) - return _c -} - -func (_c *MockClientRepository_Get_Call) RunAndReturn(run func(ctx context.Context, clientID uuid.UUID) (*domain.Client, error)) *MockClientRepository_Get_Call { - _c.Call.Return(run) - return _c -} - -// ListCursor provides a mock function for the type MockClientRepository -func (_mock *MockClientRepository) ListCursor(ctx context.Context, afterID *uuid.UUID, limit int) ([]*domain.Client, error) { - ret := _mock.Called(ctx, afterID, limit) - - if len(ret) == 0 { - panic("no return value specified for ListCursor") - } - - var r0 []*domain.Client - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, int) ([]*domain.Client, error)); ok { - return returnFunc(ctx, afterID, limit) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, int) []*domain.Client); ok { - r0 = returnFunc(ctx, afterID, limit) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*domain.Client) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, *uuid.UUID, int) error); ok { - r1 = returnFunc(ctx, afterID, limit) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockClientRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' -type MockClientRepository_ListCursor_Call struct { - *mock.Call -} - -// ListCursor is a helper method to define mock.On call -// - ctx context.Context -// - afterID *uuid.UUID -// - limit int -func (_e *MockClientRepository_Expecter) ListCursor(ctx interface{}, afterID interface{}, limit interface{}) *MockClientRepository_ListCursor_Call { - return &MockClientRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterID, limit)} -} - -func (_c *MockClientRepository_ListCursor_Call) Run(run func(ctx context.Context, afterID *uuid.UUID, limit int)) *MockClientRepository_ListCursor_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 int - if args[2] != nil { - arg2 = args[2].(int) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockClientRepository_ListCursor_Call) Return(clients []*domain.Client, err error) *MockClientRepository_ListCursor_Call { - _c.Call.Return(clients, err) - return _c -} - -func (_c *MockClientRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterID *uuid.UUID, limit int) ([]*domain.Client, error)) *MockClientRepository_ListCursor_Call { - _c.Call.Return(run) - return _c -} - -// Update provides a mock function for the type MockClientRepository -func (_mock *MockClientRepository) Update(ctx context.Context, client *domain.Client) error { - ret := _mock.Called(ctx, client) - - if len(ret) == 0 { - panic("no return value specified for Update") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Client) error); ok { - r0 = returnFunc(ctx, client) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockClientRepository_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' -type MockClientRepository_Update_Call struct { - *mock.Call -} - -// Update is a helper method to define mock.On call -// - ctx context.Context -// - client *domain.Client -func (_e *MockClientRepository_Expecter) Update(ctx interface{}, client interface{}) *MockClientRepository_Update_Call { - return &MockClientRepository_Update_Call{Call: _e.mock.On("Update", ctx, client)} -} - -func (_c *MockClientRepository_Update_Call) Run(run func(ctx context.Context, client *domain.Client)) *MockClientRepository_Update_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *domain.Client - if args[1] != nil { - arg1 = args[1].(*domain.Client) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockClientRepository_Update_Call) Return(err error) *MockClientRepository_Update_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockClientRepository_Update_Call) RunAndReturn(run func(ctx context.Context, client *domain.Client) error) *MockClientRepository_Update_Call { - _c.Call.Return(run) - return _c -} - -// UpdateLockState provides a mock function for the type MockClientRepository -func (_mock *MockClientRepository) UpdateLockState(ctx context.Context, clientID uuid.UUID, failedAttempts int, lockedUntil *time.Time) error { - ret := _mock.Called(ctx, clientID, failedAttempts, lockedUntil) - - if len(ret) == 0 { - panic("no return value specified for UpdateLockState") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, int, *time.Time) error); ok { - r0 = returnFunc(ctx, clientID, failedAttempts, lockedUntil) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockClientRepository_UpdateLockState_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateLockState' -type MockClientRepository_UpdateLockState_Call struct { - *mock.Call -} - -// UpdateLockState is a helper method to define mock.On call -// - ctx context.Context -// - clientID uuid.UUID -// - failedAttempts int -// - lockedUntil *time.Time -func (_e *MockClientRepository_Expecter) UpdateLockState(ctx interface{}, clientID interface{}, failedAttempts interface{}, lockedUntil interface{}) *MockClientRepository_UpdateLockState_Call { - return &MockClientRepository_UpdateLockState_Call{Call: _e.mock.On("UpdateLockState", ctx, clientID, failedAttempts, lockedUntil)} -} - -func (_c *MockClientRepository_UpdateLockState_Call) Run(run func(ctx context.Context, clientID uuid.UUID, failedAttempts int, lockedUntil *time.Time)) *MockClientRepository_UpdateLockState_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 int - if args[2] != nil { - arg2 = args[2].(int) - } - var arg3 *time.Time - if args[3] != nil { - arg3 = args[3].(*time.Time) - } - run( - arg0, - arg1, - arg2, - arg3, - ) - }) - return _c -} - -func (_c *MockClientRepository_UpdateLockState_Call) Return(err error) *MockClientRepository_UpdateLockState_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockClientRepository_UpdateLockState_Call) RunAndReturn(run func(ctx context.Context, clientID uuid.UUID, failedAttempts int, lockedUntil *time.Time) error) *MockClientRepository_UpdateLockState_Call { - _c.Call.Return(run) - return _c -} - -// NewMockTokenRepository creates a new instance of MockTokenRepository. 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 NewMockTokenRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *MockTokenRepository { - mock := &MockTokenRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - -// MockTokenRepository is an autogenerated mock type for the TokenRepository type -type MockTokenRepository struct { - mock.Mock -} - -type MockTokenRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *MockTokenRepository) EXPECT() *MockTokenRepository_Expecter { - return &MockTokenRepository_Expecter{mock: &_m.Mock} -} - -// Create provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) Create(ctx context.Context, token *domain.Token) error { - ret := _mock.Called(ctx, token) - - if len(ret) == 0 { - panic("no return value specified for Create") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Token) error); ok { - r0 = returnFunc(ctx, token) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTokenRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' -type MockTokenRepository_Create_Call struct { - *mock.Call -} - -// Create is a helper method to define mock.On call -// - ctx context.Context -// - token *domain.Token -func (_e *MockTokenRepository_Expecter) Create(ctx interface{}, token interface{}) *MockTokenRepository_Create_Call { - return &MockTokenRepository_Create_Call{Call: _e.mock.On("Create", ctx, token)} -} - -func (_c *MockTokenRepository_Create_Call) Run(run func(ctx context.Context, token *domain.Token)) *MockTokenRepository_Create_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *domain.Token - if args[1] != nil { - arg1 = args[1].(*domain.Token) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_Create_Call) Return(err error) *MockTokenRepository_Create_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTokenRepository_Create_Call) RunAndReturn(run func(ctx context.Context, token *domain.Token) error) *MockTokenRepository_Create_Call { - _c.Call.Return(run) - return _c -} - -// Get provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) Get(ctx context.Context, tokenID uuid.UUID) (*domain.Token, error) { - ret := _mock.Called(ctx, tokenID) - - if len(ret) == 0 { - panic("no return value specified for Get") - } - - var r0 *domain.Token - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (*domain.Token, error)); ok { - return returnFunc(ctx, tokenID) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) *domain.Token); ok { - r0 = returnFunc(ctx, tokenID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.Token) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { - r1 = returnFunc(ctx, tokenID) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' -type MockTokenRepository_Get_Call struct { - *mock.Call -} - -// Get is a helper method to define mock.On call -// - ctx context.Context -// - tokenID uuid.UUID -func (_e *MockTokenRepository_Expecter) Get(ctx interface{}, tokenID interface{}) *MockTokenRepository_Get_Call { - return &MockTokenRepository_Get_Call{Call: _e.mock.On("Get", ctx, tokenID)} -} - -func (_c *MockTokenRepository_Get_Call) Run(run func(ctx context.Context, tokenID uuid.UUID)) *MockTokenRepository_Get_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 *MockTokenRepository_Get_Call) Return(token *domain.Token, err error) *MockTokenRepository_Get_Call { - _c.Call.Return(token, err) - return _c -} - -func (_c *MockTokenRepository_Get_Call) RunAndReturn(run func(ctx context.Context, tokenID uuid.UUID) (*domain.Token, error)) *MockTokenRepository_Get_Call { - _c.Call.Return(run) - return _c -} - -// GetByTokenHash provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) GetByTokenHash(ctx context.Context, tokenHash string) (*domain.Token, error) { - ret := _mock.Called(ctx, tokenHash) - - if len(ret) == 0 { - panic("no return value specified for GetByTokenHash") - } - - var r0 *domain.Token - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.Token, error)); ok { - return returnFunc(ctx, tokenHash) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.Token); ok { - r0 = returnFunc(ctx, tokenHash) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.Token) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = returnFunc(ctx, tokenHash) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenRepository_GetByTokenHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByTokenHash' -type MockTokenRepository_GetByTokenHash_Call struct { - *mock.Call -} - -// GetByTokenHash is a helper method to define mock.On call -// - ctx context.Context -// - tokenHash string -func (_e *MockTokenRepository_Expecter) GetByTokenHash(ctx interface{}, tokenHash interface{}) *MockTokenRepository_GetByTokenHash_Call { - return &MockTokenRepository_GetByTokenHash_Call{Call: _e.mock.On("GetByTokenHash", ctx, tokenHash)} -} - -func (_c *MockTokenRepository_GetByTokenHash_Call) Run(run func(ctx context.Context, tokenHash string)) *MockTokenRepository_GetByTokenHash_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_GetByTokenHash_Call) Return(token *domain.Token, err error) *MockTokenRepository_GetByTokenHash_Call { - _c.Call.Return(token, err) - return _c -} - -func (_c *MockTokenRepository_GetByTokenHash_Call) RunAndReturn(run func(ctx context.Context, tokenHash string) (*domain.Token, error)) *MockTokenRepository_GetByTokenHash_Call { - _c.Call.Return(run) - return _c -} - -// PurgeExpiredAndRevoked provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) PurgeExpiredAndRevoked(ctx context.Context, olderThan time.Time) (int64, error) { - ret := _mock.Called(ctx, olderThan) - - if len(ret) == 0 { - panic("no return value specified for PurgeExpiredAndRevoked") - } - - var r0 int64 - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) (int64, error)); ok { - return returnFunc(ctx, olderThan) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) int64); ok { - r0 = returnFunc(ctx, olderThan) - } else { - r0 = ret.Get(0).(int64) - } - if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time) error); ok { - r1 = returnFunc(ctx, olderThan) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenRepository_PurgeExpiredAndRevoked_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PurgeExpiredAndRevoked' -type MockTokenRepository_PurgeExpiredAndRevoked_Call struct { - *mock.Call -} - -// PurgeExpiredAndRevoked is a helper method to define mock.On call -// - ctx context.Context -// - olderThan time.Time -func (_e *MockTokenRepository_Expecter) PurgeExpiredAndRevoked(ctx interface{}, olderThan interface{}) *MockTokenRepository_PurgeExpiredAndRevoked_Call { - return &MockTokenRepository_PurgeExpiredAndRevoked_Call{Call: _e.mock.On("PurgeExpiredAndRevoked", ctx, olderThan)} -} - -func (_c *MockTokenRepository_PurgeExpiredAndRevoked_Call) Run(run func(ctx context.Context, olderThan time.Time)) *MockTokenRepository_PurgeExpiredAndRevoked_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 time.Time - if args[1] != nil { - arg1 = args[1].(time.Time) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_PurgeExpiredAndRevoked_Call) Return(n int64, err error) *MockTokenRepository_PurgeExpiredAndRevoked_Call { - _c.Call.Return(n, err) - return _c -} - -func (_c *MockTokenRepository_PurgeExpiredAndRevoked_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time) (int64, error)) *MockTokenRepository_PurgeExpiredAndRevoked_Call { - _c.Call.Return(run) - return _c -} - -// RevokeByClientID provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) RevokeByClientID(ctx context.Context, clientID uuid.UUID) error { - ret := _mock.Called(ctx, clientID) - - if len(ret) == 0 { - panic("no return value specified for RevokeByClientID") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) error); ok { - r0 = returnFunc(ctx, clientID) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTokenRepository_RevokeByClientID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RevokeByClientID' -type MockTokenRepository_RevokeByClientID_Call struct { - *mock.Call -} - -// RevokeByClientID is a helper method to define mock.On call -// - ctx context.Context -// - clientID uuid.UUID -func (_e *MockTokenRepository_Expecter) RevokeByClientID(ctx interface{}, clientID interface{}) *MockTokenRepository_RevokeByClientID_Call { - return &MockTokenRepository_RevokeByClientID_Call{Call: _e.mock.On("RevokeByClientID", ctx, clientID)} -} - -func (_c *MockTokenRepository_RevokeByClientID_Call) Run(run func(ctx context.Context, clientID uuid.UUID)) *MockTokenRepository_RevokeByClientID_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 *MockTokenRepository_RevokeByClientID_Call) Return(err error) *MockTokenRepository_RevokeByClientID_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTokenRepository_RevokeByClientID_Call) RunAndReturn(run func(ctx context.Context, clientID uuid.UUID) error) *MockTokenRepository_RevokeByClientID_Call { - _c.Call.Return(run) - return _c -} - -// RevokeByTokenID provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) RevokeByTokenID(ctx context.Context, tokenID uuid.UUID) error { - ret := _mock.Called(ctx, tokenID) - - if len(ret) == 0 { - panic("no return value specified for RevokeByTokenID") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) error); ok { - r0 = returnFunc(ctx, tokenID) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTokenRepository_RevokeByTokenID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RevokeByTokenID' -type MockTokenRepository_RevokeByTokenID_Call struct { - *mock.Call -} - -// RevokeByTokenID is a helper method to define mock.On call -// - ctx context.Context -// - tokenID uuid.UUID -func (_e *MockTokenRepository_Expecter) RevokeByTokenID(ctx interface{}, tokenID interface{}) *MockTokenRepository_RevokeByTokenID_Call { - return &MockTokenRepository_RevokeByTokenID_Call{Call: _e.mock.On("RevokeByTokenID", ctx, tokenID)} -} - -func (_c *MockTokenRepository_RevokeByTokenID_Call) Run(run func(ctx context.Context, tokenID uuid.UUID)) *MockTokenRepository_RevokeByTokenID_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 *MockTokenRepository_RevokeByTokenID_Call) Return(err error) *MockTokenRepository_RevokeByTokenID_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTokenRepository_RevokeByTokenID_Call) RunAndReturn(run func(ctx context.Context, tokenID uuid.UUID) error) *MockTokenRepository_RevokeByTokenID_Call { - _c.Call.Return(run) - return _c -} - -// Update provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) Update(ctx context.Context, token *domain.Token) error { - ret := _mock.Called(ctx, token) - - if len(ret) == 0 { - panic("no return value specified for Update") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Token) error); ok { - r0 = returnFunc(ctx, token) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTokenRepository_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' -type MockTokenRepository_Update_Call struct { - *mock.Call -} - -// Update is a helper method to define mock.On call -// - ctx context.Context -// - token *domain.Token -func (_e *MockTokenRepository_Expecter) Update(ctx interface{}, token interface{}) *MockTokenRepository_Update_Call { - return &MockTokenRepository_Update_Call{Call: _e.mock.On("Update", ctx, token)} -} - -func (_c *MockTokenRepository_Update_Call) Run(run func(ctx context.Context, token *domain.Token)) *MockTokenRepository_Update_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *domain.Token - if args[1] != nil { - arg1 = args[1].(*domain.Token) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_Update_Call) Return(err error) *MockTokenRepository_Update_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTokenRepository_Update_Call) RunAndReturn(run func(ctx context.Context, token *domain.Token) error) *MockTokenRepository_Update_Call { - _c.Call.Return(run) - return _c -} - -// NewMockAuditLogRepository creates a new instance of MockAuditLogRepository. 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 NewMockAuditLogRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *MockAuditLogRepository { - mock := &MockAuditLogRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - -// MockAuditLogRepository is an autogenerated mock type for the AuditLogRepository type -type MockAuditLogRepository struct { - mock.Mock -} - -type MockAuditLogRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *MockAuditLogRepository) EXPECT() *MockAuditLogRepository_Expecter { - return &MockAuditLogRepository_Expecter{mock: &_m.Mock} -} - -// Create provides a mock function for the type MockAuditLogRepository -func (_mock *MockAuditLogRepository) Create(ctx context.Context, auditLog *domain.AuditLog) error { - ret := _mock.Called(ctx, auditLog) - - if len(ret) == 0 { - panic("no return value specified for Create") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.AuditLog) error); ok { - r0 = returnFunc(ctx, auditLog) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockAuditLogRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' -type MockAuditLogRepository_Create_Call struct { - *mock.Call -} - -// Create is a helper method to define mock.On call -// - ctx context.Context -// - auditLog *domain.AuditLog -func (_e *MockAuditLogRepository_Expecter) Create(ctx interface{}, auditLog interface{}) *MockAuditLogRepository_Create_Call { - return &MockAuditLogRepository_Create_Call{Call: _e.mock.On("Create", ctx, auditLog)} -} - -func (_c *MockAuditLogRepository_Create_Call) Run(run func(ctx context.Context, auditLog *domain.AuditLog)) *MockAuditLogRepository_Create_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *domain.AuditLog - if args[1] != nil { - arg1 = args[1].(*domain.AuditLog) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockAuditLogRepository_Create_Call) Return(err error) *MockAuditLogRepository_Create_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockAuditLogRepository_Create_Call) RunAndReturn(run func(ctx context.Context, auditLog *domain.AuditLog) error) *MockAuditLogRepository_Create_Call { - _c.Call.Return(run) - return _c -} - -// DeleteOlderThan provides a mock function for the type MockAuditLogRepository -func (_mock *MockAuditLogRepository) DeleteOlderThan(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error) { - ret := _mock.Called(ctx, olderThan, dryRun) - - if len(ret) == 0 { - panic("no return value specified for DeleteOlderThan") - } - - var r0 int64 - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) (int64, error)); ok { - return returnFunc(ctx, olderThan, dryRun) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) int64); ok { - r0 = returnFunc(ctx, olderThan, dryRun) - } else { - r0 = ret.Get(0).(int64) - } - if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, bool) error); ok { - r1 = returnFunc(ctx, olderThan, dryRun) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockAuditLogRepository_DeleteOlderThan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteOlderThan' -type MockAuditLogRepository_DeleteOlderThan_Call struct { - *mock.Call -} - -// DeleteOlderThan is a helper method to define mock.On call -// - ctx context.Context -// - olderThan time.Time -// - dryRun bool -func (_e *MockAuditLogRepository_Expecter) DeleteOlderThan(ctx interface{}, olderThan interface{}, dryRun interface{}) *MockAuditLogRepository_DeleteOlderThan_Call { - return &MockAuditLogRepository_DeleteOlderThan_Call{Call: _e.mock.On("DeleteOlderThan", ctx, olderThan, dryRun)} -} - -func (_c *MockAuditLogRepository_DeleteOlderThan_Call) Run(run func(ctx context.Context, olderThan time.Time, dryRun bool)) *MockAuditLogRepository_DeleteOlderThan_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 time.Time - if args[1] != nil { - arg1 = args[1].(time.Time) - } - var arg2 bool - if args[2] != nil { - arg2 = args[2].(bool) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockAuditLogRepository_DeleteOlderThan_Call) Return(n int64, err error) *MockAuditLogRepository_DeleteOlderThan_Call { - _c.Call.Return(n, err) - return _c -} - -func (_c *MockAuditLogRepository_DeleteOlderThan_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)) *MockAuditLogRepository_DeleteOlderThan_Call { - _c.Call.Return(run) - return _c -} - -// Get provides a mock function for the type MockAuditLogRepository -func (_mock *MockAuditLogRepository) Get(ctx context.Context, id uuid.UUID) (*domain.AuditLog, error) { - ret := _mock.Called(ctx, id) - - if len(ret) == 0 { - panic("no return value specified for Get") - } - - var r0 *domain.AuditLog - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (*domain.AuditLog, error)); ok { - return returnFunc(ctx, id) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) *domain.AuditLog); ok { - r0 = returnFunc(ctx, id) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.AuditLog) - } - } - 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 -} - -// MockAuditLogRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' -type MockAuditLogRepository_Get_Call struct { - *mock.Call -} - -// Get is a helper method to define mock.On call -// - ctx context.Context -// - id uuid.UUID -func (_e *MockAuditLogRepository_Expecter) Get(ctx interface{}, id interface{}) *MockAuditLogRepository_Get_Call { - return &MockAuditLogRepository_Get_Call{Call: _e.mock.On("Get", ctx, id)} -} - -func (_c *MockAuditLogRepository_Get_Call) Run(run func(ctx context.Context, id uuid.UUID)) *MockAuditLogRepository_Get_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 *MockAuditLogRepository_Get_Call) Return(auditLog *domain.AuditLog, err error) *MockAuditLogRepository_Get_Call { - _c.Call.Return(auditLog, err) - return _c -} - -func (_c *MockAuditLogRepository_Get_Call) RunAndReturn(run func(ctx context.Context, id uuid.UUID) (*domain.AuditLog, error)) *MockAuditLogRepository_Get_Call { - _c.Call.Return(run) - return _c -} - -// ListCursor provides a mock function for the type MockAuditLogRepository -func (_mock *MockAuditLogRepository) ListCursor(ctx context.Context, afterID *uuid.UUID, limit int, createdAtFrom *time.Time, createdAtTo *time.Time, clientID *uuid.UUID) ([]*domain.AuditLog, error) { - ret := _mock.Called(ctx, afterID, limit, createdAtFrom, createdAtTo, clientID) - - if len(ret) == 0 { - panic("no return value specified for ListCursor") - } - - var r0 []*domain.AuditLog - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, int, *time.Time, *time.Time, *uuid.UUID) ([]*domain.AuditLog, error)); ok { - return returnFunc(ctx, afterID, limit, createdAtFrom, createdAtTo, clientID) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, *uuid.UUID, int, *time.Time, *time.Time, *uuid.UUID) []*domain.AuditLog); ok { - r0 = returnFunc(ctx, afterID, limit, createdAtFrom, createdAtTo, clientID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*domain.AuditLog) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, *uuid.UUID, int, *time.Time, *time.Time, *uuid.UUID) error); ok { - r1 = returnFunc(ctx, afterID, limit, createdAtFrom, createdAtTo, clientID) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockAuditLogRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' -type MockAuditLogRepository_ListCursor_Call struct { - *mock.Call -} - -// ListCursor is a helper method to define mock.On call -// - ctx context.Context -// - afterID *uuid.UUID -// - limit int -// - createdAtFrom *time.Time -// - createdAtTo *time.Time -// - clientID *uuid.UUID -func (_e *MockAuditLogRepository_Expecter) ListCursor(ctx interface{}, afterID interface{}, limit interface{}, createdAtFrom interface{}, createdAtTo interface{}, clientID interface{}) *MockAuditLogRepository_ListCursor_Call { - return &MockAuditLogRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterID, limit, createdAtFrom, createdAtTo, clientID)} -} - -func (_c *MockAuditLogRepository_ListCursor_Call) Run(run func(ctx context.Context, afterID *uuid.UUID, limit int, createdAtFrom *time.Time, createdAtTo *time.Time, clientID *uuid.UUID)) *MockAuditLogRepository_ListCursor_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 int - if args[2] != nil { - arg2 = args[2].(int) - } - var arg3 *time.Time - if args[3] != nil { - arg3 = args[3].(*time.Time) - } - var arg4 *time.Time - if args[4] != nil { - arg4 = args[4].(*time.Time) - } - var arg5 *uuid.UUID - if args[5] != nil { - arg5 = args[5].(*uuid.UUID) - } - run( - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - ) - }) - return _c -} - -func (_c *MockAuditLogRepository_ListCursor_Call) Return(auditLogs []*domain.AuditLog, err error) *MockAuditLogRepository_ListCursor_Call { - _c.Call.Return(auditLogs, err) - return _c -} - -func (_c *MockAuditLogRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterID *uuid.UUID, limit int, createdAtFrom *time.Time, createdAtTo *time.Time, clientID *uuid.UUID) ([]*domain.AuditLog, error)) *MockAuditLogRepository_ListCursor_Call { - _c.Call.Return(run) - return _c -} - // NewMockClientUseCase creates a new instance of MockClientUseCase. 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 NewMockClientUseCase(t interface { @@ -1202,7 +77,7 @@ type MockClientUseCase_Create_Call struct { // Create is a helper method to define mock.On call // - ctx context.Context // - createClientInput *domain.CreateClientInput -func (_e *MockClientUseCase_Expecter) Create(ctx interface{}, createClientInput interface{}) *MockClientUseCase_Create_Call { +func (_e *MockClientUseCase_Expecter) Create(ctx any, createClientInput any) *MockClientUseCase_Create_Call { return &MockClientUseCase_Create_Call{Call: _e.mock.On("Create", ctx, createClientInput)} } @@ -1259,7 +134,7 @@ type MockClientUseCase_Delete_Call struct { // Delete is a helper method to define mock.On call // - ctx context.Context // - clientID uuid.UUID -func (_e *MockClientUseCase_Expecter) Delete(ctx interface{}, clientID interface{}) *MockClientUseCase_Delete_Call { +func (_e *MockClientUseCase_Expecter) Delete(ctx any, clientID any) *MockClientUseCase_Delete_Call { return &MockClientUseCase_Delete_Call{Call: _e.mock.On("Delete", ctx, clientID)} } @@ -1327,7 +202,7 @@ type MockClientUseCase_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context // - clientID uuid.UUID -func (_e *MockClientUseCase_Expecter) Get(ctx interface{}, clientID interface{}) *MockClientUseCase_Get_Call { +func (_e *MockClientUseCase_Expecter) Get(ctx any, clientID any) *MockClientUseCase_Get_Call { return &MockClientUseCase_Get_Call{Call: _e.mock.On("Get", ctx, clientID)} } @@ -1396,7 +271,7 @@ type MockClientUseCase_ListCursor_Call struct { // - ctx context.Context // - afterID *uuid.UUID // - limit int -func (_e *MockClientUseCase_Expecter) ListCursor(ctx interface{}, afterID interface{}, limit interface{}) *MockClientUseCase_ListCursor_Call { +func (_e *MockClientUseCase_Expecter) ListCursor(ctx any, afterID any, limit any) *MockClientUseCase_ListCursor_Call { return &MockClientUseCase_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterID, limit)} } @@ -1458,7 +333,7 @@ type MockClientUseCase_RevokeTokens_Call struct { // RevokeTokens is a helper method to define mock.On call // - ctx context.Context // - clientID uuid.UUID -func (_e *MockClientUseCase_Expecter) RevokeTokens(ctx interface{}, clientID interface{}) *MockClientUseCase_RevokeTokens_Call { +func (_e *MockClientUseCase_Expecter) RevokeTokens(ctx any, clientID any) *MockClientUseCase_RevokeTokens_Call { return &MockClientUseCase_RevokeTokens_Call{Call: _e.mock.On("RevokeTokens", ctx, clientID)} } @@ -1526,7 +401,7 @@ type MockClientUseCase_RotateSecret_Call struct { // RotateSecret is a helper method to define mock.On call // - ctx context.Context // - clientID uuid.UUID -func (_e *MockClientUseCase_Expecter) RotateSecret(ctx interface{}, clientID interface{}) *MockClientUseCase_RotateSecret_Call { +func (_e *MockClientUseCase_Expecter) RotateSecret(ctx any, clientID any) *MockClientUseCase_RotateSecret_Call { return &MockClientUseCase_RotateSecret_Call{Call: _e.mock.On("RotateSecret", ctx, clientID)} } @@ -1583,7 +458,7 @@ type MockClientUseCase_Unlock_Call struct { // Unlock is a helper method to define mock.On call // - ctx context.Context // - clientID uuid.UUID -func (_e *MockClientUseCase_Expecter) Unlock(ctx interface{}, clientID interface{}) *MockClientUseCase_Unlock_Call { +func (_e *MockClientUseCase_Expecter) Unlock(ctx any, clientID any) *MockClientUseCase_Unlock_Call { return &MockClientUseCase_Unlock_Call{Call: _e.mock.On("Unlock", ctx, clientID)} } @@ -1641,7 +516,7 @@ type MockClientUseCase_Update_Call struct { // - ctx context.Context // - clientID uuid.UUID // - updateClientInput *domain.UpdateClientInput -func (_e *MockClientUseCase_Expecter) Update(ctx interface{}, clientID interface{}, updateClientInput interface{}) *MockClientUseCase_Update_Call { +func (_e *MockClientUseCase_Expecter) Update(ctx any, clientID any, updateClientInput any) *MockClientUseCase_Update_Call { return &MockClientUseCase_Update_Call{Call: _e.mock.On("Update", ctx, clientID, updateClientInput)} } @@ -1741,7 +616,7 @@ type MockTokenUseCase_Authenticate_Call struct { // Authenticate is a helper method to define mock.On call // - ctx context.Context // - rawToken string -func (_e *MockTokenUseCase_Expecter) Authenticate(ctx interface{}, rawToken interface{}) *MockTokenUseCase_Authenticate_Call { +func (_e *MockTokenUseCase_Expecter) Authenticate(ctx any, rawToken any) *MockTokenUseCase_Authenticate_Call { return &MockTokenUseCase_Authenticate_Call{Call: _e.mock.On("Authenticate", ctx, rawToken)} } @@ -1809,7 +684,7 @@ type MockTokenUseCase_Issue_Call struct { // Issue is a helper method to define mock.On call // - ctx context.Context // - issueTokenInput *domain.IssueTokenInput -func (_e *MockTokenUseCase_Expecter) Issue(ctx interface{}, issueTokenInput interface{}) *MockTokenUseCase_Issue_Call { +func (_e *MockTokenUseCase_Expecter) Issue(ctx any, issueTokenInput any) *MockTokenUseCase_Issue_Call { return &MockTokenUseCase_Issue_Call{Call: _e.mock.On("Issue", ctx, issueTokenInput)} } @@ -1875,7 +750,7 @@ type MockTokenUseCase_PurgeExpiredAndRevoked_Call struct { // PurgeExpiredAndRevoked is a helper method to define mock.On call // - ctx context.Context // - days int -func (_e *MockTokenUseCase_Expecter) PurgeExpiredAndRevoked(ctx interface{}, days interface{}) *MockTokenUseCase_PurgeExpiredAndRevoked_Call { +func (_e *MockTokenUseCase_Expecter) PurgeExpiredAndRevoked(ctx any, days any) *MockTokenUseCase_PurgeExpiredAndRevoked_Call { return &MockTokenUseCase_PurgeExpiredAndRevoked_Call{Call: _e.mock.On("PurgeExpiredAndRevoked", ctx, days)} } @@ -1932,7 +807,7 @@ type MockTokenUseCase_Revoke_Call struct { // Revoke is a helper method to define mock.On call // - ctx context.Context // - rawToken string -func (_e *MockTokenUseCase_Expecter) Revoke(ctx interface{}, rawToken interface{}) *MockTokenUseCase_Revoke_Call { +func (_e *MockTokenUseCase_Expecter) Revoke(ctx any, rawToken any) *MockTokenUseCase_Revoke_Call { return &MockTokenUseCase_Revoke_Call{Call: _e.mock.On("Revoke", ctx, rawToken)} } @@ -2020,7 +895,7 @@ type MockAuditLogUseCase_Create_Call struct { // - capability domain.Capability // - path string // - metadata map[string]any -func (_e *MockAuditLogUseCase_Expecter) Create(ctx interface{}, requestID interface{}, clientID interface{}, capability interface{}, path interface{}, metadata interface{}) *MockAuditLogUseCase_Create_Call { +func (_e *MockAuditLogUseCase_Expecter) Create(ctx any, requestID any, clientID any, capability any, path any, metadata any) *MockAuditLogUseCase_Create_Call { return &MockAuditLogUseCase_Create_Call{Call: _e.mock.On("Create", ctx, requestID, clientID, capability, path, metadata)} } @@ -2107,7 +982,7 @@ type MockAuditLogUseCase_DeleteOlderThan_Call struct { // - ctx context.Context // - days int // - dryRun bool -func (_e *MockAuditLogUseCase_Expecter) DeleteOlderThan(ctx interface{}, days interface{}, dryRun interface{}) *MockAuditLogUseCase_DeleteOlderThan_Call { +func (_e *MockAuditLogUseCase_Expecter) DeleteOlderThan(ctx any, days any, dryRun any) *MockAuditLogUseCase_DeleteOlderThan_Call { return &MockAuditLogUseCase_DeleteOlderThan_Call{Call: _e.mock.On("DeleteOlderThan", ctx, days, dryRun)} } @@ -2184,7 +1059,7 @@ type MockAuditLogUseCase_ListCursor_Call struct { // - createdAtFrom *time.Time // - createdAtTo *time.Time // - clientID *uuid.UUID -func (_e *MockAuditLogUseCase_Expecter) ListCursor(ctx interface{}, afterID interface{}, limit interface{}, createdAtFrom interface{}, createdAtTo interface{}, clientID interface{}) *MockAuditLogUseCase_ListCursor_Call { +func (_e *MockAuditLogUseCase_Expecter) ListCursor(ctx any, afterID any, limit any, createdAtFrom any, createdAtTo any, clientID any) *MockAuditLogUseCase_ListCursor_Call { return &MockAuditLogUseCase_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterID, limit, createdAtFrom, createdAtTo, clientID)} } @@ -2273,7 +1148,7 @@ type MockAuditLogUseCase_VerifyBatch_Call struct { // - ctx context.Context // - startTime time.Time // - endTime time.Time -func (_e *MockAuditLogUseCase_Expecter) VerifyBatch(ctx interface{}, startTime interface{}, endTime interface{}) *MockAuditLogUseCase_VerifyBatch_Call { +func (_e *MockAuditLogUseCase_Expecter) VerifyBatch(ctx any, startTime any, endTime any) *MockAuditLogUseCase_VerifyBatch_Call { return &MockAuditLogUseCase_VerifyBatch_Call{Call: _e.mock.On("VerifyBatch", ctx, startTime, endTime)} } @@ -2335,7 +1210,7 @@ type MockAuditLogUseCase_VerifyIntegrity_Call struct { // VerifyIntegrity is a helper method to define mock.On call // - ctx context.Context // - id uuid.UUID -func (_e *MockAuditLogUseCase_Expecter) VerifyIntegrity(ctx interface{}, id interface{}) *MockAuditLogUseCase_VerifyIntegrity_Call { +func (_e *MockAuditLogUseCase_Expecter) VerifyIntegrity(ctx any, id any) *MockAuditLogUseCase_VerifyIntegrity_Call { return &MockAuditLogUseCase_VerifyIntegrity_Call{Call: _e.mock.On("VerifyIntegrity", ctx, id)} } diff --git a/internal/auth/usecase/token_usecase_test.go b/internal/auth/usecase/token_usecase_test.go index 98d35e0..e3fa05f 100644 --- a/internal/auth/usecase/token_usecase_test.go +++ b/internal/auth/usecase/token_usecase_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/mock" authDomain "github.com/allisson/secrets/internal/auth/domain" + domainMocks "github.com/allisson/secrets/internal/auth/domain/mocks" "github.com/allisson/secrets/internal/auth/usecase" usecaseMocks "github.com/allisson/secrets/internal/auth/usecase/mocks" "github.com/allisson/secrets/internal/config" @@ -30,8 +31,8 @@ func TestTokenUseCase_Issue(t *testing.T) { LockoutMaxAttempts: 10, LockoutDuration: 30 * time.Minute, } - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -74,8 +75,8 @@ func TestTokenUseCase_Issue(t *testing.T) { t.Run("Error_ClientNotFound", func(t *testing.T) { mockConfig := &config.Config{AuthTokenExpiration: 24 * time.Hour} - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -103,8 +104,8 @@ func TestTokenUseCase_Issue(t *testing.T) { t.Run("Error_ClientInactive", func(t *testing.T) { mockConfig := &config.Config{AuthTokenExpiration: 24 * time.Hour} - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -144,8 +145,8 @@ func TestTokenUseCase_Issue(t *testing.T) { LockoutMaxAttempts: 10, LockoutDuration: 30 * time.Minute, } - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -187,8 +188,8 @@ func TestTokenUseCase_Issue(t *testing.T) { t.Run("Error_AccountLocked", func(t *testing.T) { mockConfig := &config.Config{AuthTokenExpiration: 24 * time.Hour} - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -226,8 +227,8 @@ func TestTokenUseCase_Issue(t *testing.T) { LockoutMaxAttempts: 3, LockoutDuration: 30 * time.Minute, } - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -270,8 +271,8 @@ func TestTokenUseCase_Issue(t *testing.T) { AuthTokenExpiration: 24 * time.Hour, LockoutMaxAttempts: 10, } - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -309,8 +310,8 @@ func TestTokenUseCase_Issue(t *testing.T) { t.Run("Success_LockExpiredAllowsAuth", func(t *testing.T) { mockConfig := &config.Config{AuthTokenExpiration: 24 * time.Hour} - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -350,8 +351,8 @@ func TestTokenUseCase_Issue(t *testing.T) { t.Run("Error_RepositoryCreateFails", func(t *testing.T) { mockConfig := &config.Config{AuthTokenExpiration: 24 * time.Hour} - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -388,8 +389,8 @@ func TestTokenUseCase_Issue(t *testing.T) { t.Run("Success_TokenExpirationSetFromConfig", func(t *testing.T) { expiration := 12 * time.Hour mockConfig := &config.Config{AuthTokenExpiration: expiration} - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -436,8 +437,8 @@ func TestTokenUseCase_Issue(t *testing.T) { AuthTokenExpiration: 24 * time.Hour, LockoutMaxAttempts: 10, } - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -482,8 +483,8 @@ func TestTokenUseCase_Issue(t *testing.T) { LockoutMaxAttempts: 1, LockoutDuration: 30 * time.Minute, } - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -522,8 +523,8 @@ func TestTokenUseCase_Issue(t *testing.T) { }) t.Run("Error_RepositoryGetReturnsUnexpectedError", func(t *testing.T) { - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -555,8 +556,8 @@ func TestTokenUseCase_Authenticate(t *testing.T) { t.Run("Success_AuthenticateWithValidToken", func(t *testing.T) { mockConfig := &config.Config{AuthTokenExpiration: 24 * time.Hour} - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) clientID := uuid.Must(uuid.NewV7()) @@ -599,7 +600,7 @@ func TestTokenUseCase_Authenticate(t *testing.T) { }) t.Run("Error_TokenNotFound", func(t *testing.T) { - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) uc := usecase.NewTokenUseCase(nil, nil, mockTokenRepo, nil, nil, nil) tokenHash := "not-found" @@ -615,7 +616,7 @@ func TestTokenUseCase_Authenticate(t *testing.T) { }) t.Run("Error_TokenExpired", func(t *testing.T) { - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) uc := usecase.NewTokenUseCase(nil, nil, mockTokenRepo, nil, nil, nil) tokenHash := "expired" @@ -635,8 +636,8 @@ func TestTokenUseCase_Authenticate(t *testing.T) { t.Run("Error_TokenRevoked", func(t *testing.T) { mockConfig := &config.Config{AuthTokenExpiration: 24 * time.Hour} - mockClientRepo := usecaseMocks.NewMockClientRepository(t) - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) tokenHash := "revoked-token-hash" @@ -669,8 +670,8 @@ func TestTokenUseCase_Authenticate(t *testing.T) { }) t.Run("Error_ClientNotFound", func(t *testing.T) { - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) uc := usecase.NewTokenUseCase(nil, mockClientRepo, mockTokenRepo, nil, nil, nil) tokenHash := "hash" @@ -692,8 +693,8 @@ func TestTokenUseCase_Authenticate(t *testing.T) { }) t.Run("Error_ClientInactive", func(t *testing.T) { - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) uc := usecase.NewTokenUseCase(nil, mockClientRepo, mockTokenRepo, nil, nil, nil) tokenHash := "hash" @@ -719,7 +720,7 @@ func TestTokenUseCase_Authenticate(t *testing.T) { }) t.Run("Error_RepositoryGetTokenFails", func(t *testing.T) { - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) uc := usecase.NewTokenUseCase(nil, nil, mockTokenRepo, nil, nil, nil) tokenHash := "hash" @@ -736,8 +737,8 @@ func TestTokenUseCase_Authenticate(t *testing.T) { }) t.Run("Error_RepositoryGetClientFails", func(t *testing.T) { - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) - mockClientRepo := usecaseMocks.NewMockClientRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) + mockClientRepo := domainMocks.NewMockClientRepository(t) uc := usecase.NewTokenUseCase(nil, mockClientRepo, mockTokenRepo, nil, nil, nil) tokenHash := "hash" @@ -764,7 +765,7 @@ func TestTokenUseCase_Revoke(t *testing.T) { ctx := context.Background() t.Run("Success_RevokeToken", func(t *testing.T) { - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) uc := usecase.NewTokenUseCase(nil, nil, mockTokenRepo, mockAuditLogUseCase, nil, nil) @@ -786,7 +787,7 @@ func TestTokenUseCase_Revoke(t *testing.T) { }) t.Run("Error_TokenNotFound", func(t *testing.T) { - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) mockAuditLogUseCase := usecaseMocks.NewMockAuditLogUseCase(t) uc := usecase.NewTokenUseCase(nil, nil, mockTokenRepo, mockAuditLogUseCase, nil, nil) @@ -806,7 +807,7 @@ func TestTokenUseCase_PurgeExpiredAndRevoked(t *testing.T) { ctx := context.Background() t.Run("Success_PurgeTokens", func(t *testing.T) { - mockTokenRepo := usecaseMocks.NewMockTokenRepository(t) + mockTokenRepo := domainMocks.NewMockTokenRepository(t) uc := usecase.NewTokenUseCase(nil, nil, mockTokenRepo, nil, nil, nil) days := 30 diff --git a/internal/database/mocks/mocks.go b/internal/database/mocks/mocks.go index ebf3d02..b971bb6 100644 --- a/internal/database/mocks/mocks.go +++ b/internal/database/mocks/mocks.go @@ -62,7 +62,7 @@ type MockTxManager_WithTx_Call struct { // WithTx is a helper method to define mock.On call // - ctx context.Context // - fn func(ctx context.Context) error -func (_e *MockTxManager_Expecter) WithTx(ctx interface{}, fn interface{}) *MockTxManager_WithTx_Call { +func (_e *MockTxManager_Expecter) WithTx(ctx any, fn any) *MockTxManager_WithTx_Call { return &MockTxManager_WithTx_Call{Call: _e.mock.On("WithTx", ctx, fn)} } diff --git a/internal/keyring/bootstrap.go b/internal/keyring/bootstrap.go index aca9729..48d1f1c 100644 --- a/internal/keyring/bootstrap.go +++ b/internal/keyring/bootstrap.go @@ -14,11 +14,22 @@ func Bootstrap( masterKeyChain *MasterKeyChain, db *sql.DB, alg Algorithm, +) (Keyring, error) { + return bootstrapWith(ctx, masterKeyChain, newKekRepository(db), newDekRepository(db), alg) +} + +// bootstrapWith holds the KEK-loading orchestration behind the kekStore/dekStore +// seams so it can be unit-tested without a live database: it lists the persisted +// KEKs, decrypts each under its master key, and assembles the ready-to-use Keyring. +func bootstrapWith( + ctx context.Context, + masterKeyChain *MasterKeyChain, + kekRepo kekStore, + dekRepo dekStore, + alg Algorithm, ) (Keyring, error) { aeadMgr := newAEADManager() km := newKeyManager(aeadMgr) - kekRepo := newKekRepository(db) - dekRepo := newDekRepository(db) keks, err := kekRepo.list(ctx) if err != nil { @@ -29,11 +40,11 @@ func Bootstrap( } for _, k := range keks { - masterKey, ok := masterKeyChain.Get(k.masterKeyID) + mk, ok := masterKeyChain.get(k.masterKeyID) if !ok { return nil, ErrMasterKeyNotFound } - key, err := km.decryptKek(k, masterKey) + key, err := km.decryptKek(k, mk) if err != nil { return nil, err } diff --git a/internal/keyring/bootstrap_test.go b/internal/keyring/bootstrap_test.go new file mode 100644 index 0000000..ab28ed5 --- /dev/null +++ b/internal/keyring/bootstrap_test.go @@ -0,0 +1,61 @@ +package keyring + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestBootstrapWith_NoKeks_ReturnsErrKekNotFound(t *testing.T) { + ctx := context.Background() + chain, _ := newTestMasterKeyChain(t, "active") + + _, err := bootstrapWith(ctx, chain, newMemKekStore(), newMemDekStore(), AESGCM) + + require.ErrorIs(t, err, ErrKekNotFound) +} + +func TestBootstrapWith_MissingMasterKey_ReturnsErrMasterKeyNotFound(t *testing.T) { + ctx := context.Background() + chain, _ := newTestMasterKeyChain(t, "active") + + // A KEK wrapped under a master key that is not in the chain. + _, foreign := newTestMasterKeyChain(t, "other") + km := newKeyManager(newAEADManager()) + k, err := km.createKek(foreign, AESGCM) + require.NoError(t, err) + + kekStore := newMemKekStore() + require.NoError(t, kekStore.create(ctx, &k)) + + _, err = bootstrapWith(ctx, chain, kekStore, newMemDekStore(), AESGCM) + + require.ErrorIs(t, err, ErrMasterKeyNotFound) +} + +func TestBootstrapWith_HappyPath_ReturnsUsableKeyring(t *testing.T) { + ctx := context.Background() + chain, mk := newTestMasterKeyChain(t, "active") + + km := newKeyManager(newAEADManager()) + k, err := km.createKek(mk, AESGCM) + require.NoError(t, err) + + kekStore := newMemKekStore() + require.NoError(t, kekStore.create(ctx, &k)) + + kr, err := bootstrapWith(ctx, chain, kekStore, newMemDekStore(), AESGCM) + require.NoError(t, err) + require.NotNil(t, kr) + + // The assembled keyring decrypts what it encrypts — proves the loaded KEK + // was unwrapped correctly and wired into the implementation. + plaintext := []byte("bootstrapped secret") + env, err := kr.Encrypt(ctx, plaintext) + require.NoError(t, err) + got, err := kr.Decrypt(ctx, env) + require.NoError(t, err) + assert.Equal(t, plaintext, got) +} diff --git a/internal/keyring/fake_kms.go b/internal/keyring/fake_kms.go new file mode 100644 index 0000000..fa0b027 --- /dev/null +++ b/internal/keyring/fake_kms.go @@ -0,0 +1,70 @@ +package keyring + +import "context" + +// FakeKMSService is an in-memory KMSService for unit tests. It hands out a +// fakeKMSKeeper whose Encrypt/Decrypt are a reversible byte transform — no real +// KMS, no network. It is the second adapter that makes the KMSService/KMSKeeper +// interfaces a real seam: gocloud.dev in production, this in tests. +// +// The Fail* fields, when non-nil, force the matching operation to return the +// stored error, for exercising failure paths in callers. +type FakeKMSService struct { + FailOpen error + FailEncrypt error + FailDecrypt error + FailClose error +} + +// NewFakeKMSService returns a ready-to-use FakeKMSService. +func NewFakeKMSService() *FakeKMSService { + return &FakeKMSService{} +} + +// OpenKeeper returns a fake keeper, or FailOpen if it is set. +func (f *FakeKMSService) OpenKeeper(_ context.Context, _ string) (KMSKeeper, error) { + if f.FailOpen != nil { + return nil, f.FailOpen + } + return &fakeKMSKeeper{ + failEncrypt: f.FailEncrypt, + failDecrypt: f.FailDecrypt, + failClose: f.FailClose, + }, nil +} + +type fakeKMSKeeper struct { + failEncrypt error + failDecrypt error + failClose error +} + +// fakeKMSMask is the byte the fake XORs data with. XOR is its own inverse, so +// Decrypt(Encrypt(x)) == x, giving a deterministic round-trip without real keys. +const fakeKMSMask = 0x5a + +func (k *fakeKMSKeeper) Encrypt(_ context.Context, plaintext []byte) ([]byte, error) { + if k.failEncrypt != nil { + return nil, k.failEncrypt + } + return xorMask(plaintext), nil +} + +func (k *fakeKMSKeeper) Decrypt(_ context.Context, ciphertext []byte) ([]byte, error) { + if k.failDecrypt != nil { + return nil, k.failDecrypt + } + return xorMask(ciphertext), nil +} + +func (k *fakeKMSKeeper) Close() error { + return k.failClose +} + +func xorMask(in []byte) []byte { + out := make([]byte, len(in)) + for i := range in { + out[i] = in[i] ^ fakeKMSMask + } + return out +} diff --git a/internal/keyring/kek_usecase.go b/internal/keyring/kek_usecase.go index b253878..9afeef2 100644 --- a/internal/keyring/kek_usecase.go +++ b/internal/keyring/kek_usecase.go @@ -24,21 +24,21 @@ type kekUseCase struct { keyManager keyManager } -func (k *kekUseCase) getMasterKey(masterKeyChain *MasterKeyChain, id string) (*MasterKey, error) { - masterKey, ok := masterKeyChain.Get(id) +func (k *kekUseCase) getMasterKey(masterKeyChain *MasterKeyChain, id string) (*masterKey, error) { + mk, ok := masterKeyChain.get(id) if !ok { return nil, ErrMasterKeyNotFound } - return masterKey, nil + return mk, nil } func (k *kekUseCase) Create(ctx context.Context, masterKeyChain *MasterKeyChain, alg Algorithm) error { - masterKey, err := k.getMasterKey(masterKeyChain, masterKeyChain.ActiveMasterKeyID()) + mk, err := k.getMasterKey(masterKeyChain, masterKeyChain.ActiveMasterKeyID()) if err != nil { return err } - kk, err := k.keyManager.createKek(masterKey, alg) + kk, err := k.keyManager.createKek(mk, alg) if err != nil { return err } @@ -47,7 +47,7 @@ func (k *kekUseCase) Create(ctx context.Context, masterKeyChain *MasterKeyChain, } func (k *kekUseCase) Rotate(ctx context.Context, masterKeyChain *MasterKeyChain, alg Algorithm) error { - masterKey, err := k.getMasterKey(masterKeyChain, masterKeyChain.ActiveMasterKeyID()) + mk, err := k.getMasterKey(masterKeyChain, masterKeyChain.ActiveMasterKeyID()) if err != nil { return err } @@ -64,7 +64,7 @@ func (k *kekUseCase) Rotate(ctx context.Context, masterKeyChain *MasterKeyChain, currentKek := keks[0] - kk, err := k.keyManager.createKek(masterKey, alg) + kk, err := k.keyManager.createKek(mk, alg) if err != nil { return err } diff --git a/internal/keyring/kek_usecase_test.go b/internal/keyring/kek_usecase_test.go new file mode 100644 index 0000000..ee46efe --- /dev/null +++ b/internal/keyring/kek_usecase_test.go @@ -0,0 +1,79 @@ +package keyring + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func newTestKekUseCase(store kekStore) *kekUseCase { + return &kekUseCase{ + txManager: fakeTxManager{}, + kekRepo: store, + keyManager: newKeyManager(newAEADManager()), + } +} + +func TestKekUseCase_Create_MasterKeyNotInChain_ReturnsError(t *testing.T) { + ctx := context.Background() + // Chain declares an active ID but holds no key material for it. + chain := NewMasterKeyChain("active") + uc := newTestKekUseCase(newMemKekStore()) + + err := uc.Create(ctx, chain, AESGCM) + + require.ErrorIs(t, err, ErrMasterKeyNotFound) +} + +func TestKekUseCase_Create_PersistsVersionOneKek(t *testing.T) { + ctx := context.Background() + chain, _ := newTestMasterKeyChain(t, "active") + store := newMemKekStore() + uc := newTestKekUseCase(store) + + require.NoError(t, uc.Create(ctx, chain, AESGCM)) + + keks, err := store.list(ctx) + require.NoError(t, err) + require.Len(t, keks, 1) + assert.Equal(t, uint(1), keks[0].version) + assert.Equal(t, "active", keks[0].masterKeyID) +} + +func TestKekUseCase_Rotate_EmptyStore_CreatesFirstKek(t *testing.T) { + ctx := context.Background() + chain, _ := newTestMasterKeyChain(t, "active") + store := newMemKekStore() + uc := newTestKekUseCase(store) + + require.NoError(t, uc.Rotate(ctx, chain, AESGCM)) + + keks, err := store.list(ctx) + require.NoError(t, err) + require.Len(t, keks, 1) + assert.Equal(t, uint(1), keks[0].version) +} + +func TestKekUseCase_Rotate_IncrementsVersion(t *testing.T) { + ctx := context.Background() + chain, mk := newTestMasterKeyChain(t, "active") + store := newMemKekStore() + + // Seed an existing KEK at version 5. + km := newKeyManager(newAEADManager()) + existing, err := km.createKek(mk, AESGCM) + require.NoError(t, err) + existing.version = 5 + require.NoError(t, store.create(ctx, &existing)) + + uc := newTestKekUseCase(store) + require.NoError(t, uc.Rotate(ctx, chain, AESGCM)) + + keks, err := store.list(ctx) + require.NoError(t, err) + require.Len(t, keks, 2) + // list is version-descending; the rotated KEK is version 6. + assert.Equal(t, uint(6), keks[0].version) +} diff --git a/internal/keyring/key_manager.go b/internal/keyring/key_manager.go index d51998c..af1c438 100644 --- a/internal/keyring/key_manager.go +++ b/internal/keyring/key_manager.go @@ -9,8 +9,8 @@ import ( ) type keyManager interface { - createKek(masterKey *MasterKey, alg Algorithm) (kek, error) - decryptKek(k *kek, masterKey *MasterKey) ([]byte, error) + createKek(mk *masterKey, alg Algorithm) (kek, error) + decryptKek(k *kek, mk *masterKey) ([]byte, error) createDek(k *kek, alg Algorithm) (dek, error) encryptDek(dekKey []byte, k *kek) (ciphertext, nonce []byte, err error) decryptDek(d *dek, k *kek) ([]byte, error) @@ -24,14 +24,14 @@ func newKeyManager(am aeadManager) keyManager { return &keyManagerService{aeadManager: am} } -func (km *keyManagerService) createKek(masterKey *MasterKey, alg Algorithm) (kek, error) { +func (km *keyManagerService) createKek(mk *masterKey, alg Algorithm) (kek, error) { kekKey := make([]byte, 32) if _, err := rand.Read(kekKey); err != nil { return kek{}, fmt.Errorf("failed to generate KEK: %w", err) } defer Zero(kekKey) - cipher, err := km.aeadManager.createCipher(masterKey.Key, alg) + cipher, err := km.aeadManager.createCipher(mk.key, alg) if err != nil { return kek{}, err } @@ -46,7 +46,7 @@ func (km *keyManagerService) createKek(masterKey *MasterKey, alg Algorithm) (kek k := kek{ id: uuid.Must(uuid.NewV7()), - masterKeyID: masterKey.ID, + masterKeyID: mk.ID, algorithm: alg, encryptedKey: encryptedKey, key: keyCopy, @@ -58,8 +58,8 @@ func (km *keyManagerService) createKek(masterKey *MasterKey, alg Algorithm) (kek return k, nil } -func (km *keyManagerService) decryptKek(k *kek, masterKey *MasterKey) ([]byte, error) { - cipher, err := km.aeadManager.createCipher(masterKey.Key, k.algorithm) +func (km *keyManagerService) decryptKek(k *kek, mk *masterKey) ([]byte, error) { + cipher, err := km.aeadManager.createCipher(mk.key, k.algorithm) if err != nil { return nil, err } diff --git a/internal/keyring/kms.go b/internal/keyring/kms.go index 22ed1a8..4c3c05e 100644 --- a/internal/keyring/kms.go +++ b/internal/keyring/kms.go @@ -21,9 +21,13 @@ type KMSService interface { OpenKeeper(ctx context.Context, keyURI string) (KMSKeeper, error) } -// KMSKeeper wraps a gocloud.dev/secrets.Keeper to expose only the -// operations the keyring needs: decryption and resource cleanup. +// KMSKeeper wraps a gocloud.dev/secrets.Keeper to expose the operations the +// master-key lifecycle needs. Decrypt is the boot path (unwrap persisted master +// keys); Encrypt is the operator path (the create/rotate-master-key CLI commands +// wrap a fresh key). Close releases keeper resources. The running service only +// ever calls Decrypt; Encrypt exists so the CLI needs no runtime type assertion. type KMSKeeper interface { + Encrypt(ctx context.Context, plaintext []byte) ([]byte, error) Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) Close() error } diff --git a/internal/keyring/master_key.go b/internal/keyring/master_key.go index 689165a..8493fab 100644 --- a/internal/keyring/master_key.go +++ b/internal/keyring/master_key.go @@ -12,11 +12,12 @@ import ( "github.com/allisson/secrets/internal/config" ) -// MasterKey is a plaintext root key used to wrap KEKs. Key material must be -// zeroed via Zero when no longer needed. -type MasterKey struct { +// masterKey is a plaintext root key used to wrap KEKs. Key material must be +// zeroed via Zero when no longer needed. It is unexported: raw root-key bytes +// never leave the keyring package. +type masterKey struct { ID string - Key []byte + key []byte } // MasterKeyChain is an in-memory store of one or more MasterKeys, one of @@ -39,20 +40,28 @@ func (m *MasterKeyChain) ActiveMasterKeyID() string { return m.activeID } -// Get returns the MasterKey with the given ID, or false if it is not in the chain. -func (m *MasterKeyChain) Get(id string) (*MasterKey, bool) { - if masterKey, ok := m.keys.Load(id); ok { - return masterKey.(*MasterKey), ok +// get returns the masterKey with the given ID, or false if it is not in the chain. +func (m *MasterKeyChain) get(id string) (*masterKey, bool) { + if mk, ok := m.keys.Load(id); ok { + return mk.(*masterKey), ok } return nil, false } +// Has reports whether a master key with the given ID is present in the chain. +// It exposes presence without leaking key material, for callers that need to +// verify a chain was populated (e.g. end-to-end tests). +func (m *MasterKeyChain) Has(id string) bool { + _, ok := m.keys.Load(id) + return ok +} + // Close zeroes all key material in the chain and removes every entry. // After Close the chain must not be used. func (m *MasterKeyChain) Close() { - m.keys.Range(func(key, value interface{}) bool { - if masterKey, ok := value.(*MasterKey); ok { - Zero(masterKey.Key) + m.keys.Range(func(_, value any) bool { + if mk, ok := value.(*masterKey); ok { + Zero(mk.key) } return true }) @@ -183,10 +192,10 @@ func loadMasterKeyChainFromKMS( copy(keyCopy, key) Zero(key) - mkc.keys.Store(id, &MasterKey{ID: id, Key: keyCopy}) + mkc.keys.Store(id, &masterKey{ID: id, key: keyCopy}) } - if _, ok := mkc.Get(active); !ok { + if _, ok := mkc.get(active); !ok { mkc.Close() return nil, fmt.Errorf("%w: ACTIVE_MASTER_KEY_ID=%s", ErrActiveMasterKeyNotFound, active) } diff --git a/internal/keyring/master_key_test.go b/internal/keyring/master_key_test.go new file mode 100644 index 0000000..e8a5417 --- /dev/null +++ b/internal/keyring/master_key_test.go @@ -0,0 +1,105 @@ +package keyring + +import ( + "context" + "crypto/rand" + "encoding/base64" + "errors" + "io" + "log/slog" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/allisson/secrets/internal/config" +) + +func testLogger() *slog.Logger { + return slog.New(slog.NewTextHandler(io.Discard, nil)) +} + +func testKMSConfig() *config.Config { + return &config.Config{KMSProvider: "localsecrets", KMSKeyURI: "base64key://test"} +} + +// fakeEncryptB64 wraps plaintext with a fake keeper and base64-encodes it, mimicking +// how a MASTER_KEYS entry is produced by the create-master-key CLI command. +func fakeEncryptB64(t *testing.T, plaintext []byte) string { + t.Helper() + ct, err := (&fakeKMSKeeper{}).Encrypt(context.Background(), plaintext) + require.NoError(t, err) + return base64.StdEncoding.EncodeToString(ct) +} + +func randomKeyB64(t *testing.T, id string, size int) string { + t.Helper() + key := make([]byte, size) + _, err := rand.Read(key) + require.NoError(t, err) + return id + ":" + fakeEncryptB64(t, key) +} + +func TestLoadMasterKeyChainFromKMS_Errors(t *testing.T) { + validK1 := randomKeyB64(t, "k1", 32) + + // An empty env value is indistinguishable from unset for this loader (it + // checks == ""), so "" models the "not set" cases. + tests := []struct { + name string + masterKeys string + activeID string + svc KMSService + wantErr error + }{ + {"master keys not set", "", "k1", NewFakeKMSService(), ErrMasterKeysNotSet}, + {"active id not set", validK1, "", NewFakeKMSService(), ErrActiveMasterKeyIDNotSet}, + { + "open keeper fails", + validK1, "k1", + &FakeKMSService{FailOpen: errors.New("boom")}, + ErrKMSOpenKeeperFailed, + }, + {"invalid format", "no-colon-here", "k1", NewFakeKMSService(), ErrInvalidMasterKeysFormat}, + {"invalid base64", "k1:not!valid!base64!", "k1", NewFakeKMSService(), ErrInvalidMasterKeyBase64}, + {"wrong key size", randomKeyB64(t, "k1", 16), "k1", NewFakeKMSService(), ErrInvalidKeySize}, + { + "decrypt fails", + validK1, "k1", + &FakeKMSService{FailDecrypt: errors.New("bad key")}, + ErrKMSDecryptionFailed, + }, + {"active not found", validK1, "missing", NewFakeKMSService(), ErrActiveMasterKeyNotFound}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Setenv("MASTER_KEYS", tt.masterKeys) + t.Setenv("ACTIVE_MASTER_KEY_ID", tt.activeID) + + _, err := loadMasterKeyChainFromKMS(context.Background(), testKMSConfig(), tt.svc, testLogger()) + require.ErrorIs(t, err, tt.wantErr) + }) + } +} + +func TestLoadMasterKeyChainFromKMS_HappyPath_MultipleKeys(t *testing.T) { + t.Setenv("MASTER_KEYS", randomKeyB64(t, "k1", 32)+","+randomKeyB64(t, "k2", 32)) + t.Setenv("ACTIVE_MASTER_KEY_ID", "k2") + + mkc, err := loadMasterKeyChainFromKMS( + context.Background(), + testKMSConfig(), + NewFakeKMSService(), + testLogger(), + ) + require.NoError(t, err) + require.NotNil(t, mkc) + require.Equal(t, "k2", mkc.ActiveMasterKeyID()) + + for _, id := range []string{"k1", "k2"} { + mk, ok := mkc.get(id) + require.True(t, ok, "expected %s in chain", id) + require.Len(t, mk.key, 32) + } + mkc.Close() +} diff --git a/internal/keyring/mocks/mock_kek_usecase.go b/internal/keyring/mocks/mocks.go similarity index 66% rename from internal/keyring/mocks/mock_kek_usecase.go rename to internal/keyring/mocks/mocks.go index 1624927..d105a28 100644 --- a/internal/keyring/mocks/mock_kek_usecase.go +++ b/internal/keyring/mocks/mocks.go @@ -7,21 +7,25 @@ package mocks import ( "context" - mock "github.com/stretchr/testify/mock" - "github.com/allisson/secrets/internal/keyring" + mock "github.com/stretchr/testify/mock" ) +// NewMockKekUseCase creates a new instance of MockKekUseCase. 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 NewMockKekUseCase(t interface { mock.TestingT Cleanup(func()) }) *MockKekUseCase { - m := &MockKekUseCase{} - m.Mock.Test(t) - t.Cleanup(func() { m.AssertExpectations(t) }) - return m + mock := &MockKekUseCase{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock } +// MockKekUseCase is an autogenerated mock type for the KekUseCase type type MockKekUseCase struct { mock.Mock } @@ -51,11 +55,16 @@ func (_mock *MockKekUseCase) Create(ctx context.Context, masterKeyChain *keyring return r0 } +// MockKekUseCase_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' type MockKekUseCase_Create_Call struct { *mock.Call } -func (_e *MockKekUseCase_Expecter) Create(ctx interface{}, masterKeyChain interface{}, alg interface{}) *MockKekUseCase_Create_Call { +// Create is a helper method to define mock.On call +// - ctx context.Context +// - masterKeyChain *keyring.MasterKeyChain +// - alg keyring.Algorithm +func (_e *MockKekUseCase_Expecter) Create(ctx any, masterKeyChain any, alg any) *MockKekUseCase_Create_Call { return &MockKekUseCase_Create_Call{Call: _e.mock.On("Create", ctx, masterKeyChain, alg)} } @@ -73,7 +82,11 @@ func (_c *MockKekUseCase_Create_Call) Run(run func(ctx context.Context, masterKe if args[2] != nil { arg2 = args[2].(keyring.Algorithm) } - run(arg0, arg1, arg2) + run( + arg0, + arg1, + arg2, + ) }) return _c } @@ -83,7 +96,7 @@ func (_c *MockKekUseCase_Create_Call) Return(err error) *MockKekUseCase_Create_C return _c } -func (_c *MockKekUseCase_Create_Call) RunAndReturn(run func(context.Context, *keyring.MasterKeyChain, keyring.Algorithm) error) *MockKekUseCase_Create_Call { +func (_c *MockKekUseCase_Create_Call) RunAndReturn(run func(ctx context.Context, masterKeyChain *keyring.MasterKeyChain, alg keyring.Algorithm) error) *MockKekUseCase_Create_Call { _c.Call.Return(run) return _c } @@ -105,11 +118,16 @@ func (_mock *MockKekUseCase) Rotate(ctx context.Context, masterKeyChain *keyring return r0 } +// MockKekUseCase_Rotate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Rotate' type MockKekUseCase_Rotate_Call struct { *mock.Call } -func (_e *MockKekUseCase_Expecter) Rotate(ctx interface{}, masterKeyChain interface{}, alg interface{}) *MockKekUseCase_Rotate_Call { +// Rotate is a helper method to define mock.On call +// - ctx context.Context +// - masterKeyChain *keyring.MasterKeyChain +// - alg keyring.Algorithm +func (_e *MockKekUseCase_Expecter) Rotate(ctx any, masterKeyChain any, alg any) *MockKekUseCase_Rotate_Call { return &MockKekUseCase_Rotate_Call{Call: _e.mock.On("Rotate", ctx, masterKeyChain, alg)} } @@ -127,7 +145,11 @@ func (_c *MockKekUseCase_Rotate_Call) Run(run func(ctx context.Context, masterKe if args[2] != nil { arg2 = args[2].(keyring.Algorithm) } - run(arg0, arg1, arg2) + run( + arg0, + arg1, + arg2, + ) }) return _c } @@ -137,7 +159,7 @@ func (_c *MockKekUseCase_Rotate_Call) Return(err error) *MockKekUseCase_Rotate_C return _c } -func (_c *MockKekUseCase_Rotate_Call) RunAndReturn(run func(context.Context, *keyring.MasterKeyChain, keyring.Algorithm) error) *MockKekUseCase_Rotate_Call { +func (_c *MockKekUseCase_Rotate_Call) RunAndReturn(run func(ctx context.Context, masterKeyChain *keyring.MasterKeyChain, alg keyring.Algorithm) error) *MockKekUseCase_Rotate_Call { _c.Call.Return(run) return _c } diff --git a/internal/keyring/store_fakes_test.go b/internal/keyring/store_fakes_test.go new file mode 100644 index 0000000..5fd968d --- /dev/null +++ b/internal/keyring/store_fakes_test.go @@ -0,0 +1,80 @@ +package keyring + +import ( + "context" + "crypto/rand" + "sort" + "sync" + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" +) + +// newMemDekStore returns an empty in-memory dekStore (type defined in impl_test.go). +func newMemDekStore() *memDekStore { + return &memDekStore{deks: make(map[uuid.UUID]*dek)} +} + +// memKekStore is an in-memory kekStore for unit tests. list returns rows ordered +// by version descending, matching the production repository's ORDER BY. +type memKekStore struct { + mu sync.Mutex + keks map[string]*kek +} + +func newMemKekStore() *memKekStore { + return &memKekStore{keks: make(map[string]*kek)} +} + +func (m *memKekStore) create(_ context.Context, k *kek) error { + m.mu.Lock() + defer m.mu.Unlock() + cp := *k + m.keks[k.id.String()] = &cp + return nil +} + +func (m *memKekStore) update(_ context.Context, k *kek) error { + m.mu.Lock() + defer m.mu.Unlock() + if _, ok := m.keks[k.id.String()]; !ok { + return ErrKekNotFound + } + cp := *k + m.keks[k.id.String()] = &cp + return nil +} + +func (m *memKekStore) list(_ context.Context) ([]*kek, error) { + m.mu.Lock() + defer m.mu.Unlock() + out := make([]*kek, 0, len(m.keks)) + for _, k := range m.keks { + cp := *k + out = append(out, &cp) + } + sort.Slice(out, func(i, j int) bool { return out[i].version > out[j].version }) + return out, nil +} + +// fakeTxManager runs the callback inline with no real transaction, so use-case +// orchestration can be tested without a database. +type fakeTxManager struct{} + +func (fakeTxManager) WithTx(ctx context.Context, fn func(ctx context.Context) error) error { + return fn(ctx) +} + +// newTestMasterKeyChain returns a chain holding a single random 32-byte master +// key whose ID is activeID, plus the master key itself for wrapping KEKs. +func newTestMasterKeyChain(t *testing.T, activeID string) (*MasterKeyChain, *masterKey) { + t.Helper() + key := make([]byte, 32) + _, err := rand.Read(key) + require.NoError(t, err) + mk := &masterKey{ID: activeID, key: key} + chain := NewMasterKeyChain(activeID) + chain.keys.Store(activeID, mk) + return chain, mk +} diff --git a/internal/secrets/domain/mocks/mocks.go b/internal/secrets/domain/mocks/mocks.go new file mode 100644 index 0000000..68a0e6b --- /dev/null +++ b/internal/secrets/domain/mocks/mocks.go @@ -0,0 +1,442 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "time" + + "github.com/allisson/secrets/internal/secrets/domain" + mock "github.com/stretchr/testify/mock" +) + +// NewMockSecretRepository creates a new instance of MockSecretRepository. 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 NewMockSecretRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSecretRepository { + mock := &MockSecretRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +// MockSecretRepository is an autogenerated mock type for the SecretRepository type +type MockSecretRepository struct { + mock.Mock +} + +type MockSecretRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSecretRepository) EXPECT() *MockSecretRepository_Expecter { + return &MockSecretRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockSecretRepository +func (_mock *MockSecretRepository) Create(ctx context.Context, secret *domain.Secret) error { + ret := _mock.Called(ctx, secret) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Secret) error); ok { + r0 = returnFunc(ctx, secret) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockSecretRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSecretRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - secret *domain.Secret +func (_e *MockSecretRepository_Expecter) Create(ctx any, secret any) *MockSecretRepository_Create_Call { + return &MockSecretRepository_Create_Call{Call: _e.mock.On("Create", ctx, secret)} +} + +func (_c *MockSecretRepository_Create_Call) Run(run func(ctx context.Context, secret *domain.Secret)) *MockSecretRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *domain.Secret + if args[1] != nil { + arg1 = args[1].(*domain.Secret) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockSecretRepository_Create_Call) Return(err error) *MockSecretRepository_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockSecretRepository_Create_Call) RunAndReturn(run func(ctx context.Context, secret *domain.Secret) error) *MockSecretRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function for the type MockSecretRepository +func (_mock *MockSecretRepository) Delete(ctx context.Context, path string) error { + ret := _mock.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = returnFunc(ctx, path) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockSecretRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockSecretRepository_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockSecretRepository_Expecter) Delete(ctx any, path any) *MockSecretRepository_Delete_Call { + return &MockSecretRepository_Delete_Call{Call: _e.mock.On("Delete", ctx, path)} +} + +func (_c *MockSecretRepository_Delete_Call) Run(run func(ctx context.Context, path string)) *MockSecretRepository_Delete_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockSecretRepository_Delete_Call) Return(err error) *MockSecretRepository_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockSecretRepository_Delete_Call) RunAndReturn(run func(ctx context.Context, path string) error) *MockSecretRepository_Delete_Call { + _c.Call.Return(run) + return _c +} + +// GetByPath provides a mock function for the type MockSecretRepository +func (_mock *MockSecretRepository) GetByPath(ctx context.Context, path string) (*domain.Secret, error) { + ret := _mock.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for GetByPath") + } + + var r0 *domain.Secret + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.Secret, error)); ok { + return returnFunc(ctx, path) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.Secret); ok { + r0 = returnFunc(ctx, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.Secret) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, path) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSecretRepository_GetByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByPath' +type MockSecretRepository_GetByPath_Call struct { + *mock.Call +} + +// GetByPath is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockSecretRepository_Expecter) GetByPath(ctx any, path any) *MockSecretRepository_GetByPath_Call { + return &MockSecretRepository_GetByPath_Call{Call: _e.mock.On("GetByPath", ctx, path)} +} + +func (_c *MockSecretRepository_GetByPath_Call) Run(run func(ctx context.Context, path string)) *MockSecretRepository_GetByPath_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockSecretRepository_GetByPath_Call) Return(secret *domain.Secret, err error) *MockSecretRepository_GetByPath_Call { + _c.Call.Return(secret, err) + return _c +} + +func (_c *MockSecretRepository_GetByPath_Call) RunAndReturn(run func(ctx context.Context, path string) (*domain.Secret, error)) *MockSecretRepository_GetByPath_Call { + _c.Call.Return(run) + return _c +} + +// GetByPathAndVersion provides a mock function for the type MockSecretRepository +func (_mock *MockSecretRepository) GetByPathAndVersion(ctx context.Context, path string, version uint) (*domain.Secret, error) { + ret := _mock.Called(ctx, path, version) + + if len(ret) == 0 { + panic("no return value specified for GetByPathAndVersion") + } + + var r0 *domain.Secret + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) (*domain.Secret, error)); ok { + return returnFunc(ctx, path, version) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) *domain.Secret); ok { + r0 = returnFunc(ctx, path, version) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.Secret) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, uint) error); ok { + r1 = returnFunc(ctx, path, version) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSecretRepository_GetByPathAndVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByPathAndVersion' +type MockSecretRepository_GetByPathAndVersion_Call struct { + *mock.Call +} + +// GetByPathAndVersion is a helper method to define mock.On call +// - ctx context.Context +// - path string +// - version uint +func (_e *MockSecretRepository_Expecter) GetByPathAndVersion(ctx any, path any, version any) *MockSecretRepository_GetByPathAndVersion_Call { + return &MockSecretRepository_GetByPathAndVersion_Call{Call: _e.mock.On("GetByPathAndVersion", ctx, path, version)} +} + +func (_c *MockSecretRepository_GetByPathAndVersion_Call) Run(run func(ctx context.Context, path string, version uint)) *MockSecretRepository_GetByPathAndVersion_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 uint + if args[2] != nil { + arg2 = args[2].(uint) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSecretRepository_GetByPathAndVersion_Call) Return(secret *domain.Secret, err error) *MockSecretRepository_GetByPathAndVersion_Call { + _c.Call.Return(secret, err) + return _c +} + +func (_c *MockSecretRepository_GetByPathAndVersion_Call) RunAndReturn(run func(ctx context.Context, path string, version uint) (*domain.Secret, error)) *MockSecretRepository_GetByPathAndVersion_Call { + _c.Call.Return(run) + return _c +} + +// HardDelete provides a mock function for the type MockSecretRepository +func (_mock *MockSecretRepository) HardDelete(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error) { + ret := _mock.Called(ctx, olderThan, dryRun) + + if len(ret) == 0 { + panic("no return value specified for HardDelete") + } + + var r0 int64 + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) (int64, error)); ok { + return returnFunc(ctx, olderThan, dryRun) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) int64); ok { + r0 = returnFunc(ctx, olderThan, dryRun) + } else { + r0 = ret.Get(0).(int64) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, bool) error); ok { + r1 = returnFunc(ctx, olderThan, dryRun) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSecretRepository_HardDelete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HardDelete' +type MockSecretRepository_HardDelete_Call struct { + *mock.Call +} + +// HardDelete is a helper method to define mock.On call +// - ctx context.Context +// - olderThan time.Time +// - dryRun bool +func (_e *MockSecretRepository_Expecter) HardDelete(ctx any, olderThan any, dryRun any) *MockSecretRepository_HardDelete_Call { + return &MockSecretRepository_HardDelete_Call{Call: _e.mock.On("HardDelete", ctx, olderThan, dryRun)} +} + +func (_c *MockSecretRepository_HardDelete_Call) Run(run func(ctx context.Context, olderThan time.Time, dryRun bool)) *MockSecretRepository_HardDelete_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 time.Time + if args[1] != nil { + arg1 = args[1].(time.Time) + } + var arg2 bool + if args[2] != nil { + arg2 = args[2].(bool) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSecretRepository_HardDelete_Call) Return(n int64, err error) *MockSecretRepository_HardDelete_Call { + _c.Call.Return(n, err) + return _c +} + +func (_c *MockSecretRepository_HardDelete_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)) *MockSecretRepository_HardDelete_Call { + _c.Call.Return(run) + return _c +} + +// ListCursor provides a mock function for the type MockSecretRepository +func (_mock *MockSecretRepository) ListCursor(ctx context.Context, afterPath *string, limit int) ([]*domain.Secret, error) { + ret := _mock.Called(ctx, afterPath, limit) + + if len(ret) == 0 { + panic("no return value specified for ListCursor") + } + + var r0 []*domain.Secret + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) ([]*domain.Secret, error)); ok { + return returnFunc(ctx, afterPath, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) []*domain.Secret); ok { + r0 = returnFunc(ctx, afterPath, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*domain.Secret) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, *string, int) error); ok { + r1 = returnFunc(ctx, afterPath, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSecretRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' +type MockSecretRepository_ListCursor_Call struct { + *mock.Call +} + +// ListCursor is a helper method to define mock.On call +// - ctx context.Context +// - afterPath *string +// - limit int +func (_e *MockSecretRepository_Expecter) ListCursor(ctx any, afterPath any, limit any) *MockSecretRepository_ListCursor_Call { + return &MockSecretRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterPath, limit)} +} + +func (_c *MockSecretRepository_ListCursor_Call) Run(run func(ctx context.Context, afterPath *string, limit int)) *MockSecretRepository_ListCursor_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 int + if args[2] != nil { + arg2 = args[2].(int) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSecretRepository_ListCursor_Call) Return(secrets []*domain.Secret, err error) *MockSecretRepository_ListCursor_Call { + _c.Call.Return(secrets, err) + return _c +} + +func (_c *MockSecretRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterPath *string, limit int) ([]*domain.Secret, error)) *MockSecretRepository_ListCursor_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/secrets/usecase/mocks/mocks.go b/internal/secrets/usecase/mocks/mocks.go index 87578ba..435547e 100644 --- a/internal/secrets/usecase/mocks/mocks.go +++ b/internal/secrets/usecase/mocks/mocks.go @@ -6,441 +6,11 @@ package mocks import ( "context" - "time" "github.com/allisson/secrets/internal/secrets/domain" mock "github.com/stretchr/testify/mock" ) -// NewMockSecretRepository creates a new instance of MockSecretRepository. 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 NewMockSecretRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *MockSecretRepository { - mock := &MockSecretRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - -// MockSecretRepository is an autogenerated mock type for the SecretRepository type -type MockSecretRepository struct { - mock.Mock -} - -type MockSecretRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *MockSecretRepository) EXPECT() *MockSecretRepository_Expecter { - return &MockSecretRepository_Expecter{mock: &_m.Mock} -} - -// Create provides a mock function for the type MockSecretRepository -func (_mock *MockSecretRepository) Create(ctx context.Context, secret *domain.Secret) error { - ret := _mock.Called(ctx, secret) - - if len(ret) == 0 { - panic("no return value specified for Create") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Secret) error); ok { - r0 = returnFunc(ctx, secret) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockSecretRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' -type MockSecretRepository_Create_Call struct { - *mock.Call -} - -// Create is a helper method to define mock.On call -// - ctx context.Context -// - secret *domain.Secret -func (_e *MockSecretRepository_Expecter) Create(ctx interface{}, secret interface{}) *MockSecretRepository_Create_Call { - return &MockSecretRepository_Create_Call{Call: _e.mock.On("Create", ctx, secret)} -} - -func (_c *MockSecretRepository_Create_Call) Run(run func(ctx context.Context, secret *domain.Secret)) *MockSecretRepository_Create_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *domain.Secret - if args[1] != nil { - arg1 = args[1].(*domain.Secret) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockSecretRepository_Create_Call) Return(err error) *MockSecretRepository_Create_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockSecretRepository_Create_Call) RunAndReturn(run func(ctx context.Context, secret *domain.Secret) error) *MockSecretRepository_Create_Call { - _c.Call.Return(run) - return _c -} - -// Delete provides a mock function for the type MockSecretRepository -func (_mock *MockSecretRepository) Delete(ctx context.Context, path string) error { - ret := _mock.Called(ctx, path) - - if len(ret) == 0 { - panic("no return value specified for Delete") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = returnFunc(ctx, path) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockSecretRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' -type MockSecretRepository_Delete_Call struct { - *mock.Call -} - -// Delete is a helper method to define mock.On call -// - ctx context.Context -// - path string -func (_e *MockSecretRepository_Expecter) Delete(ctx interface{}, path interface{}) *MockSecretRepository_Delete_Call { - return &MockSecretRepository_Delete_Call{Call: _e.mock.On("Delete", ctx, path)} -} - -func (_c *MockSecretRepository_Delete_Call) Run(run func(ctx context.Context, path string)) *MockSecretRepository_Delete_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockSecretRepository_Delete_Call) Return(err error) *MockSecretRepository_Delete_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockSecretRepository_Delete_Call) RunAndReturn(run func(ctx context.Context, path string) error) *MockSecretRepository_Delete_Call { - _c.Call.Return(run) - return _c -} - -// GetByPath provides a mock function for the type MockSecretRepository -func (_mock *MockSecretRepository) GetByPath(ctx context.Context, path string) (*domain.Secret, error) { - ret := _mock.Called(ctx, path) - - if len(ret) == 0 { - panic("no return value specified for GetByPath") - } - - var r0 *domain.Secret - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.Secret, error)); ok { - return returnFunc(ctx, path) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.Secret); ok { - r0 = returnFunc(ctx, path) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.Secret) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = returnFunc(ctx, path) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockSecretRepository_GetByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByPath' -type MockSecretRepository_GetByPath_Call struct { - *mock.Call -} - -// GetByPath is a helper method to define mock.On call -// - ctx context.Context -// - path string -func (_e *MockSecretRepository_Expecter) GetByPath(ctx interface{}, path interface{}) *MockSecretRepository_GetByPath_Call { - return &MockSecretRepository_GetByPath_Call{Call: _e.mock.On("GetByPath", ctx, path)} -} - -func (_c *MockSecretRepository_GetByPath_Call) Run(run func(ctx context.Context, path string)) *MockSecretRepository_GetByPath_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockSecretRepository_GetByPath_Call) Return(secret *domain.Secret, err error) *MockSecretRepository_GetByPath_Call { - _c.Call.Return(secret, err) - return _c -} - -func (_c *MockSecretRepository_GetByPath_Call) RunAndReturn(run func(ctx context.Context, path string) (*domain.Secret, error)) *MockSecretRepository_GetByPath_Call { - _c.Call.Return(run) - return _c -} - -// GetByPathAndVersion provides a mock function for the type MockSecretRepository -func (_mock *MockSecretRepository) GetByPathAndVersion(ctx context.Context, path string, version uint) (*domain.Secret, error) { - ret := _mock.Called(ctx, path, version) - - if len(ret) == 0 { - panic("no return value specified for GetByPathAndVersion") - } - - var r0 *domain.Secret - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) (*domain.Secret, error)); ok { - return returnFunc(ctx, path, version) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) *domain.Secret); ok { - r0 = returnFunc(ctx, path, version) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.Secret) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, string, uint) error); ok { - r1 = returnFunc(ctx, path, version) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockSecretRepository_GetByPathAndVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByPathAndVersion' -type MockSecretRepository_GetByPathAndVersion_Call struct { - *mock.Call -} - -// GetByPathAndVersion is a helper method to define mock.On call -// - ctx context.Context -// - path string -// - version uint -func (_e *MockSecretRepository_Expecter) GetByPathAndVersion(ctx interface{}, path interface{}, version interface{}) *MockSecretRepository_GetByPathAndVersion_Call { - return &MockSecretRepository_GetByPathAndVersion_Call{Call: _e.mock.On("GetByPathAndVersion", ctx, path, version)} -} - -func (_c *MockSecretRepository_GetByPathAndVersion_Call) Run(run func(ctx context.Context, path string, version uint)) *MockSecretRepository_GetByPathAndVersion_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 uint - if args[2] != nil { - arg2 = args[2].(uint) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockSecretRepository_GetByPathAndVersion_Call) Return(secret *domain.Secret, err error) *MockSecretRepository_GetByPathAndVersion_Call { - _c.Call.Return(secret, err) - return _c -} - -func (_c *MockSecretRepository_GetByPathAndVersion_Call) RunAndReturn(run func(ctx context.Context, path string, version uint) (*domain.Secret, error)) *MockSecretRepository_GetByPathAndVersion_Call { - _c.Call.Return(run) - return _c -} - -// HardDelete provides a mock function for the type MockSecretRepository -func (_mock *MockSecretRepository) HardDelete(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error) { - ret := _mock.Called(ctx, olderThan, dryRun) - - if len(ret) == 0 { - panic("no return value specified for HardDelete") - } - - var r0 int64 - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) (int64, error)); ok { - return returnFunc(ctx, olderThan, dryRun) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) int64); ok { - r0 = returnFunc(ctx, olderThan, dryRun) - } else { - r0 = ret.Get(0).(int64) - } - if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, bool) error); ok { - r1 = returnFunc(ctx, olderThan, dryRun) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockSecretRepository_HardDelete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HardDelete' -type MockSecretRepository_HardDelete_Call struct { - *mock.Call -} - -// HardDelete is a helper method to define mock.On call -// - ctx context.Context -// - olderThan time.Time -// - dryRun bool -func (_e *MockSecretRepository_Expecter) HardDelete(ctx interface{}, olderThan interface{}, dryRun interface{}) *MockSecretRepository_HardDelete_Call { - return &MockSecretRepository_HardDelete_Call{Call: _e.mock.On("HardDelete", ctx, olderThan, dryRun)} -} - -func (_c *MockSecretRepository_HardDelete_Call) Run(run func(ctx context.Context, olderThan time.Time, dryRun bool)) *MockSecretRepository_HardDelete_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 time.Time - if args[1] != nil { - arg1 = args[1].(time.Time) - } - var arg2 bool - if args[2] != nil { - arg2 = args[2].(bool) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockSecretRepository_HardDelete_Call) Return(n int64, err error) *MockSecretRepository_HardDelete_Call { - _c.Call.Return(n, err) - return _c -} - -func (_c *MockSecretRepository_HardDelete_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)) *MockSecretRepository_HardDelete_Call { - _c.Call.Return(run) - return _c -} - -// ListCursor provides a mock function for the type MockSecretRepository -func (_mock *MockSecretRepository) ListCursor(ctx context.Context, afterPath *string, limit int) ([]*domain.Secret, error) { - ret := _mock.Called(ctx, afterPath, limit) - - if len(ret) == 0 { - panic("no return value specified for ListCursor") - } - - var r0 []*domain.Secret - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) ([]*domain.Secret, error)); ok { - return returnFunc(ctx, afterPath, limit) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) []*domain.Secret); ok { - r0 = returnFunc(ctx, afterPath, limit) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*domain.Secret) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, *string, int) error); ok { - r1 = returnFunc(ctx, afterPath, limit) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockSecretRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' -type MockSecretRepository_ListCursor_Call struct { - *mock.Call -} - -// ListCursor is a helper method to define mock.On call -// - ctx context.Context -// - afterPath *string -// - limit int -func (_e *MockSecretRepository_Expecter) ListCursor(ctx interface{}, afterPath interface{}, limit interface{}) *MockSecretRepository_ListCursor_Call { - return &MockSecretRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterPath, limit)} -} - -func (_c *MockSecretRepository_ListCursor_Call) Run(run func(ctx context.Context, afterPath *string, limit int)) *MockSecretRepository_ListCursor_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 int - if args[2] != nil { - arg2 = args[2].(int) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockSecretRepository_ListCursor_Call) Return(secrets []*domain.Secret, err error) *MockSecretRepository_ListCursor_Call { - _c.Call.Return(secrets, err) - return _c -} - -func (_c *MockSecretRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterPath *string, limit int) ([]*domain.Secret, error)) *MockSecretRepository_ListCursor_Call { - _c.Call.Return(run) - return _c -} - // NewMockSecretUseCase creates a new instance of MockSecretUseCase. 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 NewMockSecretUseCase(t interface { @@ -505,7 +75,7 @@ type MockSecretUseCase_CreateOrUpdate_Call struct { // - ctx context.Context // - path string // - value []byte -func (_e *MockSecretUseCase_Expecter) CreateOrUpdate(ctx interface{}, path interface{}, value interface{}) *MockSecretUseCase_CreateOrUpdate_Call { +func (_e *MockSecretUseCase_Expecter) CreateOrUpdate(ctx any, path any, value any) *MockSecretUseCase_CreateOrUpdate_Call { return &MockSecretUseCase_CreateOrUpdate_Call{Call: _e.mock.On("CreateOrUpdate", ctx, path, value)} } @@ -567,7 +137,7 @@ type MockSecretUseCase_Delete_Call struct { // Delete is a helper method to define mock.On call // - ctx context.Context // - path string -func (_e *MockSecretUseCase_Expecter) Delete(ctx interface{}, path interface{}) *MockSecretUseCase_Delete_Call { +func (_e *MockSecretUseCase_Expecter) Delete(ctx any, path any) *MockSecretUseCase_Delete_Call { return &MockSecretUseCase_Delete_Call{Call: _e.mock.On("Delete", ctx, path)} } @@ -635,7 +205,7 @@ type MockSecretUseCase_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context // - path string -func (_e *MockSecretUseCase_Expecter) Get(ctx interface{}, path interface{}) *MockSecretUseCase_Get_Call { +func (_e *MockSecretUseCase_Expecter) Get(ctx any, path any) *MockSecretUseCase_Get_Call { return &MockSecretUseCase_Get_Call{Call: _e.mock.On("Get", ctx, path)} } @@ -704,7 +274,7 @@ type MockSecretUseCase_GetByVersion_Call struct { // - ctx context.Context // - path string // - version uint -func (_e *MockSecretUseCase_Expecter) GetByVersion(ctx interface{}, path interface{}, version interface{}) *MockSecretUseCase_GetByVersion_Call { +func (_e *MockSecretUseCase_Expecter) GetByVersion(ctx any, path any, version any) *MockSecretUseCase_GetByVersion_Call { return &MockSecretUseCase_GetByVersion_Call{Call: _e.mock.On("GetByVersion", ctx, path, version)} } @@ -778,7 +348,7 @@ type MockSecretUseCase_ListCursor_Call struct { // - ctx context.Context // - afterPath *string // - limit int -func (_e *MockSecretUseCase_Expecter) ListCursor(ctx interface{}, afterPath interface{}, limit interface{}) *MockSecretUseCase_ListCursor_Call { +func (_e *MockSecretUseCase_Expecter) ListCursor(ctx any, afterPath any, limit any) *MockSecretUseCase_ListCursor_Call { return &MockSecretUseCase_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterPath, limit)} } @@ -850,7 +420,7 @@ type MockSecretUseCase_PurgeDeleted_Call struct { // - ctx context.Context // - olderThanDays int // - dryRun bool -func (_e *MockSecretUseCase_Expecter) PurgeDeleted(ctx interface{}, olderThanDays interface{}, dryRun interface{}) *MockSecretUseCase_PurgeDeleted_Call { +func (_e *MockSecretUseCase_Expecter) PurgeDeleted(ctx any, olderThanDays any, dryRun any) *MockSecretUseCase_PurgeDeleted_Call { return &MockSecretUseCase_PurgeDeleted_Call{Call: _e.mock.On("PurgeDeleted", ctx, olderThanDays, dryRun)} } diff --git a/internal/secrets/usecase/secret_usecase_test.go b/internal/secrets/usecase/secret_usecase_test.go index 4839cb6..363d4f1 100644 --- a/internal/secrets/usecase/secret_usecase_test.go +++ b/internal/secrets/usecase/secret_usecase_test.go @@ -14,8 +14,8 @@ import ( apperrors "github.com/allisson/secrets/internal/errors" "github.com/allisson/secrets/internal/keyring" secretsDomain "github.com/allisson/secrets/internal/secrets/domain" + "github.com/allisson/secrets/internal/secrets/domain/mocks" "github.com/allisson/secrets/internal/secrets/usecase" - "github.com/allisson/secrets/internal/secrets/usecase/mocks" ) // noopTxManager runs the function with no real transaction. The secrets diff --git a/internal/tokenization/domain/mocks/mocks.go b/internal/tokenization/domain/mocks/mocks.go new file mode 100644 index 0000000..c33a1da --- /dev/null +++ b/internal/tokenization/domain/mocks/mocks.go @@ -0,0 +1,1051 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "time" + + "github.com/allisson/secrets/internal/tokenization/domain" + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockTokenizationKeyRepository creates a new instance of MockTokenizationKeyRepository. 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 NewMockTokenizationKeyRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockTokenizationKeyRepository { + mock := &MockTokenizationKeyRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +// MockTokenizationKeyRepository is an autogenerated mock type for the TokenizationKeyRepository type +type MockTokenizationKeyRepository struct { + mock.Mock +} + +type MockTokenizationKeyRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockTokenizationKeyRepository) EXPECT() *MockTokenizationKeyRepository_Expecter { + return &MockTokenizationKeyRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockTokenizationKeyRepository +func (_mock *MockTokenizationKeyRepository) Create(ctx context.Context, key *domain.TokenizationKey) error { + ret := _mock.Called(ctx, key) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.TokenizationKey) error); ok { + r0 = returnFunc(ctx, key) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTokenizationKeyRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockTokenizationKeyRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - key *domain.TokenizationKey +func (_e *MockTokenizationKeyRepository_Expecter) Create(ctx any, key any) *MockTokenizationKeyRepository_Create_Call { + return &MockTokenizationKeyRepository_Create_Call{Call: _e.mock.On("Create", ctx, key)} +} + +func (_c *MockTokenizationKeyRepository_Create_Call) Run(run func(ctx context.Context, key *domain.TokenizationKey)) *MockTokenizationKeyRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *domain.TokenizationKey + if args[1] != nil { + arg1 = args[1].(*domain.TokenizationKey) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenizationKeyRepository_Create_Call) Return(err error) *MockTokenizationKeyRepository_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTokenizationKeyRepository_Create_Call) RunAndReturn(run func(ctx context.Context, key *domain.TokenizationKey) error) *MockTokenizationKeyRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function for the type MockTokenizationKeyRepository +func (_mock *MockTokenizationKeyRepository) Delete(ctx context.Context, name string) error { + ret := _mock.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = returnFunc(ctx, name) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTokenizationKeyRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockTokenizationKeyRepository_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *MockTokenizationKeyRepository_Expecter) Delete(ctx any, name any) *MockTokenizationKeyRepository_Delete_Call { + return &MockTokenizationKeyRepository_Delete_Call{Call: _e.mock.On("Delete", ctx, name)} +} + +func (_c *MockTokenizationKeyRepository_Delete_Call) Run(run func(ctx context.Context, name string)) *MockTokenizationKeyRepository_Delete_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenizationKeyRepository_Delete_Call) Return(err error) *MockTokenizationKeyRepository_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTokenizationKeyRepository_Delete_Call) RunAndReturn(run func(ctx context.Context, name string) error) *MockTokenizationKeyRepository_Delete_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function for the type MockTokenizationKeyRepository +func (_mock *MockTokenizationKeyRepository) Get(ctx context.Context, keyID uuid.UUID) (*domain.TokenizationKey, error) { + ret := _mock.Called(ctx, keyID) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *domain.TokenizationKey + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (*domain.TokenizationKey, error)); ok { + return returnFunc(ctx, keyID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) *domain.TokenizationKey); ok { + r0 = returnFunc(ctx, keyID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.TokenizationKey) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { + r1 = returnFunc(ctx, keyID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenizationKeyRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockTokenizationKeyRepository_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - keyID uuid.UUID +func (_e *MockTokenizationKeyRepository_Expecter) Get(ctx any, keyID any) *MockTokenizationKeyRepository_Get_Call { + return &MockTokenizationKeyRepository_Get_Call{Call: _e.mock.On("Get", ctx, keyID)} +} + +func (_c *MockTokenizationKeyRepository_Get_Call) Run(run func(ctx context.Context, keyID uuid.UUID)) *MockTokenizationKeyRepository_Get_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 *MockTokenizationKeyRepository_Get_Call) Return(tokenizationKey *domain.TokenizationKey, err error) *MockTokenizationKeyRepository_Get_Call { + _c.Call.Return(tokenizationKey, err) + return _c +} + +func (_c *MockTokenizationKeyRepository_Get_Call) RunAndReturn(run func(ctx context.Context, keyID uuid.UUID) (*domain.TokenizationKey, error)) *MockTokenizationKeyRepository_Get_Call { + _c.Call.Return(run) + return _c +} + +// GetByName provides a mock function for the type MockTokenizationKeyRepository +func (_mock *MockTokenizationKeyRepository) GetByName(ctx context.Context, name string) (*domain.TokenizationKey, error) { + ret := _mock.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for GetByName") + } + + var r0 *domain.TokenizationKey + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.TokenizationKey, error)); ok { + return returnFunc(ctx, name) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.TokenizationKey); ok { + r0 = returnFunc(ctx, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.TokenizationKey) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, name) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenizationKeyRepository_GetByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByName' +type MockTokenizationKeyRepository_GetByName_Call struct { + *mock.Call +} + +// GetByName is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *MockTokenizationKeyRepository_Expecter) GetByName(ctx any, name any) *MockTokenizationKeyRepository_GetByName_Call { + return &MockTokenizationKeyRepository_GetByName_Call{Call: _e.mock.On("GetByName", ctx, name)} +} + +func (_c *MockTokenizationKeyRepository_GetByName_Call) Run(run func(ctx context.Context, name string)) *MockTokenizationKeyRepository_GetByName_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenizationKeyRepository_GetByName_Call) Return(tokenizationKey *domain.TokenizationKey, err error) *MockTokenizationKeyRepository_GetByName_Call { + _c.Call.Return(tokenizationKey, err) + return _c +} + +func (_c *MockTokenizationKeyRepository_GetByName_Call) RunAndReturn(run func(ctx context.Context, name string) (*domain.TokenizationKey, error)) *MockTokenizationKeyRepository_GetByName_Call { + _c.Call.Return(run) + return _c +} + +// GetByNameAndVersion provides a mock function for the type MockTokenizationKeyRepository +func (_mock *MockTokenizationKeyRepository) GetByNameAndVersion(ctx context.Context, name string, version uint) (*domain.TokenizationKey, error) { + ret := _mock.Called(ctx, name, version) + + if len(ret) == 0 { + panic("no return value specified for GetByNameAndVersion") + } + + var r0 *domain.TokenizationKey + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) (*domain.TokenizationKey, error)); ok { + return returnFunc(ctx, name, version) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) *domain.TokenizationKey); ok { + r0 = returnFunc(ctx, name, version) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.TokenizationKey) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, uint) error); ok { + r1 = returnFunc(ctx, name, version) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenizationKeyRepository_GetByNameAndVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByNameAndVersion' +type MockTokenizationKeyRepository_GetByNameAndVersion_Call struct { + *mock.Call +} + +// GetByNameAndVersion is a helper method to define mock.On call +// - ctx context.Context +// - name string +// - version uint +func (_e *MockTokenizationKeyRepository_Expecter) GetByNameAndVersion(ctx any, name any, version any) *MockTokenizationKeyRepository_GetByNameAndVersion_Call { + return &MockTokenizationKeyRepository_GetByNameAndVersion_Call{Call: _e.mock.On("GetByNameAndVersion", ctx, name, version)} +} + +func (_c *MockTokenizationKeyRepository_GetByNameAndVersion_Call) Run(run func(ctx context.Context, name string, version uint)) *MockTokenizationKeyRepository_GetByNameAndVersion_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 uint + if args[2] != nil { + arg2 = args[2].(uint) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockTokenizationKeyRepository_GetByNameAndVersion_Call) Return(tokenizationKey *domain.TokenizationKey, err error) *MockTokenizationKeyRepository_GetByNameAndVersion_Call { + _c.Call.Return(tokenizationKey, err) + return _c +} + +func (_c *MockTokenizationKeyRepository_GetByNameAndVersion_Call) RunAndReturn(run func(ctx context.Context, name string, version uint) (*domain.TokenizationKey, error)) *MockTokenizationKeyRepository_GetByNameAndVersion_Call { + _c.Call.Return(run) + return _c +} + +// HardDelete provides a mock function for the type MockTokenizationKeyRepository +func (_mock *MockTokenizationKeyRepository) HardDelete(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error) { + ret := _mock.Called(ctx, olderThan, dryRun) + + if len(ret) == 0 { + panic("no return value specified for HardDelete") + } + + var r0 int64 + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) (int64, error)); ok { + return returnFunc(ctx, olderThan, dryRun) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) int64); ok { + r0 = returnFunc(ctx, olderThan, dryRun) + } else { + r0 = ret.Get(0).(int64) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, bool) error); ok { + r1 = returnFunc(ctx, olderThan, dryRun) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenizationKeyRepository_HardDelete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HardDelete' +type MockTokenizationKeyRepository_HardDelete_Call struct { + *mock.Call +} + +// HardDelete is a helper method to define mock.On call +// - ctx context.Context +// - olderThan time.Time +// - dryRun bool +func (_e *MockTokenizationKeyRepository_Expecter) HardDelete(ctx any, olderThan any, dryRun any) *MockTokenizationKeyRepository_HardDelete_Call { + return &MockTokenizationKeyRepository_HardDelete_Call{Call: _e.mock.On("HardDelete", ctx, olderThan, dryRun)} +} + +func (_c *MockTokenizationKeyRepository_HardDelete_Call) Run(run func(ctx context.Context, olderThan time.Time, dryRun bool)) *MockTokenizationKeyRepository_HardDelete_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 time.Time + if args[1] != nil { + arg1 = args[1].(time.Time) + } + var arg2 bool + if args[2] != nil { + arg2 = args[2].(bool) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockTokenizationKeyRepository_HardDelete_Call) Return(n int64, err error) *MockTokenizationKeyRepository_HardDelete_Call { + _c.Call.Return(n, err) + return _c +} + +func (_c *MockTokenizationKeyRepository_HardDelete_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)) *MockTokenizationKeyRepository_HardDelete_Call { + _c.Call.Return(run) + return _c +} + +// ListCursor provides a mock function for the type MockTokenizationKeyRepository +func (_mock *MockTokenizationKeyRepository) ListCursor(ctx context.Context, afterName *string, limit int) ([]*domain.TokenizationKey, error) { + ret := _mock.Called(ctx, afterName, limit) + + if len(ret) == 0 { + panic("no return value specified for ListCursor") + } + + var r0 []*domain.TokenizationKey + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) ([]*domain.TokenizationKey, error)); ok { + return returnFunc(ctx, afterName, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) []*domain.TokenizationKey); ok { + r0 = returnFunc(ctx, afterName, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*domain.TokenizationKey) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, *string, int) error); ok { + r1 = returnFunc(ctx, afterName, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenizationKeyRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' +type MockTokenizationKeyRepository_ListCursor_Call struct { + *mock.Call +} + +// ListCursor is a helper method to define mock.On call +// - ctx context.Context +// - afterName *string +// - limit int +func (_e *MockTokenizationKeyRepository_Expecter) ListCursor(ctx any, afterName any, limit any) *MockTokenizationKeyRepository_ListCursor_Call { + return &MockTokenizationKeyRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterName, limit)} +} + +func (_c *MockTokenizationKeyRepository_ListCursor_Call) Run(run func(ctx context.Context, afterName *string, limit int)) *MockTokenizationKeyRepository_ListCursor_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 int + if args[2] != nil { + arg2 = args[2].(int) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockTokenizationKeyRepository_ListCursor_Call) Return(tokenizationKeys []*domain.TokenizationKey, err error) *MockTokenizationKeyRepository_ListCursor_Call { + _c.Call.Return(tokenizationKeys, err) + return _c +} + +func (_c *MockTokenizationKeyRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterName *string, limit int) ([]*domain.TokenizationKey, error)) *MockTokenizationKeyRepository_ListCursor_Call { + _c.Call.Return(run) + return _c +} + +// NewMockTokenRepository creates a new instance of MockTokenRepository. 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 NewMockTokenRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockTokenRepository { + mock := &MockTokenRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +// MockTokenRepository is an autogenerated mock type for the TokenRepository type +type MockTokenRepository struct { + mock.Mock +} + +type MockTokenRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockTokenRepository) EXPECT() *MockTokenRepository_Expecter { + return &MockTokenRepository_Expecter{mock: &_m.Mock} +} + +// CountExpired provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) CountExpired(ctx context.Context, olderThan time.Time) (int64, error) { + ret := _mock.Called(ctx, olderThan) + + if len(ret) == 0 { + panic("no return value specified for CountExpired") + } + + var r0 int64 + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) (int64, error)); ok { + return returnFunc(ctx, olderThan) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) int64); ok { + r0 = returnFunc(ctx, olderThan) + } else { + r0 = ret.Get(0).(int64) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time) error); ok { + r1 = returnFunc(ctx, olderThan) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenRepository_CountExpired_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CountExpired' +type MockTokenRepository_CountExpired_Call struct { + *mock.Call +} + +// CountExpired is a helper method to define mock.On call +// - ctx context.Context +// - olderThan time.Time +func (_e *MockTokenRepository_Expecter) CountExpired(ctx any, olderThan any) *MockTokenRepository_CountExpired_Call { + return &MockTokenRepository_CountExpired_Call{Call: _e.mock.On("CountExpired", ctx, olderThan)} +} + +func (_c *MockTokenRepository_CountExpired_Call) Run(run func(ctx context.Context, olderThan time.Time)) *MockTokenRepository_CountExpired_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 time.Time + if args[1] != nil { + arg1 = args[1].(time.Time) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_CountExpired_Call) Return(n int64, err error) *MockTokenRepository_CountExpired_Call { + _c.Call.Return(n, err) + return _c +} + +func (_c *MockTokenRepository_CountExpired_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time) (int64, error)) *MockTokenRepository_CountExpired_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) Create(ctx context.Context, token *domain.Token) error { + ret := _mock.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Token) error); ok { + r0 = returnFunc(ctx, token) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTokenRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockTokenRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - token *domain.Token +func (_e *MockTokenRepository_Expecter) Create(ctx any, token any) *MockTokenRepository_Create_Call { + return &MockTokenRepository_Create_Call{Call: _e.mock.On("Create", ctx, token)} +} + +func (_c *MockTokenRepository_Create_Call) Run(run func(ctx context.Context, token *domain.Token)) *MockTokenRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *domain.Token + if args[1] != nil { + arg1 = args[1].(*domain.Token) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_Create_Call) Return(err error) *MockTokenRepository_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTokenRepository_Create_Call) RunAndReturn(run func(ctx context.Context, token *domain.Token) error) *MockTokenRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// CreateBatch provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) CreateBatch(ctx context.Context, tokens []*domain.Token) error { + ret := _mock.Called(ctx, tokens) + + if len(ret) == 0 { + panic("no return value specified for CreateBatch") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, []*domain.Token) error); ok { + r0 = returnFunc(ctx, tokens) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTokenRepository_CreateBatch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateBatch' +type MockTokenRepository_CreateBatch_Call struct { + *mock.Call +} + +// CreateBatch is a helper method to define mock.On call +// - ctx context.Context +// - tokens []*domain.Token +func (_e *MockTokenRepository_Expecter) CreateBatch(ctx any, tokens any) *MockTokenRepository_CreateBatch_Call { + return &MockTokenRepository_CreateBatch_Call{Call: _e.mock.On("CreateBatch", ctx, tokens)} +} + +func (_c *MockTokenRepository_CreateBatch_Call) Run(run func(ctx context.Context, tokens []*domain.Token)) *MockTokenRepository_CreateBatch_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 []*domain.Token + if args[1] != nil { + arg1 = args[1].([]*domain.Token) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_CreateBatch_Call) Return(err error) *MockTokenRepository_CreateBatch_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTokenRepository_CreateBatch_Call) RunAndReturn(run func(ctx context.Context, tokens []*domain.Token) error) *MockTokenRepository_CreateBatch_Call { + _c.Call.Return(run) + return _c +} + +// DeleteExpired provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) DeleteExpired(ctx context.Context, olderThan time.Time) (int64, error) { + ret := _mock.Called(ctx, olderThan) + + if len(ret) == 0 { + panic("no return value specified for DeleteExpired") + } + + var r0 int64 + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) (int64, error)); ok { + return returnFunc(ctx, olderThan) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) int64); ok { + r0 = returnFunc(ctx, olderThan) + } else { + r0 = ret.Get(0).(int64) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time) error); ok { + r1 = returnFunc(ctx, olderThan) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenRepository_DeleteExpired_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteExpired' +type MockTokenRepository_DeleteExpired_Call struct { + *mock.Call +} + +// DeleteExpired is a helper method to define mock.On call +// - ctx context.Context +// - olderThan time.Time +func (_e *MockTokenRepository_Expecter) DeleteExpired(ctx any, olderThan any) *MockTokenRepository_DeleteExpired_Call { + return &MockTokenRepository_DeleteExpired_Call{Call: _e.mock.On("DeleteExpired", ctx, olderThan)} +} + +func (_c *MockTokenRepository_DeleteExpired_Call) Run(run func(ctx context.Context, olderThan time.Time)) *MockTokenRepository_DeleteExpired_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 time.Time + if args[1] != nil { + arg1 = args[1].(time.Time) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_DeleteExpired_Call) Return(n int64, err error) *MockTokenRepository_DeleteExpired_Call { + _c.Call.Return(n, err) + return _c +} + +func (_c *MockTokenRepository_DeleteExpired_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time) (int64, error)) *MockTokenRepository_DeleteExpired_Call { + _c.Call.Return(run) + return _c +} + +// GetBatchByTokens provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) GetBatchByTokens(ctx context.Context, tokens []string) ([]*domain.Token, error) { + ret := _mock.Called(ctx, tokens) + + if len(ret) == 0 { + panic("no return value specified for GetBatchByTokens") + } + + var r0 []*domain.Token + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, []string) ([]*domain.Token, error)); ok { + return returnFunc(ctx, tokens) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, []string) []*domain.Token); ok { + r0 = returnFunc(ctx, tokens) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*domain.Token) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, []string) error); ok { + r1 = returnFunc(ctx, tokens) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenRepository_GetBatchByTokens_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBatchByTokens' +type MockTokenRepository_GetBatchByTokens_Call struct { + *mock.Call +} + +// GetBatchByTokens is a helper method to define mock.On call +// - ctx context.Context +// - tokens []string +func (_e *MockTokenRepository_Expecter) GetBatchByTokens(ctx any, tokens any) *MockTokenRepository_GetBatchByTokens_Call { + return &MockTokenRepository_GetBatchByTokens_Call{Call: _e.mock.On("GetBatchByTokens", ctx, tokens)} +} + +func (_c *MockTokenRepository_GetBatchByTokens_Call) Run(run func(ctx context.Context, tokens []string)) *MockTokenRepository_GetBatchByTokens_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_GetBatchByTokens_Call) Return(tokens1 []*domain.Token, err error) *MockTokenRepository_GetBatchByTokens_Call { + _c.Call.Return(tokens1, err) + return _c +} + +func (_c *MockTokenRepository_GetBatchByTokens_Call) RunAndReturn(run func(ctx context.Context, tokens []string) ([]*domain.Token, error)) *MockTokenRepository_GetBatchByTokens_Call { + _c.Call.Return(run) + return _c +} + +// GetByToken provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) GetByToken(ctx context.Context, token string) (*domain.Token, error) { + ret := _mock.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for GetByToken") + } + + var r0 *domain.Token + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.Token, error)); ok { + return returnFunc(ctx, token) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.Token); ok { + r0 = returnFunc(ctx, token) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.Token) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, token) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenRepository_GetByToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByToken' +type MockTokenRepository_GetByToken_Call struct { + *mock.Call +} + +// GetByToken is a helper method to define mock.On call +// - ctx context.Context +// - token string +func (_e *MockTokenRepository_Expecter) GetByToken(ctx any, token any) *MockTokenRepository_GetByToken_Call { + return &MockTokenRepository_GetByToken_Call{Call: _e.mock.On("GetByToken", ctx, token)} +} + +func (_c *MockTokenRepository_GetByToken_Call) Run(run func(ctx context.Context, token string)) *MockTokenRepository_GetByToken_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_GetByToken_Call) Return(token1 *domain.Token, err error) *MockTokenRepository_GetByToken_Call { + _c.Call.Return(token1, err) + return _c +} + +func (_c *MockTokenRepository_GetByToken_Call) RunAndReturn(run func(ctx context.Context, token string) (*domain.Token, error)) *MockTokenRepository_GetByToken_Call { + _c.Call.Return(run) + return _c +} + +// GetByValueHash provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) GetByValueHash(ctx context.Context, keyID uuid.UUID, valueHash string) (*domain.Token, error) { + ret := _mock.Called(ctx, keyID, valueHash) + + if len(ret) == 0 { + panic("no return value specified for GetByValueHash") + } + + var r0 *domain.Token + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) (*domain.Token, error)); ok { + return returnFunc(ctx, keyID, valueHash) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) *domain.Token); ok { + r0 = returnFunc(ctx, keyID, valueHash) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.Token) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, string) error); ok { + r1 = returnFunc(ctx, keyID, valueHash) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokenRepository_GetByValueHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByValueHash' +type MockTokenRepository_GetByValueHash_Call struct { + *mock.Call +} + +// GetByValueHash is a helper method to define mock.On call +// - ctx context.Context +// - keyID uuid.UUID +// - valueHash string +func (_e *MockTokenRepository_Expecter) GetByValueHash(ctx any, keyID any, valueHash any) *MockTokenRepository_GetByValueHash_Call { + return &MockTokenRepository_GetByValueHash_Call{Call: _e.mock.On("GetByValueHash", ctx, keyID, valueHash)} +} + +func (_c *MockTokenRepository_GetByValueHash_Call) Run(run func(ctx context.Context, keyID uuid.UUID, valueHash string)) *MockTokenRepository_GetByValueHash_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 *MockTokenRepository_GetByValueHash_Call) Return(token *domain.Token, err error) *MockTokenRepository_GetByValueHash_Call { + _c.Call.Return(token, err) + return _c +} + +func (_c *MockTokenRepository_GetByValueHash_Call) RunAndReturn(run func(ctx context.Context, keyID uuid.UUID, valueHash string) (*domain.Token, error)) *MockTokenRepository_GetByValueHash_Call { + _c.Call.Return(run) + return _c +} + +// Revoke provides a mock function for the type MockTokenRepository +func (_mock *MockTokenRepository) Revoke(ctx context.Context, token string) error { + ret := _mock.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for Revoke") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = returnFunc(ctx, token) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTokenRepository_Revoke_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Revoke' +type MockTokenRepository_Revoke_Call struct { + *mock.Call +} + +// Revoke is a helper method to define mock.On call +// - ctx context.Context +// - token string +func (_e *MockTokenRepository_Expecter) Revoke(ctx any, token any) *MockTokenRepository_Revoke_Call { + return &MockTokenRepository_Revoke_Call{Call: _e.mock.On("Revoke", ctx, token)} +} + +func (_c *MockTokenRepository_Revoke_Call) Run(run func(ctx context.Context, token string)) *MockTokenRepository_Revoke_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTokenRepository_Revoke_Call) Return(err error) *MockTokenRepository_Revoke_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTokenRepository_Revoke_Call) RunAndReturn(run func(ctx context.Context, token string) error) *MockTokenRepository_Revoke_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/tokenization/testing/helpers.go b/internal/tokenization/testing/helpers.go deleted file mode 100644 index 7b19bb7..0000000 --- a/internal/tokenization/testing/helpers.go +++ /dev/null @@ -1,14 +0,0 @@ -// Package testing provides shared test utilities for tokenization module tests. -package testing - -import ( - "github.com/allisson/secrets/internal/keyring" -) - -// CreateMasterKey creates a test master key with a random 32-byte key. -func CreateMasterKey() *keyring.MasterKey { - return &keyring.MasterKey{ - ID: "test-master-key", - Key: make([]byte, 32), - } -} diff --git a/internal/tokenization/usecase/mocks/mocks.go b/internal/tokenization/usecase/mocks/mocks.go index 772ae67..bf2b58e 100644 --- a/internal/tokenization/usecase/mocks/mocks.go +++ b/internal/tokenization/usecase/mocks/mocks.go @@ -10,1048 +10,9 @@ import ( "github.com/allisson/secrets/internal/keyring" "github.com/allisson/secrets/internal/tokenization/domain" - "github.com/google/uuid" mock "github.com/stretchr/testify/mock" ) - -// NewMockTokenizationKeyRepository creates a new instance of MockTokenizationKeyRepository. 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 NewMockTokenizationKeyRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *MockTokenizationKeyRepository { - mock := &MockTokenizationKeyRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - -// MockTokenizationKeyRepository is an autogenerated mock type for the TokenizationKeyRepository type -type MockTokenizationKeyRepository struct { - mock.Mock -} - -type MockTokenizationKeyRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *MockTokenizationKeyRepository) EXPECT() *MockTokenizationKeyRepository_Expecter { - return &MockTokenizationKeyRepository_Expecter{mock: &_m.Mock} -} - -// Create provides a mock function for the type MockTokenizationKeyRepository -func (_mock *MockTokenizationKeyRepository) Create(ctx context.Context, key *domain.TokenizationKey) error { - ret := _mock.Called(ctx, key) - - if len(ret) == 0 { - panic("no return value specified for Create") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.TokenizationKey) error); ok { - r0 = returnFunc(ctx, key) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTokenizationKeyRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' -type MockTokenizationKeyRepository_Create_Call struct { - *mock.Call -} - -// Create is a helper method to define mock.On call -// - ctx context.Context -// - key *domain.TokenizationKey -func (_e *MockTokenizationKeyRepository_Expecter) Create(ctx interface{}, key interface{}) *MockTokenizationKeyRepository_Create_Call { - return &MockTokenizationKeyRepository_Create_Call{Call: _e.mock.On("Create", ctx, key)} -} - -func (_c *MockTokenizationKeyRepository_Create_Call) Run(run func(ctx context.Context, key *domain.TokenizationKey)) *MockTokenizationKeyRepository_Create_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *domain.TokenizationKey - if args[1] != nil { - arg1 = args[1].(*domain.TokenizationKey) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenizationKeyRepository_Create_Call) Return(err error) *MockTokenizationKeyRepository_Create_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTokenizationKeyRepository_Create_Call) RunAndReturn(run func(ctx context.Context, key *domain.TokenizationKey) error) *MockTokenizationKeyRepository_Create_Call { - _c.Call.Return(run) - return _c -} - -// Delete provides a mock function for the type MockTokenizationKeyRepository -func (_mock *MockTokenizationKeyRepository) Delete(ctx context.Context, name string) error { - ret := _mock.Called(ctx, name) - - if len(ret) == 0 { - panic("no return value specified for Delete") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = returnFunc(ctx, name) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTokenizationKeyRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' -type MockTokenizationKeyRepository_Delete_Call struct { - *mock.Call -} - -// Delete is a helper method to define mock.On call -// - ctx context.Context -// - name string -func (_e *MockTokenizationKeyRepository_Expecter) Delete(ctx interface{}, name interface{}) *MockTokenizationKeyRepository_Delete_Call { - return &MockTokenizationKeyRepository_Delete_Call{Call: _e.mock.On("Delete", ctx, name)} -} - -func (_c *MockTokenizationKeyRepository_Delete_Call) Run(run func(ctx context.Context, name string)) *MockTokenizationKeyRepository_Delete_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenizationKeyRepository_Delete_Call) Return(err error) *MockTokenizationKeyRepository_Delete_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTokenizationKeyRepository_Delete_Call) RunAndReturn(run func(ctx context.Context, name string) error) *MockTokenizationKeyRepository_Delete_Call { - _c.Call.Return(run) - return _c -} - -// Get provides a mock function for the type MockTokenizationKeyRepository -func (_mock *MockTokenizationKeyRepository) Get(ctx context.Context, keyID uuid.UUID) (*domain.TokenizationKey, error) { - ret := _mock.Called(ctx, keyID) - - if len(ret) == 0 { - panic("no return value specified for Get") - } - - var r0 *domain.TokenizationKey - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (*domain.TokenizationKey, error)); ok { - return returnFunc(ctx, keyID) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) *domain.TokenizationKey); ok { - r0 = returnFunc(ctx, keyID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.TokenizationKey) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { - r1 = returnFunc(ctx, keyID) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenizationKeyRepository_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' -type MockTokenizationKeyRepository_Get_Call struct { - *mock.Call -} - -// Get is a helper method to define mock.On call -// - ctx context.Context -// - keyID uuid.UUID -func (_e *MockTokenizationKeyRepository_Expecter) Get(ctx interface{}, keyID interface{}) *MockTokenizationKeyRepository_Get_Call { - return &MockTokenizationKeyRepository_Get_Call{Call: _e.mock.On("Get", ctx, keyID)} -} - -func (_c *MockTokenizationKeyRepository_Get_Call) Run(run func(ctx context.Context, keyID uuid.UUID)) *MockTokenizationKeyRepository_Get_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 *MockTokenizationKeyRepository_Get_Call) Return(tokenizationKey *domain.TokenizationKey, err error) *MockTokenizationKeyRepository_Get_Call { - _c.Call.Return(tokenizationKey, err) - return _c -} - -func (_c *MockTokenizationKeyRepository_Get_Call) RunAndReturn(run func(ctx context.Context, keyID uuid.UUID) (*domain.TokenizationKey, error)) *MockTokenizationKeyRepository_Get_Call { - _c.Call.Return(run) - return _c -} - -// GetByName provides a mock function for the type MockTokenizationKeyRepository -func (_mock *MockTokenizationKeyRepository) GetByName(ctx context.Context, name string) (*domain.TokenizationKey, error) { - ret := _mock.Called(ctx, name) - - if len(ret) == 0 { - panic("no return value specified for GetByName") - } - - var r0 *domain.TokenizationKey - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.TokenizationKey, error)); ok { - return returnFunc(ctx, name) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.TokenizationKey); ok { - r0 = returnFunc(ctx, name) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.TokenizationKey) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = returnFunc(ctx, name) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenizationKeyRepository_GetByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByName' -type MockTokenizationKeyRepository_GetByName_Call struct { - *mock.Call -} - -// GetByName is a helper method to define mock.On call -// - ctx context.Context -// - name string -func (_e *MockTokenizationKeyRepository_Expecter) GetByName(ctx interface{}, name interface{}) *MockTokenizationKeyRepository_GetByName_Call { - return &MockTokenizationKeyRepository_GetByName_Call{Call: _e.mock.On("GetByName", ctx, name)} -} - -func (_c *MockTokenizationKeyRepository_GetByName_Call) Run(run func(ctx context.Context, name string)) *MockTokenizationKeyRepository_GetByName_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenizationKeyRepository_GetByName_Call) Return(tokenizationKey *domain.TokenizationKey, err error) *MockTokenizationKeyRepository_GetByName_Call { - _c.Call.Return(tokenizationKey, err) - return _c -} - -func (_c *MockTokenizationKeyRepository_GetByName_Call) RunAndReturn(run func(ctx context.Context, name string) (*domain.TokenizationKey, error)) *MockTokenizationKeyRepository_GetByName_Call { - _c.Call.Return(run) - return _c -} - -// GetByNameAndVersion provides a mock function for the type MockTokenizationKeyRepository -func (_mock *MockTokenizationKeyRepository) GetByNameAndVersion(ctx context.Context, name string, version uint) (*domain.TokenizationKey, error) { - ret := _mock.Called(ctx, name, version) - - if len(ret) == 0 { - panic("no return value specified for GetByNameAndVersion") - } - - var r0 *domain.TokenizationKey - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) (*domain.TokenizationKey, error)); ok { - return returnFunc(ctx, name, version) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) *domain.TokenizationKey); ok { - r0 = returnFunc(ctx, name, version) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.TokenizationKey) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, string, uint) error); ok { - r1 = returnFunc(ctx, name, version) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenizationKeyRepository_GetByNameAndVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByNameAndVersion' -type MockTokenizationKeyRepository_GetByNameAndVersion_Call struct { - *mock.Call -} - -// GetByNameAndVersion is a helper method to define mock.On call -// - ctx context.Context -// - name string -// - version uint -func (_e *MockTokenizationKeyRepository_Expecter) GetByNameAndVersion(ctx interface{}, name interface{}, version interface{}) *MockTokenizationKeyRepository_GetByNameAndVersion_Call { - return &MockTokenizationKeyRepository_GetByNameAndVersion_Call{Call: _e.mock.On("GetByNameAndVersion", ctx, name, version)} -} - -func (_c *MockTokenizationKeyRepository_GetByNameAndVersion_Call) Run(run func(ctx context.Context, name string, version uint)) *MockTokenizationKeyRepository_GetByNameAndVersion_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 uint - if args[2] != nil { - arg2 = args[2].(uint) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockTokenizationKeyRepository_GetByNameAndVersion_Call) Return(tokenizationKey *domain.TokenizationKey, err error) *MockTokenizationKeyRepository_GetByNameAndVersion_Call { - _c.Call.Return(tokenizationKey, err) - return _c -} - -func (_c *MockTokenizationKeyRepository_GetByNameAndVersion_Call) RunAndReturn(run func(ctx context.Context, name string, version uint) (*domain.TokenizationKey, error)) *MockTokenizationKeyRepository_GetByNameAndVersion_Call { - _c.Call.Return(run) - return _c -} - -// HardDelete provides a mock function for the type MockTokenizationKeyRepository -func (_mock *MockTokenizationKeyRepository) HardDelete(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error) { - ret := _mock.Called(ctx, olderThan, dryRun) - - if len(ret) == 0 { - panic("no return value specified for HardDelete") - } - - var r0 int64 - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) (int64, error)); ok { - return returnFunc(ctx, olderThan, dryRun) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) int64); ok { - r0 = returnFunc(ctx, olderThan, dryRun) - } else { - r0 = ret.Get(0).(int64) - } - if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, bool) error); ok { - r1 = returnFunc(ctx, olderThan, dryRun) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenizationKeyRepository_HardDelete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HardDelete' -type MockTokenizationKeyRepository_HardDelete_Call struct { - *mock.Call -} - -// HardDelete is a helper method to define mock.On call -// - ctx context.Context -// - olderThan time.Time -// - dryRun bool -func (_e *MockTokenizationKeyRepository_Expecter) HardDelete(ctx interface{}, olderThan interface{}, dryRun interface{}) *MockTokenizationKeyRepository_HardDelete_Call { - return &MockTokenizationKeyRepository_HardDelete_Call{Call: _e.mock.On("HardDelete", ctx, olderThan, dryRun)} -} - -func (_c *MockTokenizationKeyRepository_HardDelete_Call) Run(run func(ctx context.Context, olderThan time.Time, dryRun bool)) *MockTokenizationKeyRepository_HardDelete_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 time.Time - if args[1] != nil { - arg1 = args[1].(time.Time) - } - var arg2 bool - if args[2] != nil { - arg2 = args[2].(bool) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockTokenizationKeyRepository_HardDelete_Call) Return(n int64, err error) *MockTokenizationKeyRepository_HardDelete_Call { - _c.Call.Return(n, err) - return _c -} - -func (_c *MockTokenizationKeyRepository_HardDelete_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)) *MockTokenizationKeyRepository_HardDelete_Call { - _c.Call.Return(run) - return _c -} - -// ListCursor provides a mock function for the type MockTokenizationKeyRepository -func (_mock *MockTokenizationKeyRepository) ListCursor(ctx context.Context, afterName *string, limit int) ([]*domain.TokenizationKey, error) { - ret := _mock.Called(ctx, afterName, limit) - - if len(ret) == 0 { - panic("no return value specified for ListCursor") - } - - var r0 []*domain.TokenizationKey - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) ([]*domain.TokenizationKey, error)); ok { - return returnFunc(ctx, afterName, limit) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) []*domain.TokenizationKey); ok { - r0 = returnFunc(ctx, afterName, limit) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*domain.TokenizationKey) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, *string, int) error); ok { - r1 = returnFunc(ctx, afterName, limit) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenizationKeyRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' -type MockTokenizationKeyRepository_ListCursor_Call struct { - *mock.Call -} - -// ListCursor is a helper method to define mock.On call -// - ctx context.Context -// - afterName *string -// - limit int -func (_e *MockTokenizationKeyRepository_Expecter) ListCursor(ctx interface{}, afterName interface{}, limit interface{}) *MockTokenizationKeyRepository_ListCursor_Call { - return &MockTokenizationKeyRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterName, limit)} -} - -func (_c *MockTokenizationKeyRepository_ListCursor_Call) Run(run func(ctx context.Context, afterName *string, limit int)) *MockTokenizationKeyRepository_ListCursor_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 int - if args[2] != nil { - arg2 = args[2].(int) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockTokenizationKeyRepository_ListCursor_Call) Return(tokenizationKeys []*domain.TokenizationKey, err error) *MockTokenizationKeyRepository_ListCursor_Call { - _c.Call.Return(tokenizationKeys, err) - return _c -} - -func (_c *MockTokenizationKeyRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterName *string, limit int) ([]*domain.TokenizationKey, error)) *MockTokenizationKeyRepository_ListCursor_Call { - _c.Call.Return(run) - return _c -} - -// NewMockTokenRepository creates a new instance of MockTokenRepository. 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 NewMockTokenRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *MockTokenRepository { - mock := &MockTokenRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - -// MockTokenRepository is an autogenerated mock type for the TokenRepository type -type MockTokenRepository struct { - mock.Mock -} - -type MockTokenRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *MockTokenRepository) EXPECT() *MockTokenRepository_Expecter { - return &MockTokenRepository_Expecter{mock: &_m.Mock} -} - -// CountExpired provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) CountExpired(ctx context.Context, olderThan time.Time) (int64, error) { - ret := _mock.Called(ctx, olderThan) - - if len(ret) == 0 { - panic("no return value specified for CountExpired") - } - - var r0 int64 - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) (int64, error)); ok { - return returnFunc(ctx, olderThan) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) int64); ok { - r0 = returnFunc(ctx, olderThan) - } else { - r0 = ret.Get(0).(int64) - } - if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time) error); ok { - r1 = returnFunc(ctx, olderThan) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenRepository_CountExpired_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CountExpired' -type MockTokenRepository_CountExpired_Call struct { - *mock.Call -} - -// CountExpired is a helper method to define mock.On call -// - ctx context.Context -// - olderThan time.Time -func (_e *MockTokenRepository_Expecter) CountExpired(ctx interface{}, olderThan interface{}) *MockTokenRepository_CountExpired_Call { - return &MockTokenRepository_CountExpired_Call{Call: _e.mock.On("CountExpired", ctx, olderThan)} -} - -func (_c *MockTokenRepository_CountExpired_Call) Run(run func(ctx context.Context, olderThan time.Time)) *MockTokenRepository_CountExpired_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 time.Time - if args[1] != nil { - arg1 = args[1].(time.Time) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_CountExpired_Call) Return(n int64, err error) *MockTokenRepository_CountExpired_Call { - _c.Call.Return(n, err) - return _c -} - -func (_c *MockTokenRepository_CountExpired_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time) (int64, error)) *MockTokenRepository_CountExpired_Call { - _c.Call.Return(run) - return _c -} - -// Create provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) Create(ctx context.Context, token *domain.Token) error { - ret := _mock.Called(ctx, token) - - if len(ret) == 0 { - panic("no return value specified for Create") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.Token) error); ok { - r0 = returnFunc(ctx, token) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTokenRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' -type MockTokenRepository_Create_Call struct { - *mock.Call -} - -// Create is a helper method to define mock.On call -// - ctx context.Context -// - token *domain.Token -func (_e *MockTokenRepository_Expecter) Create(ctx interface{}, token interface{}) *MockTokenRepository_Create_Call { - return &MockTokenRepository_Create_Call{Call: _e.mock.On("Create", ctx, token)} -} - -func (_c *MockTokenRepository_Create_Call) Run(run func(ctx context.Context, token *domain.Token)) *MockTokenRepository_Create_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *domain.Token - if args[1] != nil { - arg1 = args[1].(*domain.Token) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_Create_Call) Return(err error) *MockTokenRepository_Create_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTokenRepository_Create_Call) RunAndReturn(run func(ctx context.Context, token *domain.Token) error) *MockTokenRepository_Create_Call { - _c.Call.Return(run) - return _c -} - -// CreateBatch provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) CreateBatch(ctx context.Context, tokens []*domain.Token) error { - ret := _mock.Called(ctx, tokens) - - if len(ret) == 0 { - panic("no return value specified for CreateBatch") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, []*domain.Token) error); ok { - r0 = returnFunc(ctx, tokens) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTokenRepository_CreateBatch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateBatch' -type MockTokenRepository_CreateBatch_Call struct { - *mock.Call -} - -// CreateBatch is a helper method to define mock.On call -// - ctx context.Context -// - tokens []*domain.Token -func (_e *MockTokenRepository_Expecter) CreateBatch(ctx interface{}, tokens interface{}) *MockTokenRepository_CreateBatch_Call { - return &MockTokenRepository_CreateBatch_Call{Call: _e.mock.On("CreateBatch", ctx, tokens)} -} - -func (_c *MockTokenRepository_CreateBatch_Call) Run(run func(ctx context.Context, tokens []*domain.Token)) *MockTokenRepository_CreateBatch_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 []*domain.Token - if args[1] != nil { - arg1 = args[1].([]*domain.Token) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_CreateBatch_Call) Return(err error) *MockTokenRepository_CreateBatch_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTokenRepository_CreateBatch_Call) RunAndReturn(run func(ctx context.Context, tokens []*domain.Token) error) *MockTokenRepository_CreateBatch_Call { - _c.Call.Return(run) - return _c -} - -// DeleteExpired provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) DeleteExpired(ctx context.Context, olderThan time.Time) (int64, error) { - ret := _mock.Called(ctx, olderThan) - - if len(ret) == 0 { - panic("no return value specified for DeleteExpired") - } - - var r0 int64 - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) (int64, error)); ok { - return returnFunc(ctx, olderThan) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time) int64); ok { - r0 = returnFunc(ctx, olderThan) - } else { - r0 = ret.Get(0).(int64) - } - if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time) error); ok { - r1 = returnFunc(ctx, olderThan) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenRepository_DeleteExpired_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteExpired' -type MockTokenRepository_DeleteExpired_Call struct { - *mock.Call -} - -// DeleteExpired is a helper method to define mock.On call -// - ctx context.Context -// - olderThan time.Time -func (_e *MockTokenRepository_Expecter) DeleteExpired(ctx interface{}, olderThan interface{}) *MockTokenRepository_DeleteExpired_Call { - return &MockTokenRepository_DeleteExpired_Call{Call: _e.mock.On("DeleteExpired", ctx, olderThan)} -} - -func (_c *MockTokenRepository_DeleteExpired_Call) Run(run func(ctx context.Context, olderThan time.Time)) *MockTokenRepository_DeleteExpired_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 time.Time - if args[1] != nil { - arg1 = args[1].(time.Time) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_DeleteExpired_Call) Return(n int64, err error) *MockTokenRepository_DeleteExpired_Call { - _c.Call.Return(n, err) - return _c -} - -func (_c *MockTokenRepository_DeleteExpired_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time) (int64, error)) *MockTokenRepository_DeleteExpired_Call { - _c.Call.Return(run) - return _c -} - -// GetBatchByTokens provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) GetBatchByTokens(ctx context.Context, tokens []string) ([]*domain.Token, error) { - ret := _mock.Called(ctx, tokens) - - if len(ret) == 0 { - panic("no return value specified for GetBatchByTokens") - } - - var r0 []*domain.Token - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, []string) ([]*domain.Token, error)); ok { - return returnFunc(ctx, tokens) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, []string) []*domain.Token); ok { - r0 = returnFunc(ctx, tokens) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*domain.Token) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, []string) error); ok { - r1 = returnFunc(ctx, tokens) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenRepository_GetBatchByTokens_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBatchByTokens' -type MockTokenRepository_GetBatchByTokens_Call struct { - *mock.Call -} - -// GetBatchByTokens is a helper method to define mock.On call -// - ctx context.Context -// - tokens []string -func (_e *MockTokenRepository_Expecter) GetBatchByTokens(ctx interface{}, tokens interface{}) *MockTokenRepository_GetBatchByTokens_Call { - return &MockTokenRepository_GetBatchByTokens_Call{Call: _e.mock.On("GetBatchByTokens", ctx, tokens)} -} - -func (_c *MockTokenRepository_GetBatchByTokens_Call) Run(run func(ctx context.Context, tokens []string)) *MockTokenRepository_GetBatchByTokens_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_GetBatchByTokens_Call) Return(tokens1 []*domain.Token, err error) *MockTokenRepository_GetBatchByTokens_Call { - _c.Call.Return(tokens1, err) - return _c -} - -func (_c *MockTokenRepository_GetBatchByTokens_Call) RunAndReturn(run func(ctx context.Context, tokens []string) ([]*domain.Token, error)) *MockTokenRepository_GetBatchByTokens_Call { - _c.Call.Return(run) - return _c -} - -// GetByToken provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) GetByToken(ctx context.Context, token string) (*domain.Token, error) { - ret := _mock.Called(ctx, token) - - if len(ret) == 0 { - panic("no return value specified for GetByToken") - } - - var r0 *domain.Token - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.Token, error)); ok { - return returnFunc(ctx, token) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.Token); ok { - r0 = returnFunc(ctx, token) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.Token) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = returnFunc(ctx, token) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenRepository_GetByToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByToken' -type MockTokenRepository_GetByToken_Call struct { - *mock.Call -} - -// GetByToken is a helper method to define mock.On call -// - ctx context.Context -// - token string -func (_e *MockTokenRepository_Expecter) GetByToken(ctx interface{}, token interface{}) *MockTokenRepository_GetByToken_Call { - return &MockTokenRepository_GetByToken_Call{Call: _e.mock.On("GetByToken", ctx, token)} -} - -func (_c *MockTokenRepository_GetByToken_Call) Run(run func(ctx context.Context, token string)) *MockTokenRepository_GetByToken_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_GetByToken_Call) Return(token1 *domain.Token, err error) *MockTokenRepository_GetByToken_Call { - _c.Call.Return(token1, err) - return _c -} - -func (_c *MockTokenRepository_GetByToken_Call) RunAndReturn(run func(ctx context.Context, token string) (*domain.Token, error)) *MockTokenRepository_GetByToken_Call { - _c.Call.Return(run) - return _c -} - -// GetByValueHash provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) GetByValueHash(ctx context.Context, keyID uuid.UUID, valueHash string) (*domain.Token, error) { - ret := _mock.Called(ctx, keyID, valueHash) - - if len(ret) == 0 { - panic("no return value specified for GetByValueHash") - } - - var r0 *domain.Token - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) (*domain.Token, error)); ok { - return returnFunc(ctx, keyID, valueHash) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) *domain.Token); ok { - r0 = returnFunc(ctx, keyID, valueHash) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.Token) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, string) error); ok { - r1 = returnFunc(ctx, keyID, valueHash) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTokenRepository_GetByValueHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByValueHash' -type MockTokenRepository_GetByValueHash_Call struct { - *mock.Call -} - -// GetByValueHash is a helper method to define mock.On call -// - ctx context.Context -// - keyID uuid.UUID -// - valueHash string -func (_e *MockTokenRepository_Expecter) GetByValueHash(ctx interface{}, keyID interface{}, valueHash interface{}) *MockTokenRepository_GetByValueHash_Call { - return &MockTokenRepository_GetByValueHash_Call{Call: _e.mock.On("GetByValueHash", ctx, keyID, valueHash)} -} - -func (_c *MockTokenRepository_GetByValueHash_Call) Run(run func(ctx context.Context, keyID uuid.UUID, valueHash string)) *MockTokenRepository_GetByValueHash_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 *MockTokenRepository_GetByValueHash_Call) Return(token *domain.Token, err error) *MockTokenRepository_GetByValueHash_Call { - _c.Call.Return(token, err) - return _c -} - -func (_c *MockTokenRepository_GetByValueHash_Call) RunAndReturn(run func(ctx context.Context, keyID uuid.UUID, valueHash string) (*domain.Token, error)) *MockTokenRepository_GetByValueHash_Call { - _c.Call.Return(run) - return _c -} - -// Revoke provides a mock function for the type MockTokenRepository -func (_mock *MockTokenRepository) Revoke(ctx context.Context, token string) error { - ret := _mock.Called(ctx, token) - - if len(ret) == 0 { - panic("no return value specified for Revoke") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = returnFunc(ctx, token) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTokenRepository_Revoke_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Revoke' -type MockTokenRepository_Revoke_Call struct { - *mock.Call -} - -// Revoke is a helper method to define mock.On call -// - ctx context.Context -// - token string -func (_e *MockTokenRepository_Expecter) Revoke(ctx interface{}, token interface{}) *MockTokenRepository_Revoke_Call { - return &MockTokenRepository_Revoke_Call{Call: _e.mock.On("Revoke", ctx, token)} -} - -func (_c *MockTokenRepository_Revoke_Call) Run(run func(ctx context.Context, token string)) *MockTokenRepository_Revoke_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTokenRepository_Revoke_Call) Return(err error) *MockTokenRepository_Revoke_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTokenRepository_Revoke_Call) RunAndReturn(run func(ctx context.Context, token string) error) *MockTokenRepository_Revoke_Call { - _c.Call.Return(run) - return _c -} - // NewMockTokenizationKeyUseCase creates a new instance of MockTokenizationKeyUseCase. 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 NewMockTokenizationKeyUseCase(t interface { @@ -1118,7 +79,7 @@ type MockTokenizationKeyUseCase_Create_Call struct { // - formatType domain.FormatType // - isDeterministic bool // - alg keyring.Algorithm -func (_e *MockTokenizationKeyUseCase_Expecter) Create(ctx interface{}, name interface{}, formatType interface{}, isDeterministic interface{}, alg interface{}) *MockTokenizationKeyUseCase_Create_Call { +func (_e *MockTokenizationKeyUseCase_Expecter) Create(ctx any, name any, formatType any, isDeterministic any, alg any) *MockTokenizationKeyUseCase_Create_Call { return &MockTokenizationKeyUseCase_Create_Call{Call: _e.mock.On("Create", ctx, name, formatType, isDeterministic, alg)} } @@ -1190,7 +151,7 @@ type MockTokenizationKeyUseCase_Delete_Call struct { // Delete is a helper method to define mock.On call // - ctx context.Context // - name string -func (_e *MockTokenizationKeyUseCase_Expecter) Delete(ctx interface{}, name interface{}) *MockTokenizationKeyUseCase_Delete_Call { +func (_e *MockTokenizationKeyUseCase_Expecter) Delete(ctx any, name any) *MockTokenizationKeyUseCase_Delete_Call { return &MockTokenizationKeyUseCase_Delete_Call{Call: _e.mock.On("Delete", ctx, name)} } @@ -1258,7 +219,7 @@ type MockTokenizationKeyUseCase_GetByName_Call struct { // GetByName is a helper method to define mock.On call // - ctx context.Context // - name string -func (_e *MockTokenizationKeyUseCase_Expecter) GetByName(ctx interface{}, name interface{}) *MockTokenizationKeyUseCase_GetByName_Call { +func (_e *MockTokenizationKeyUseCase_Expecter) GetByName(ctx any, name any) *MockTokenizationKeyUseCase_GetByName_Call { return &MockTokenizationKeyUseCase_GetByName_Call{Call: _e.mock.On("GetByName", ctx, name)} } @@ -1327,7 +288,7 @@ type MockTokenizationKeyUseCase_ListCursor_Call struct { // - ctx context.Context // - afterName *string // - limit int -func (_e *MockTokenizationKeyUseCase_Expecter) ListCursor(ctx interface{}, afterName interface{}, limit interface{}) *MockTokenizationKeyUseCase_ListCursor_Call { +func (_e *MockTokenizationKeyUseCase_Expecter) ListCursor(ctx any, afterName any, limit any) *MockTokenizationKeyUseCase_ListCursor_Call { return &MockTokenizationKeyUseCase_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterName, limit)} } @@ -1399,7 +360,7 @@ type MockTokenizationKeyUseCase_PurgeDeleted_Call struct { // - ctx context.Context // - olderThanDays int // - dryRun bool -func (_e *MockTokenizationKeyUseCase_Expecter) PurgeDeleted(ctx interface{}, olderThanDays interface{}, dryRun interface{}) *MockTokenizationKeyUseCase_PurgeDeleted_Call { +func (_e *MockTokenizationKeyUseCase_Expecter) PurgeDeleted(ctx any, olderThanDays any, dryRun any) *MockTokenizationKeyUseCase_PurgeDeleted_Call { return &MockTokenizationKeyUseCase_PurgeDeleted_Call{Call: _e.mock.On("PurgeDeleted", ctx, olderThanDays, dryRun)} } @@ -1475,7 +436,7 @@ type MockTokenizationKeyUseCase_Rotate_Call struct { // - formatType domain.FormatType // - isDeterministic bool // - alg keyring.Algorithm -func (_e *MockTokenizationKeyUseCase_Expecter) Rotate(ctx interface{}, name interface{}, formatType interface{}, isDeterministic interface{}, alg interface{}) *MockTokenizationKeyUseCase_Rotate_Call { +func (_e *MockTokenizationKeyUseCase_Expecter) Rotate(ctx any, name any, formatType any, isDeterministic any, alg any) *MockTokenizationKeyUseCase_Rotate_Call { return &MockTokenizationKeyUseCase_Rotate_Call{Call: _e.mock.On("Rotate", ctx, name, formatType, isDeterministic, alg)} } @@ -1584,7 +545,7 @@ type MockTokenizationUseCase_CleanupExpired_Call struct { // - ctx context.Context // - days int // - dryRun bool -func (_e *MockTokenizationUseCase_Expecter) CleanupExpired(ctx interface{}, days interface{}, dryRun interface{}) *MockTokenizationUseCase_CleanupExpired_Call { +func (_e *MockTokenizationUseCase_Expecter) CleanupExpired(ctx any, days any, dryRun any) *MockTokenizationUseCase_CleanupExpired_Call { return &MockTokenizationUseCase_CleanupExpired_Call{Call: _e.mock.On("CleanupExpired", ctx, days, dryRun)} } @@ -1665,7 +626,7 @@ type MockTokenizationUseCase_Detokenize_Call struct { // Detokenize is a helper method to define mock.On call // - ctx context.Context // - token string -func (_e *MockTokenizationUseCase_Expecter) Detokenize(ctx interface{}, token interface{}) *MockTokenizationUseCase_Detokenize_Call { +func (_e *MockTokenizationUseCase_Expecter) Detokenize(ctx any, token any) *MockTokenizationUseCase_Detokenize_Call { return &MockTokenizationUseCase_Detokenize_Call{Call: _e.mock.On("Detokenize", ctx, token)} } @@ -1741,7 +702,7 @@ type MockTokenizationUseCase_DetokenizeBatch_Call struct { // DetokenizeBatch is a helper method to define mock.On call // - ctx context.Context // - tokens []string -func (_e *MockTokenizationUseCase_Expecter) DetokenizeBatch(ctx interface{}, tokens interface{}) *MockTokenizationUseCase_DetokenizeBatch_Call { +func (_e *MockTokenizationUseCase_Expecter) DetokenizeBatch(ctx any, tokens any) *MockTokenizationUseCase_DetokenizeBatch_Call { return &MockTokenizationUseCase_DetokenizeBatch_Call{Call: _e.mock.On("DetokenizeBatch", ctx, tokens)} } @@ -1798,7 +759,7 @@ type MockTokenizationUseCase_Revoke_Call struct { // Revoke is a helper method to define mock.On call // - ctx context.Context // - token string -func (_e *MockTokenizationUseCase_Expecter) Revoke(ctx interface{}, token interface{}) *MockTokenizationUseCase_Revoke_Call { +func (_e *MockTokenizationUseCase_Expecter) Revoke(ctx any, token any) *MockTokenizationUseCase_Revoke_Call { return &MockTokenizationUseCase_Revoke_Call{Call: _e.mock.On("Revoke", ctx, token)} } @@ -1869,7 +830,7 @@ type MockTokenizationUseCase_Tokenize_Call struct { // - plaintext []byte // - metadata map[string]any // - expiresAt *time.Time -func (_e *MockTokenizationUseCase_Expecter) Tokenize(ctx interface{}, keyName interface{}, plaintext interface{}, metadata interface{}, expiresAt interface{}) *MockTokenizationUseCase_Tokenize_Call { +func (_e *MockTokenizationUseCase_Expecter) Tokenize(ctx any, keyName any, plaintext any, metadata any, expiresAt any) *MockTokenizationUseCase_Tokenize_Call { return &MockTokenizationUseCase_Tokenize_Call{Call: _e.mock.On("Tokenize", ctx, keyName, plaintext, metadata, expiresAt)} } @@ -1955,7 +916,7 @@ type MockTokenizationUseCase_TokenizeBatch_Call struct { // - plaintexts [][]byte // - metadatas []map[string]any // - expiresAt *time.Time -func (_e *MockTokenizationUseCase_Expecter) TokenizeBatch(ctx interface{}, keyName interface{}, plaintexts interface{}, metadatas interface{}, expiresAt interface{}) *MockTokenizationUseCase_TokenizeBatch_Call { +func (_e *MockTokenizationUseCase_Expecter) TokenizeBatch(ctx any, keyName any, plaintexts any, metadatas any, expiresAt any) *MockTokenizationUseCase_TokenizeBatch_Call { return &MockTokenizationUseCase_TokenizeBatch_Call{Call: _e.mock.On("TokenizeBatch", ctx, keyName, plaintexts, metadatas, expiresAt)} } @@ -2036,7 +997,7 @@ type MockTokenizationUseCase_Validate_Call struct { // Validate is a helper method to define mock.On call // - ctx context.Context // - token string -func (_e *MockTokenizationUseCase_Expecter) Validate(ctx interface{}, token interface{}) *MockTokenizationUseCase_Validate_Call { +func (_e *MockTokenizationUseCase_Expecter) Validate(ctx any, token any) *MockTokenizationUseCase_Validate_Call { return &MockTokenizationUseCase_Validate_Call{Call: _e.mock.On("Validate", ctx, token)} } diff --git a/internal/tokenization/usecase/tokenization_key_usecase_test.go b/internal/tokenization/usecase/tokenization_key_usecase_test.go index 3d97f09..8a718cb 100644 --- a/internal/tokenization/usecase/tokenization_key_usecase_test.go +++ b/internal/tokenization/usecase/tokenization_key_usecase_test.go @@ -11,8 +11,8 @@ import ( apperrors "github.com/allisson/secrets/internal/errors" "github.com/allisson/secrets/internal/keyring" tokenizationDomain "github.com/allisson/secrets/internal/tokenization/domain" + "github.com/allisson/secrets/internal/tokenization/domain/mocks" "github.com/allisson/secrets/internal/tokenization/usecase" - "github.com/allisson/secrets/internal/tokenization/usecase/mocks" ) // noopTxManager runs the function with no real transaction. diff --git a/internal/tokenization/usecase/tokenization_usecase_test.go b/internal/tokenization/usecase/tokenization_usecase_test.go index 3023936..47a502b 100644 --- a/internal/tokenization/usecase/tokenization_usecase_test.go +++ b/internal/tokenization/usecase/tokenization_usecase_test.go @@ -16,8 +16,8 @@ import ( apperrors "github.com/allisson/secrets/internal/errors" "github.com/allisson/secrets/internal/keyring" tokenizationDomain "github.com/allisson/secrets/internal/tokenization/domain" + "github.com/allisson/secrets/internal/tokenization/domain/mocks" "github.com/allisson/secrets/internal/tokenization/usecase" - "github.com/allisson/secrets/internal/tokenization/usecase/mocks" ) func newTokenizationUseCase( diff --git a/internal/transit/domain/mocks/mocks.go b/internal/transit/domain/mocks/mocks.go new file mode 100644 index 0000000..2fc091b --- /dev/null +++ b/internal/transit/domain/mocks/mocks.go @@ -0,0 +1,516 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "time" + + "github.com/allisson/secrets/internal/transit/domain" + mock "github.com/stretchr/testify/mock" +) + +// NewMockTransitKeyRepository creates a new instance of MockTransitKeyRepository. 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 NewMockTransitKeyRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockTransitKeyRepository { + mock := &MockTransitKeyRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +// MockTransitKeyRepository is an autogenerated mock type for the TransitKeyRepository type +type MockTransitKeyRepository struct { + mock.Mock +} + +type MockTransitKeyRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockTransitKeyRepository) EXPECT() *MockTransitKeyRepository_Expecter { + return &MockTransitKeyRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockTransitKeyRepository +func (_mock *MockTransitKeyRepository) Create(ctx context.Context, transitKey *domain.TransitKey) error { + ret := _mock.Called(ctx, transitKey) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.TransitKey) error); ok { + r0 = returnFunc(ctx, transitKey) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTransitKeyRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockTransitKeyRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - transitKey *domain.TransitKey +func (_e *MockTransitKeyRepository_Expecter) Create(ctx any, transitKey any) *MockTransitKeyRepository_Create_Call { + return &MockTransitKeyRepository_Create_Call{Call: _e.mock.On("Create", ctx, transitKey)} +} + +func (_c *MockTransitKeyRepository_Create_Call) Run(run func(ctx context.Context, transitKey *domain.TransitKey)) *MockTransitKeyRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 *domain.TransitKey + if args[1] != nil { + arg1 = args[1].(*domain.TransitKey) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTransitKeyRepository_Create_Call) Return(err error) *MockTransitKeyRepository_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTransitKeyRepository_Create_Call) RunAndReturn(run func(ctx context.Context, transitKey *domain.TransitKey) error) *MockTransitKeyRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function for the type MockTransitKeyRepository +func (_mock *MockTransitKeyRepository) Delete(ctx context.Context, name string) error { + ret := _mock.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = returnFunc(ctx, name) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockTransitKeyRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockTransitKeyRepository_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *MockTransitKeyRepository_Expecter) Delete(ctx any, name any) *MockTransitKeyRepository_Delete_Call { + return &MockTransitKeyRepository_Delete_Call{Call: _e.mock.On("Delete", ctx, name)} +} + +func (_c *MockTransitKeyRepository_Delete_Call) Run(run func(ctx context.Context, name string)) *MockTransitKeyRepository_Delete_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTransitKeyRepository_Delete_Call) Return(err error) *MockTransitKeyRepository_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTransitKeyRepository_Delete_Call) RunAndReturn(run func(ctx context.Context, name string) error) *MockTransitKeyRepository_Delete_Call { + _c.Call.Return(run) + return _c +} + +// GetByName provides a mock function for the type MockTransitKeyRepository +func (_mock *MockTransitKeyRepository) GetByName(ctx context.Context, name string) (*domain.TransitKey, error) { + ret := _mock.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for GetByName") + } + + var r0 *domain.TransitKey + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.TransitKey, error)); ok { + return returnFunc(ctx, name) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.TransitKey); ok { + r0 = returnFunc(ctx, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.TransitKey) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, name) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTransitKeyRepository_GetByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByName' +type MockTransitKeyRepository_GetByName_Call struct { + *mock.Call +} + +// GetByName is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *MockTransitKeyRepository_Expecter) GetByName(ctx any, name any) *MockTransitKeyRepository_GetByName_Call { + return &MockTransitKeyRepository_GetByName_Call{Call: _e.mock.On("GetByName", ctx, name)} +} + +func (_c *MockTransitKeyRepository_GetByName_Call) Run(run func(ctx context.Context, name string)) *MockTransitKeyRepository_GetByName_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) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockTransitKeyRepository_GetByName_Call) Return(transitKey *domain.TransitKey, err error) *MockTransitKeyRepository_GetByName_Call { + _c.Call.Return(transitKey, err) + return _c +} + +func (_c *MockTransitKeyRepository_GetByName_Call) RunAndReturn(run func(ctx context.Context, name string) (*domain.TransitKey, error)) *MockTransitKeyRepository_GetByName_Call { + _c.Call.Return(run) + return _c +} + +// GetByNameAndVersion provides a mock function for the type MockTransitKeyRepository +func (_mock *MockTransitKeyRepository) GetByNameAndVersion(ctx context.Context, name string, version uint) (*domain.TransitKey, error) { + ret := _mock.Called(ctx, name, version) + + if len(ret) == 0 { + panic("no return value specified for GetByNameAndVersion") + } + + var r0 *domain.TransitKey + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) (*domain.TransitKey, error)); ok { + return returnFunc(ctx, name, version) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) *domain.TransitKey); ok { + r0 = returnFunc(ctx, name, version) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.TransitKey) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, uint) error); ok { + r1 = returnFunc(ctx, name, version) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTransitKeyRepository_GetByNameAndVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByNameAndVersion' +type MockTransitKeyRepository_GetByNameAndVersion_Call struct { + *mock.Call +} + +// GetByNameAndVersion is a helper method to define mock.On call +// - ctx context.Context +// - name string +// - version uint +func (_e *MockTransitKeyRepository_Expecter) GetByNameAndVersion(ctx any, name any, version any) *MockTransitKeyRepository_GetByNameAndVersion_Call { + return &MockTransitKeyRepository_GetByNameAndVersion_Call{Call: _e.mock.On("GetByNameAndVersion", ctx, name, version)} +} + +func (_c *MockTransitKeyRepository_GetByNameAndVersion_Call) Run(run func(ctx context.Context, name string, version uint)) *MockTransitKeyRepository_GetByNameAndVersion_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 uint + if args[2] != nil { + arg2 = args[2].(uint) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockTransitKeyRepository_GetByNameAndVersion_Call) Return(transitKey *domain.TransitKey, err error) *MockTransitKeyRepository_GetByNameAndVersion_Call { + _c.Call.Return(transitKey, err) + return _c +} + +func (_c *MockTransitKeyRepository_GetByNameAndVersion_Call) RunAndReturn(run func(ctx context.Context, name string, version uint) (*domain.TransitKey, error)) *MockTransitKeyRepository_GetByNameAndVersion_Call { + _c.Call.Return(run) + return _c +} + +// GetTransitKey provides a mock function for the type MockTransitKeyRepository +func (_mock *MockTransitKeyRepository) GetTransitKey(ctx context.Context, name string, version uint) (*domain.TransitKey, error) { + ret := _mock.Called(ctx, name, version) + + if len(ret) == 0 { + panic("no return value specified for GetTransitKey") + } + + var r0 *domain.TransitKey + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) (*domain.TransitKey, error)); ok { + return returnFunc(ctx, name, version) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) *domain.TransitKey); ok { + r0 = returnFunc(ctx, name, version) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*domain.TransitKey) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, uint) error); ok { + r1 = returnFunc(ctx, name, version) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTransitKeyRepository_GetTransitKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTransitKey' +type MockTransitKeyRepository_GetTransitKey_Call struct { + *mock.Call +} + +// GetTransitKey is a helper method to define mock.On call +// - ctx context.Context +// - name string +// - version uint +func (_e *MockTransitKeyRepository_Expecter) GetTransitKey(ctx any, name any, version any) *MockTransitKeyRepository_GetTransitKey_Call { + return &MockTransitKeyRepository_GetTransitKey_Call{Call: _e.mock.On("GetTransitKey", ctx, name, version)} +} + +func (_c *MockTransitKeyRepository_GetTransitKey_Call) Run(run func(ctx context.Context, name string, version uint)) *MockTransitKeyRepository_GetTransitKey_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 uint + if args[2] != nil { + arg2 = args[2].(uint) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockTransitKeyRepository_GetTransitKey_Call) Return(transitKey *domain.TransitKey, err error) *MockTransitKeyRepository_GetTransitKey_Call { + _c.Call.Return(transitKey, err) + return _c +} + +func (_c *MockTransitKeyRepository_GetTransitKey_Call) RunAndReturn(run func(ctx context.Context, name string, version uint) (*domain.TransitKey, error)) *MockTransitKeyRepository_GetTransitKey_Call { + _c.Call.Return(run) + return _c +} + +// HardDelete provides a mock function for the type MockTransitKeyRepository +func (_mock *MockTransitKeyRepository) HardDelete(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error) { + ret := _mock.Called(ctx, olderThan, dryRun) + + if len(ret) == 0 { + panic("no return value specified for HardDelete") + } + + var r0 int64 + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) (int64, error)); ok { + return returnFunc(ctx, olderThan, dryRun) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) int64); ok { + r0 = returnFunc(ctx, olderThan, dryRun) + } else { + r0 = ret.Get(0).(int64) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, bool) error); ok { + r1 = returnFunc(ctx, olderThan, dryRun) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTransitKeyRepository_HardDelete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HardDelete' +type MockTransitKeyRepository_HardDelete_Call struct { + *mock.Call +} + +// HardDelete is a helper method to define mock.On call +// - ctx context.Context +// - olderThan time.Time +// - dryRun bool +func (_e *MockTransitKeyRepository_Expecter) HardDelete(ctx any, olderThan any, dryRun any) *MockTransitKeyRepository_HardDelete_Call { + return &MockTransitKeyRepository_HardDelete_Call{Call: _e.mock.On("HardDelete", ctx, olderThan, dryRun)} +} + +func (_c *MockTransitKeyRepository_HardDelete_Call) Run(run func(ctx context.Context, olderThan time.Time, dryRun bool)) *MockTransitKeyRepository_HardDelete_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 time.Time + if args[1] != nil { + arg1 = args[1].(time.Time) + } + var arg2 bool + if args[2] != nil { + arg2 = args[2].(bool) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockTransitKeyRepository_HardDelete_Call) Return(n int64, err error) *MockTransitKeyRepository_HardDelete_Call { + _c.Call.Return(n, err) + return _c +} + +func (_c *MockTransitKeyRepository_HardDelete_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)) *MockTransitKeyRepository_HardDelete_Call { + _c.Call.Return(run) + return _c +} + +// ListCursor provides a mock function for the type MockTransitKeyRepository +func (_mock *MockTransitKeyRepository) ListCursor(ctx context.Context, afterName *string, limit int) ([]*domain.TransitKey, error) { + ret := _mock.Called(ctx, afterName, limit) + + if len(ret) == 0 { + panic("no return value specified for ListCursor") + } + + var r0 []*domain.TransitKey + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) ([]*domain.TransitKey, error)); ok { + return returnFunc(ctx, afterName, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) []*domain.TransitKey); ok { + r0 = returnFunc(ctx, afterName, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*domain.TransitKey) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, *string, int) error); ok { + r1 = returnFunc(ctx, afterName, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTransitKeyRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' +type MockTransitKeyRepository_ListCursor_Call struct { + *mock.Call +} + +// ListCursor is a helper method to define mock.On call +// - ctx context.Context +// - afterName *string +// - limit int +func (_e *MockTransitKeyRepository_Expecter) ListCursor(ctx any, afterName any, limit any) *MockTransitKeyRepository_ListCursor_Call { + return &MockTransitKeyRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterName, limit)} +} + +func (_c *MockTransitKeyRepository_ListCursor_Call) Run(run func(ctx context.Context, afterName *string, limit int)) *MockTransitKeyRepository_ListCursor_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 int + if args[2] != nil { + arg2 = args[2].(int) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockTransitKeyRepository_ListCursor_Call) Return(transitKeys []*domain.TransitKey, err error) *MockTransitKeyRepository_ListCursor_Call { + _c.Call.Return(transitKeys, err) + return _c +} + +func (_c *MockTransitKeyRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterName *string, limit int) ([]*domain.TransitKey, error)) *MockTransitKeyRepository_ListCursor_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transit/usecase/mocks/mocks.go b/internal/transit/usecase/mocks/mocks.go index cbcf1eb..3f65acb 100644 --- a/internal/transit/usecase/mocks/mocks.go +++ b/internal/transit/usecase/mocks/mocks.go @@ -6,516 +6,12 @@ package mocks import ( "context" - "time" "github.com/allisson/secrets/internal/keyring" "github.com/allisson/secrets/internal/transit/domain" mock "github.com/stretchr/testify/mock" ) -// NewMockTransitKeyRepository creates a new instance of MockTransitKeyRepository. 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 NewMockTransitKeyRepository(t interface { - mock.TestingT - Cleanup(func()) -}) *MockTransitKeyRepository { - mock := &MockTransitKeyRepository{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} - -// MockTransitKeyRepository is an autogenerated mock type for the TransitKeyRepository type -type MockTransitKeyRepository struct { - mock.Mock -} - -type MockTransitKeyRepository_Expecter struct { - mock *mock.Mock -} - -func (_m *MockTransitKeyRepository) EXPECT() *MockTransitKeyRepository_Expecter { - return &MockTransitKeyRepository_Expecter{mock: &_m.Mock} -} - -// Create provides a mock function for the type MockTransitKeyRepository -func (_mock *MockTransitKeyRepository) Create(ctx context.Context, transitKey *domain.TransitKey) error { - ret := _mock.Called(ctx, transitKey) - - if len(ret) == 0 { - panic("no return value specified for Create") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *domain.TransitKey) error); ok { - r0 = returnFunc(ctx, transitKey) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTransitKeyRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' -type MockTransitKeyRepository_Create_Call struct { - *mock.Call -} - -// Create is a helper method to define mock.On call -// - ctx context.Context -// - transitKey *domain.TransitKey -func (_e *MockTransitKeyRepository_Expecter) Create(ctx interface{}, transitKey interface{}) *MockTransitKeyRepository_Create_Call { - return &MockTransitKeyRepository_Create_Call{Call: _e.mock.On("Create", ctx, transitKey)} -} - -func (_c *MockTransitKeyRepository_Create_Call) Run(run func(ctx context.Context, transitKey *domain.TransitKey)) *MockTransitKeyRepository_Create_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 *domain.TransitKey - if args[1] != nil { - arg1 = args[1].(*domain.TransitKey) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTransitKeyRepository_Create_Call) Return(err error) *MockTransitKeyRepository_Create_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTransitKeyRepository_Create_Call) RunAndReturn(run func(ctx context.Context, transitKey *domain.TransitKey) error) *MockTransitKeyRepository_Create_Call { - _c.Call.Return(run) - return _c -} - -// Delete provides a mock function for the type MockTransitKeyRepository -func (_mock *MockTransitKeyRepository) Delete(ctx context.Context, name string) error { - ret := _mock.Called(ctx, name) - - if len(ret) == 0 { - panic("no return value specified for Delete") - } - - var r0 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string) error); ok { - r0 = returnFunc(ctx, name) - } else { - r0 = ret.Error(0) - } - return r0 -} - -// MockTransitKeyRepository_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' -type MockTransitKeyRepository_Delete_Call struct { - *mock.Call -} - -// Delete is a helper method to define mock.On call -// - ctx context.Context -// - name string -func (_e *MockTransitKeyRepository_Expecter) Delete(ctx interface{}, name interface{}) *MockTransitKeyRepository_Delete_Call { - return &MockTransitKeyRepository_Delete_Call{Call: _e.mock.On("Delete", ctx, name)} -} - -func (_c *MockTransitKeyRepository_Delete_Call) Run(run func(ctx context.Context, name string)) *MockTransitKeyRepository_Delete_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTransitKeyRepository_Delete_Call) Return(err error) *MockTransitKeyRepository_Delete_Call { - _c.Call.Return(err) - return _c -} - -func (_c *MockTransitKeyRepository_Delete_Call) RunAndReturn(run func(ctx context.Context, name string) error) *MockTransitKeyRepository_Delete_Call { - _c.Call.Return(run) - return _c -} - -// GetByName provides a mock function for the type MockTransitKeyRepository -func (_mock *MockTransitKeyRepository) GetByName(ctx context.Context, name string) (*domain.TransitKey, error) { - ret := _mock.Called(ctx, name) - - if len(ret) == 0 { - panic("no return value specified for GetByName") - } - - var r0 *domain.TransitKey - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string) (*domain.TransitKey, error)); ok { - return returnFunc(ctx, name) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, string) *domain.TransitKey); ok { - r0 = returnFunc(ctx, name) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.TransitKey) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { - r1 = returnFunc(ctx, name) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTransitKeyRepository_GetByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByName' -type MockTransitKeyRepository_GetByName_Call struct { - *mock.Call -} - -// GetByName is a helper method to define mock.On call -// - ctx context.Context -// - name string -func (_e *MockTransitKeyRepository_Expecter) GetByName(ctx interface{}, name interface{}) *MockTransitKeyRepository_GetByName_Call { - return &MockTransitKeyRepository_GetByName_Call{Call: _e.mock.On("GetByName", ctx, name)} -} - -func (_c *MockTransitKeyRepository_GetByName_Call) Run(run func(ctx context.Context, name string)) *MockTransitKeyRepository_GetByName_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) - } - run( - arg0, - arg1, - ) - }) - return _c -} - -func (_c *MockTransitKeyRepository_GetByName_Call) Return(transitKey *domain.TransitKey, err error) *MockTransitKeyRepository_GetByName_Call { - _c.Call.Return(transitKey, err) - return _c -} - -func (_c *MockTransitKeyRepository_GetByName_Call) RunAndReturn(run func(ctx context.Context, name string) (*domain.TransitKey, error)) *MockTransitKeyRepository_GetByName_Call { - _c.Call.Return(run) - return _c -} - -// GetByNameAndVersion provides a mock function for the type MockTransitKeyRepository -func (_mock *MockTransitKeyRepository) GetByNameAndVersion(ctx context.Context, name string, version uint) (*domain.TransitKey, error) { - ret := _mock.Called(ctx, name, version) - - if len(ret) == 0 { - panic("no return value specified for GetByNameAndVersion") - } - - var r0 *domain.TransitKey - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) (*domain.TransitKey, error)); ok { - return returnFunc(ctx, name, version) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) *domain.TransitKey); ok { - r0 = returnFunc(ctx, name, version) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.TransitKey) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, string, uint) error); ok { - r1 = returnFunc(ctx, name, version) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTransitKeyRepository_GetByNameAndVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByNameAndVersion' -type MockTransitKeyRepository_GetByNameAndVersion_Call struct { - *mock.Call -} - -// GetByNameAndVersion is a helper method to define mock.On call -// - ctx context.Context -// - name string -// - version uint -func (_e *MockTransitKeyRepository_Expecter) GetByNameAndVersion(ctx interface{}, name interface{}, version interface{}) *MockTransitKeyRepository_GetByNameAndVersion_Call { - return &MockTransitKeyRepository_GetByNameAndVersion_Call{Call: _e.mock.On("GetByNameAndVersion", ctx, name, version)} -} - -func (_c *MockTransitKeyRepository_GetByNameAndVersion_Call) Run(run func(ctx context.Context, name string, version uint)) *MockTransitKeyRepository_GetByNameAndVersion_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 uint - if args[2] != nil { - arg2 = args[2].(uint) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockTransitKeyRepository_GetByNameAndVersion_Call) Return(transitKey *domain.TransitKey, err error) *MockTransitKeyRepository_GetByNameAndVersion_Call { - _c.Call.Return(transitKey, err) - return _c -} - -func (_c *MockTransitKeyRepository_GetByNameAndVersion_Call) RunAndReturn(run func(ctx context.Context, name string, version uint) (*domain.TransitKey, error)) *MockTransitKeyRepository_GetByNameAndVersion_Call { - _c.Call.Return(run) - return _c -} - -// GetTransitKey provides a mock function for the type MockTransitKeyRepository -func (_mock *MockTransitKeyRepository) GetTransitKey(ctx context.Context, name string, version uint) (*domain.TransitKey, error) { - ret := _mock.Called(ctx, name, version) - - if len(ret) == 0 { - panic("no return value specified for GetTransitKey") - } - - var r0 *domain.TransitKey - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) (*domain.TransitKey, error)); ok { - return returnFunc(ctx, name, version) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, string, uint) *domain.TransitKey); ok { - r0 = returnFunc(ctx, name, version) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*domain.TransitKey) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, string, uint) error); ok { - r1 = returnFunc(ctx, name, version) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTransitKeyRepository_GetTransitKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTransitKey' -type MockTransitKeyRepository_GetTransitKey_Call struct { - *mock.Call -} - -// GetTransitKey is a helper method to define mock.On call -// - ctx context.Context -// - name string -// - version uint -func (_e *MockTransitKeyRepository_Expecter) GetTransitKey(ctx interface{}, name interface{}, version interface{}) *MockTransitKeyRepository_GetTransitKey_Call { - return &MockTransitKeyRepository_GetTransitKey_Call{Call: _e.mock.On("GetTransitKey", ctx, name, version)} -} - -func (_c *MockTransitKeyRepository_GetTransitKey_Call) Run(run func(ctx context.Context, name string, version uint)) *MockTransitKeyRepository_GetTransitKey_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 uint - if args[2] != nil { - arg2 = args[2].(uint) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockTransitKeyRepository_GetTransitKey_Call) Return(transitKey *domain.TransitKey, err error) *MockTransitKeyRepository_GetTransitKey_Call { - _c.Call.Return(transitKey, err) - return _c -} - -func (_c *MockTransitKeyRepository_GetTransitKey_Call) RunAndReturn(run func(ctx context.Context, name string, version uint) (*domain.TransitKey, error)) *MockTransitKeyRepository_GetTransitKey_Call { - _c.Call.Return(run) - return _c -} - -// HardDelete provides a mock function for the type MockTransitKeyRepository -func (_mock *MockTransitKeyRepository) HardDelete(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error) { - ret := _mock.Called(ctx, olderThan, dryRun) - - if len(ret) == 0 { - panic("no return value specified for HardDelete") - } - - var r0 int64 - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) (int64, error)); ok { - return returnFunc(ctx, olderThan, dryRun) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, bool) int64); ok { - r0 = returnFunc(ctx, olderThan, dryRun) - } else { - r0 = ret.Get(0).(int64) - } - if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, bool) error); ok { - r1 = returnFunc(ctx, olderThan, dryRun) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTransitKeyRepository_HardDelete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HardDelete' -type MockTransitKeyRepository_HardDelete_Call struct { - *mock.Call -} - -// HardDelete is a helper method to define mock.On call -// - ctx context.Context -// - olderThan time.Time -// - dryRun bool -func (_e *MockTransitKeyRepository_Expecter) HardDelete(ctx interface{}, olderThan interface{}, dryRun interface{}) *MockTransitKeyRepository_HardDelete_Call { - return &MockTransitKeyRepository_HardDelete_Call{Call: _e.mock.On("HardDelete", ctx, olderThan, dryRun)} -} - -func (_c *MockTransitKeyRepository_HardDelete_Call) Run(run func(ctx context.Context, olderThan time.Time, dryRun bool)) *MockTransitKeyRepository_HardDelete_Call { - _c.Call.Run(func(args mock.Arguments) { - var arg0 context.Context - if args[0] != nil { - arg0 = args[0].(context.Context) - } - var arg1 time.Time - if args[1] != nil { - arg1 = args[1].(time.Time) - } - var arg2 bool - if args[2] != nil { - arg2 = args[2].(bool) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockTransitKeyRepository_HardDelete_Call) Return(n int64, err error) *MockTransitKeyRepository_HardDelete_Call { - _c.Call.Return(n, err) - return _c -} - -func (_c *MockTransitKeyRepository_HardDelete_Call) RunAndReturn(run func(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)) *MockTransitKeyRepository_HardDelete_Call { - _c.Call.Return(run) - return _c -} - -// ListCursor provides a mock function for the type MockTransitKeyRepository -func (_mock *MockTransitKeyRepository) ListCursor(ctx context.Context, afterName *string, limit int) ([]*domain.TransitKey, error) { - ret := _mock.Called(ctx, afterName, limit) - - if len(ret) == 0 { - panic("no return value specified for ListCursor") - } - - var r0 []*domain.TransitKey - var r1 error - if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) ([]*domain.TransitKey, error)); ok { - return returnFunc(ctx, afterName, limit) - } - if returnFunc, ok := ret.Get(0).(func(context.Context, *string, int) []*domain.TransitKey); ok { - r0 = returnFunc(ctx, afterName, limit) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*domain.TransitKey) - } - } - if returnFunc, ok := ret.Get(1).(func(context.Context, *string, int) error); ok { - r1 = returnFunc(ctx, afterName, limit) - } else { - r1 = ret.Error(1) - } - return r0, r1 -} - -// MockTransitKeyRepository_ListCursor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCursor' -type MockTransitKeyRepository_ListCursor_Call struct { - *mock.Call -} - -// ListCursor is a helper method to define mock.On call -// - ctx context.Context -// - afterName *string -// - limit int -func (_e *MockTransitKeyRepository_Expecter) ListCursor(ctx interface{}, afterName interface{}, limit interface{}) *MockTransitKeyRepository_ListCursor_Call { - return &MockTransitKeyRepository_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterName, limit)} -} - -func (_c *MockTransitKeyRepository_ListCursor_Call) Run(run func(ctx context.Context, afterName *string, limit int)) *MockTransitKeyRepository_ListCursor_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 int - if args[2] != nil { - arg2 = args[2].(int) - } - run( - arg0, - arg1, - arg2, - ) - }) - return _c -} - -func (_c *MockTransitKeyRepository_ListCursor_Call) Return(transitKeys []*domain.TransitKey, err error) *MockTransitKeyRepository_ListCursor_Call { - _c.Call.Return(transitKeys, err) - return _c -} - -func (_c *MockTransitKeyRepository_ListCursor_Call) RunAndReturn(run func(ctx context.Context, afterName *string, limit int) ([]*domain.TransitKey, error)) *MockTransitKeyRepository_ListCursor_Call { - _c.Call.Return(run) - return _c -} - // NewMockTransitKeyUseCase creates a new instance of MockTransitKeyUseCase. 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 NewMockTransitKeyUseCase(t interface { @@ -580,7 +76,7 @@ type MockTransitKeyUseCase_Create_Call struct { // - ctx context.Context // - name string // - alg keyring.Algorithm -func (_e *MockTransitKeyUseCase_Expecter) Create(ctx interface{}, name interface{}, alg interface{}) *MockTransitKeyUseCase_Create_Call { +func (_e *MockTransitKeyUseCase_Expecter) Create(ctx any, name any, alg any) *MockTransitKeyUseCase_Create_Call { return &MockTransitKeyUseCase_Create_Call{Call: _e.mock.On("Create", ctx, name, alg)} } @@ -655,7 +151,7 @@ type MockTransitKeyUseCase_Decrypt_Call struct { // - name string // - ciphertext string // - context1 []byte -func (_e *MockTransitKeyUseCase_Expecter) Decrypt(ctx interface{}, name interface{}, ciphertext interface{}, context1 interface{}) *MockTransitKeyUseCase_Decrypt_Call { +func (_e *MockTransitKeyUseCase_Expecter) Decrypt(ctx any, name any, ciphertext any, context1 any) *MockTransitKeyUseCase_Decrypt_Call { return &MockTransitKeyUseCase_Decrypt_Call{Call: _e.mock.On("Decrypt", ctx, name, ciphertext, context1)} } @@ -722,7 +218,7 @@ type MockTransitKeyUseCase_Delete_Call struct { // Delete is a helper method to define mock.On call // - ctx context.Context // - name string -func (_e *MockTransitKeyUseCase_Expecter) Delete(ctx interface{}, name interface{}) *MockTransitKeyUseCase_Delete_Call { +func (_e *MockTransitKeyUseCase_Expecter) Delete(ctx any, name any) *MockTransitKeyUseCase_Delete_Call { return &MockTransitKeyUseCase_Delete_Call{Call: _e.mock.On("Delete", ctx, name)} } @@ -792,7 +288,7 @@ type MockTransitKeyUseCase_Encrypt_Call struct { // - name string // - plaintext []byte // - context1 []byte -func (_e *MockTransitKeyUseCase_Expecter) Encrypt(ctx interface{}, name interface{}, plaintext interface{}, context1 interface{}) *MockTransitKeyUseCase_Encrypt_Call { +func (_e *MockTransitKeyUseCase_Expecter) Encrypt(ctx any, name any, plaintext any, context1 any) *MockTransitKeyUseCase_Encrypt_Call { return &MockTransitKeyUseCase_Encrypt_Call{Call: _e.mock.On("Encrypt", ctx, name, plaintext, context1)} } @@ -871,7 +367,7 @@ type MockTransitKeyUseCase_Get_Call struct { // - ctx context.Context // - name string // - version uint -func (_e *MockTransitKeyUseCase_Expecter) Get(ctx interface{}, name interface{}, version interface{}) *MockTransitKeyUseCase_Get_Call { +func (_e *MockTransitKeyUseCase_Expecter) Get(ctx any, name any, version any) *MockTransitKeyUseCase_Get_Call { return &MockTransitKeyUseCase_Get_Call{Call: _e.mock.On("Get", ctx, name, version)} } @@ -945,7 +441,7 @@ type MockTransitKeyUseCase_ListCursor_Call struct { // - ctx context.Context // - afterName *string // - limit int -func (_e *MockTransitKeyUseCase_Expecter) ListCursor(ctx interface{}, afterName interface{}, limit interface{}) *MockTransitKeyUseCase_ListCursor_Call { +func (_e *MockTransitKeyUseCase_Expecter) ListCursor(ctx any, afterName any, limit any) *MockTransitKeyUseCase_ListCursor_Call { return &MockTransitKeyUseCase_ListCursor_Call{Call: _e.mock.On("ListCursor", ctx, afterName, limit)} } @@ -1017,7 +513,7 @@ type MockTransitKeyUseCase_PurgeDeleted_Call struct { // - ctx context.Context // - olderThanDays int // - dryRun bool -func (_e *MockTransitKeyUseCase_Expecter) PurgeDeleted(ctx interface{}, olderThanDays interface{}, dryRun interface{}) *MockTransitKeyUseCase_PurgeDeleted_Call { +func (_e *MockTransitKeyUseCase_Expecter) PurgeDeleted(ctx any, olderThanDays any, dryRun any) *MockTransitKeyUseCase_PurgeDeleted_Call { return &MockTransitKeyUseCase_PurgeDeleted_Call{Call: _e.mock.On("PurgeDeleted", ctx, olderThanDays, dryRun)} } @@ -1091,7 +587,7 @@ type MockTransitKeyUseCase_Rotate_Call struct { // - ctx context.Context // - name string // - alg keyring.Algorithm -func (_e *MockTransitKeyUseCase_Expecter) Rotate(ctx interface{}, name interface{}, alg interface{}) *MockTransitKeyUseCase_Rotate_Call { +func (_e *MockTransitKeyUseCase_Expecter) Rotate(ctx any, name any, alg any) *MockTransitKeyUseCase_Rotate_Call { return &MockTransitKeyUseCase_Rotate_Call{Call: _e.mock.On("Rotate", ctx, name, alg)} } diff --git a/internal/transit/usecase/transit_key_usecase_test.go b/internal/transit/usecase/transit_key_usecase_test.go index 5388461..5eca6e0 100644 --- a/internal/transit/usecase/transit_key_usecase_test.go +++ b/internal/transit/usecase/transit_key_usecase_test.go @@ -13,8 +13,8 @@ import ( "github.com/allisson/secrets/internal/keyring" transitDomain "github.com/allisson/secrets/internal/transit/domain" + "github.com/allisson/secrets/internal/transit/domain/mocks" "github.com/allisson/secrets/internal/transit/usecase" - "github.com/allisson/secrets/internal/transit/usecase/mocks" ) // noopTxManager runs the function with no real transaction. diff --git a/test/integration/helpers_test.go b/test/integration/helpers_test.go index ec27d55..630d99d 100644 --- a/test/integration/helpers_test.go +++ b/test/integration/helpers_test.go @@ -24,7 +24,6 @@ import ( "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gocloud.dev/secrets" _ "gocloud.dev/secrets/localsecrets" "github.com/allisson/secrets/internal/app" @@ -87,20 +86,28 @@ func (ctx *integrationTestContext) makeRequest( return resp, respBody } +// testMasterKey is a test-only (id, raw key) pair. keyring no longer exports a +// master-key type — production code never constructs one outside the package — +// so tests carry their own to drive the KMS-encrypt flow. +type testMasterKey struct { + ID string + Key []byte +} + // generateMasterKey creates a new 32-byte master key for testing. -func generateMasterKey() *keyring.MasterKey { +func generateMasterKey() *testMasterKey { key := make([]byte, 32) if _, err := rand.Read(key); err != nil { panic(fmt.Sprintf("failed to generate master key: %v", err)) } - return &keyring.MasterKey{ + return &testMasterKey{ ID: "test-key-1", Key: key, } } // createMasterKeyChain creates a master key chain with KMS encryption using localsecrets provider. -func createMasterKeyChain(masterKey *keyring.MasterKey) *keyring.MasterKeyChain { +func createMasterKeyChain(masterKey *testMasterKey) *keyring.MasterKeyChain { ctx := context.Background() // Generate a random KMS key for localsecrets provider @@ -112,20 +119,14 @@ func createMasterKeyChain(masterKey *keyring.MasterKey) *keyring.MasterKeyChain // Open KMS keeper kmsService := keyring.NewKMSService() - keeperInterface, err := kmsService.OpenKeeper(ctx, kmsKeyURI) + keeper, err := kmsService.OpenKeeper(ctx, kmsKeyURI) if err != nil { panic(fmt.Sprintf("failed to open KMS keeper: %v", err)) } defer func() { - _ = keeperInterface.Close() + _ = keeper.Close() }() - // Type assert to get Encrypt method - keeper, ok := keeperInterface.(*secrets.Keeper) - if !ok { - panic("keeper should be *secrets.Keeper") - } - // Encrypt master key with KMS ciphertext, err := keeper.Encrypt(ctx, masterKey.Key) if err != nil { @@ -177,23 +178,19 @@ func generateLocalSecretsKMSKey(t *testing.T) string { func createMasterKeyChainWithKMS( ctx context.Context, t *testing.T, - masterKey *keyring.MasterKey, + masterKey *testMasterKey, kmsKeyURI string, ) *keyring.MasterKeyChain { t.Helper() // Open KMS keeper kmsService := keyring.NewKMSService() - keeperInterface, err := kmsService.OpenKeeper(ctx, kmsKeyURI) + keeper, err := kmsService.OpenKeeper(ctx, kmsKeyURI) require.NoError(t, err, "failed to open KMS keeper") defer func() { - assert.NoError(t, keeperInterface.Close()) + assert.NoError(t, keeper.Close()) }() - // Type assert to get Encrypt method - keeper, ok := keeperInterface.(*secrets.Keeper) - require.True(t, ok, "keeper should be *secrets.Keeper") - // Encrypt master key with KMS ciphertext, err := keeper.Encrypt(ctx, masterKey.Key) require.NoError(t, err, "failed to encrypt master key with KMS") diff --git a/test/integration/kms_flow_test.go b/test/integration/kms_flow_test.go index 2946a85..2c68ca9 100644 --- a/test/integration/kms_flow_test.go +++ b/test/integration/kms_flow_test.go @@ -15,7 +15,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gocloud.dev/secrets" "github.com/allisson/secrets/internal/config" "github.com/allisson/secrets/internal/keyring" @@ -49,12 +48,10 @@ func TestIntegration_KMS_CompleteFlow(t *testing.T) { assert.NotNil(t, ctx.masterKeyChain) // Verify active master key exists - activeKey, exists := ctx.masterKeyChain.Get(ctx.masterKeyChain.ActiveMasterKeyID()) - assert.True(t, exists, "active master key should exist") - assert.NotNil(t, activeKey, "active master key should not be nil") - assert.Equal(t, "test-key-1", activeKey.ID) + assert.Equal(t, "test-key-1", ctx.masterKeyChain.ActiveMasterKeyID()) + assert.True(t, ctx.masterKeyChain.Has("test-key-1"), "active master key should exist") - t.Logf("KMS master key loaded: id=%s", activeKey.ID) + t.Logf("KMS master key loaded: id=%s", ctx.masterKeyChain.ActiveMasterKeyID()) }) // [2/7] Verify KEK created with KMS master key @@ -113,7 +110,7 @@ func TestIntegration_KMS_CompleteFlow(t *testing.T) { // [5/7] Rotate master key with KMS t.Run("05_RotateMasterKeyWithKMS", func(t *testing.T) { // Generate new master key - newMasterKey := &keyring.MasterKey{ + newMasterKey := &testMasterKey{ ID: "test-key-2", Key: make([]byte, 32), } @@ -122,15 +119,12 @@ func TestIntegration_KMS_CompleteFlow(t *testing.T) { // Encrypt new master key with KMS kmsService := keyring.NewKMSService() - keeperInterface, err := kmsService.OpenKeeper(context.Background(), ctx.kmsKeyURI) + keeper, err := kmsService.OpenKeeper(context.Background(), ctx.kmsKeyURI) require.NoError(t, err) defer func() { - assert.NoError(t, keeperInterface.Close()) + assert.NoError(t, keeper.Close()) }() - keeper, ok := keeperInterface.(*secrets.Keeper) - require.True(t, ok) - newCiphertext, err := keeper.Encrypt(context.Background(), newMasterKey.Key) require.NoError(t, err) newEncodedCiphertext := base64.StdEncoding.EncodeToString(newCiphertext) @@ -168,13 +162,8 @@ func TestIntegration_KMS_CompleteFlow(t *testing.T) { ctx.masterKeyChain = newChain // Verify both keys loaded - oldKey, oldExists := ctx.masterKeyChain.Get("test-key-1") - assert.True(t, oldExists, "old master key should still exist") - assert.NotNil(t, oldKey) - - activeKey, activeExists := ctx.masterKeyChain.Get("test-key-2") - assert.True(t, activeExists, "new master key should exist") - assert.NotNil(t, activeKey) + assert.True(t, ctx.masterKeyChain.Has("test-key-1"), "old master key should still exist") + assert.True(t, ctx.masterKeyChain.Has("test-key-2"), "new master key should exist") assert.Equal(t, "test-key-2", ctx.masterKeyChain.ActiveMasterKeyID()) t.Logf("Master key rotated: old=%s, new=%s (active)", "test-key-1", "test-key-2")