aboutsummaryrefslogtreecommitdiffstats
path: root/internal/bolttest
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-02-29 19:53:20 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2024-02-29 19:53:20 -0500
commitbf1d3b3e1fc42132678b244e479839416a03a6ce (patch)
treefbe4f5e7e41b77bc990ebdece673c7f16102f61f /internal/bolttest
parentTweak error and doc for storage module (diff)
downloadcli-bf1d3b3e1fc42132678b244e479839416a03a6ce.zip
Add service tests
Diffstat (limited to 'internal/bolttest')
-rw-r--r--internal/bolttest/mock_migration_db_repo.go78
-rw-r--r--internal/bolttest/mock_migration_fs_repo.go82
-rw-r--r--internal/bolttest/null_outputer.go19
3 files changed, 179 insertions, 0 deletions
diff --git a/internal/bolttest/mock_migration_db_repo.go b/internal/bolttest/mock_migration_db_repo.go
new file mode 100644
index 0000000..bdcc928
--- /dev/null
+++ b/internal/bolttest/mock_migration_db_repo.go
@@ -0,0 +1,78 @@
+package bolttest
+
+import "github.com/eugenetriguba/bolt/internal/models"
+
+type MockMigrationDBRepo struct {
+ ListReturnValue ListReturnValue
+ ListCallCount int
+ IsAppliedReturnValue IsAppliedReturnValue
+ IsAppliedCallCount int
+ ApplyReturnValue ApplyReturnValue
+ ApplyCallCount int
+ ApplyWithTxReturnValue ApplyWithTxReturnValue
+ ApplyWithTxCallCount int
+ RevertReturnValue RevertReturnValue
+ RevertCallCount int
+ RevertWithTxReturnValue RevertWithTxReturnValue
+ RevertWithTxCallCount int
+}
+
+type ListReturnValue struct {
+ Migrations map[string]*models.Migration
+ Err error
+}
+
+type IsAppliedReturnValue struct {
+ IsApplied bool
+ Err error
+}
+
+type ApplyReturnValue struct {
+ Err error
+}
+
+type ApplyWithTxReturnValue = ApplyReturnValue
+type RevertReturnValue = ApplyReturnValue
+type RevertWithTxReturnValue = ApplyReturnValue
+
+func (repo *MockMigrationDBRepo) List() (map[string]*models.Migration, error) {
+ repo.ListCallCount += 1
+ return repo.ListReturnValue.Migrations, repo.ListReturnValue.Err
+}
+
+func (repo *MockMigrationDBRepo) IsApplied(version string) (bool, error) {
+ repo.IsAppliedCallCount += 1
+ return repo.IsAppliedReturnValue.IsApplied, repo.IsAppliedReturnValue.Err
+}
+
+func (repo *MockMigrationDBRepo) Apply(
+ upgradeScript string,
+ migration *models.Migration,
+) error {
+ repo.ApplyCallCount += 1
+ return repo.ApplyReturnValue.Err
+}
+
+func (repo *MockMigrationDBRepo) ApplyWithTx(
+ upgradeScript string,
+ migration *models.Migration,
+) error {
+ repo.ApplyWithTxCallCount += 1
+ return repo.ApplyWithTxReturnValue.Err
+}
+
+func (repo *MockMigrationDBRepo) Revert(
+ downgradeScript string,
+ migration *models.Migration,
+) error {
+ repo.RevertCallCount += 1
+ return repo.RevertReturnValue.Err
+}
+
+func (repo *MockMigrationDBRepo) RevertWithTx(
+ downgradeScript string,
+ migration *models.Migration,
+) error {
+ repo.RevertWithTxCallCount += 1
+ return repo.RevertWithTxReturnValue.Err
+}
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
+}
diff --git a/internal/bolttest/null_outputer.go b/internal/bolttest/null_outputer.go
new file mode 100644
index 0000000..f70b002
--- /dev/null
+++ b/internal/bolttest/null_outputer.go
@@ -0,0 +1,19 @@
+package bolttest
+
+type NullOutputter struct {
+ OutputLogs []string
+ ErrorLogs []string
+ TableLogs []string
+}
+
+func (o NullOutputter) Output(message string) error {
+ return nil
+}
+
+func (o NullOutputter) Error(err error) error {
+ return nil
+}
+
+func (o NullOutputter) Table(header []string, rows [][]string) error {
+ return nil
+}