From bf1d3b3e1fc42132678b244e479839416a03a6ce Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Thu, 29 Feb 2024 19:53:20 -0500 Subject: Add service tests --- internal/bolttest/mock_migration_fs_repo.go | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 internal/bolttest/mock_migration_fs_repo.go (limited to 'internal/bolttest/mock_migration_fs_repo.go') diff --git a/internal/bolttest/mock_migration_fs_repo.go b/internal/bolttest/mock_migration_fs_repo.go new file mode 100644 index 0000000..0932b37 --- /dev/null +++ b/internal/bolttest/mock_migration_fs_repo.go @@ -0,0 +1,82 @@ +package bolttest + +import "github.com/eugenetriguba/bolt/internal/models" + +type MockMigrationFsRepo struct { + CreateReturnValue CreateReturnValue + CreateCallCount int + ExistsReturnValue ExistsReturnValue + ExistsCallCount int + GetReturnValue GetReturnValue + GetCallCount int + ListReturnValue ListReturnValue + ListCallCount int + LatestReturnValue LatestReturnValue + LatestCallCount int + ReadUpgradeScriptReturnValue ReadUpgradeScriptReturnValue + ReadUpgradeScriptCallCount int + ReadDowngradeScriptReturnValue ReadDowngradeScriptReturnValue + ReadDowngradeScriptCallCount int +} + +type CreateReturnValue struct { + Err error +} + +type ExistsReturnValue struct { + Exists bool + Err error +} + +type GetReturnValue struct { + Migration *models.Migration + Err error +} + +type LatestReturnValue = GetReturnValue + +type ReadUpgradeScriptReturnValue struct { + ScriptContents string + Err error +} + +type ReadDowngradeScriptReturnValue = ReadUpgradeScriptReturnValue + +func (repo *MockMigrationFsRepo) Create(migration *models.Migration) error { + repo.CreateCallCount += 1 + return repo.CreateReturnValue.Err +} + +func (repo *MockMigrationFsRepo) Exists(version string) (bool, error) { + repo.ExistsCallCount += 1 + return repo.ExistsReturnValue.Exists, repo.ExistsReturnValue.Err +} + +func (repo *MockMigrationFsRepo) Get(version string) (*models.Migration, error) { + repo.GetCallCount += 1 + return repo.GetReturnValue.Migration, repo.GetReturnValue.Err +} + +func (repo *MockMigrationFsRepo) List() (map[string]*models.Migration, error) { + repo.ListCallCount += 1 + return repo.ListReturnValue.Migrations, repo.ListReturnValue.Err +} + +func (repo *MockMigrationFsRepo) Latest() (*models.Migration, error) { + repo.LatestCallCount += 1 + return repo.LatestReturnValue.Migration, repo.LatestReturnValue.Err +} + +func (repo *MockMigrationFsRepo) ReadUpgradeScript( + migration *models.Migration, +) (string, error) { + repo.ReadUpgradeScriptCallCount += 1 + return repo.ReadUpgradeScriptReturnValue.ScriptContents, repo.ReadUpgradeScriptReturnValue.Err +} + +func (repo *MockMigrationFsRepo) ReadDowngradeScript( + migration *models.Migration, +) (string, error) { + repo.ReadDowngradeScriptCallCount += 1 + return repo.ReadDowngradeScriptReturnValue.ScriptContents, repo.ReadDowngradeScriptReturnValue.Err +} -- cgit v1.2.3 From 018083b9259c2265ad3ea2432f315641e5b996ce Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 2 Mar 2024 10:18:41 -0500 Subject: Clean up fs repo and fs repo tests --- internal/bolttest/mock_migration_fs_repo.go | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'internal/bolttest/mock_migration_fs_repo.go') diff --git a/internal/bolttest/mock_migration_fs_repo.go b/internal/bolttest/mock_migration_fs_repo.go index 0932b37..ae933e3 100644 --- a/internal/bolttest/mock_migration_fs_repo.go +++ b/internal/bolttest/mock_migration_fs_repo.go @@ -5,10 +5,6 @@ import "github.com/eugenetriguba/bolt/internal/models" type MockMigrationFsRepo struct { CreateReturnValue CreateReturnValue CreateCallCount int - ExistsReturnValue ExistsReturnValue - ExistsCallCount int - GetReturnValue GetReturnValue - GetCallCount int ListReturnValue ListReturnValue ListCallCount int LatestReturnValue LatestReturnValue @@ -23,18 +19,11 @@ type CreateReturnValue struct { Err error } -type ExistsReturnValue struct { - Exists bool - Err error -} - -type GetReturnValue struct { +type LatestReturnValue struct { Migration *models.Migration Err error } -type LatestReturnValue = GetReturnValue - type ReadUpgradeScriptReturnValue struct { ScriptContents string Err error @@ -47,16 +36,6 @@ func (repo *MockMigrationFsRepo) Create(migration *models.Migration) error { return repo.CreateReturnValue.Err } -func (repo *MockMigrationFsRepo) Exists(version string) (bool, error) { - repo.ExistsCallCount += 1 - return repo.ExistsReturnValue.Exists, repo.ExistsReturnValue.Err -} - -func (repo *MockMigrationFsRepo) Get(version string) (*models.Migration, error) { - repo.GetCallCount += 1 - return repo.GetReturnValue.Migration, repo.GetReturnValue.Err -} - func (repo *MockMigrationFsRepo) List() (map[string]*models.Migration, error) { repo.ListCallCount += 1 return repo.ListReturnValue.Migrations, repo.ListReturnValue.Err -- cgit v1.2.3 From a37df93853def914dbda165cdcf09ae8e0305ec3 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 2 Mar 2024 11:04:00 -0500 Subject: Remove Latest() from migration fs repo in favor of using List on service --- internal/bolttest/mock_migration_fs_repo.go | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'internal/bolttest/mock_migration_fs_repo.go') diff --git a/internal/bolttest/mock_migration_fs_repo.go b/internal/bolttest/mock_migration_fs_repo.go index ae933e3..d392732 100644 --- a/internal/bolttest/mock_migration_fs_repo.go +++ b/internal/bolttest/mock_migration_fs_repo.go @@ -7,8 +7,6 @@ type MockMigrationFsRepo struct { CreateCallCount int ListReturnValue ListReturnValue ListCallCount int - LatestReturnValue LatestReturnValue - LatestCallCount int ReadUpgradeScriptReturnValue ReadUpgradeScriptReturnValue ReadUpgradeScriptCallCount int ReadDowngradeScriptReturnValue ReadDowngradeScriptReturnValue @@ -19,11 +17,6 @@ type CreateReturnValue struct { Err error } -type LatestReturnValue struct { - Migration *models.Migration - Err error -} - type ReadUpgradeScriptReturnValue struct { ScriptContents string Err error @@ -41,11 +34,6 @@ func (repo *MockMigrationFsRepo) List() (map[string]*models.Migration, error) { return repo.ListReturnValue.Migrations, repo.ListReturnValue.Err } -func (repo *MockMigrationFsRepo) Latest() (*models.Migration, error) { - repo.LatestCallCount += 1 - return repo.LatestReturnValue.Migration, repo.LatestReturnValue.Err -} - func (repo *MockMigrationFsRepo) ReadUpgradeScript( migration *models.Migration, ) (string, error) { -- cgit v1.2.3