aboutsummaryrefslogtreecommitdiffstats
path: root/internal/bolttest
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-10-18 10:43:39 -0400
committerEugene Triguba <hello@eugenetriguba.com>2025-11-26 11:46:57 -0500
commite5658d1f61415054029b66cd2f703f1f40138460 (patch)
treec609e209f4cebc62dd985d1b773558f47eb73bf6 /internal/bolttest
parentAdd is-branch main check for docs deployment (diff)
downloadcli-e5658d1f61415054029b66cd2f703f1f40138460.zip
Add support for migration dependencies
Diffstat (limited to 'internal/bolttest')
-rw-r--r--internal/bolttest/mock_migration_dependency_graph.go65
-rw-r--r--internal/bolttest/mock_migration_executor.go26
-rw-r--r--internal/bolttest/mock_migration_query_service.go31
3 files changed, 122 insertions, 0 deletions
diff --git a/internal/bolttest/mock_migration_dependency_graph.go b/internal/bolttest/mock_migration_dependency_graph.go
new file mode 100644
index 0000000..1d73ca4
--- /dev/null
+++ b/internal/bolttest/mock_migration_dependency_graph.go
@@ -0,0 +1,65 @@
+package bolttest
+
+import "git.sr.ht/~eugenetriguba/bolt/internal/models"
+
+type MockMigrationDependencyGraph struct {
+ TopologicalSortReturnValue TopologicalSortReturnValue
+ TopologicalSortCallCount int
+ ReverseTopologicalSortReturnValue ReverseTopologicalSortReturnValue
+ ReverseTopologicalSortCallCount int
+ CheckDependenciesAppliedReturnValue CheckDependenciesAppliedReturnValue
+ CheckDependenciesAppliedCallCount int
+ CheckNoDependentsAppliedReturnValue CheckNoDependentsAppliedReturnValue
+ CheckNoDependentsAppliedCallCount int
+ FindLeafNodesReturnValue FindLeafNodesReturnValue
+ FindLeafNodesCallCount int
+}
+
+type TopologicalSortReturnValue struct {
+ Migrations []*models.Migration
+ Err error
+}
+
+type ReverseTopologicalSortReturnValue = TopologicalSortReturnValue
+
+type CheckDependenciesAppliedReturnValue struct {
+ Err error
+}
+
+type CheckNoDependentsAppliedReturnValue = CheckDependenciesAppliedReturnValue
+
+type FindLeafNodesReturnValue struct {
+ LeafNodes []string
+ Err error
+}
+
+func (g *MockMigrationDependencyGraph) TopologicalSort(migrations []*models.Migration) ([]*models.Migration, error) {
+ g.TopologicalSortCallCount++
+ return g.TopologicalSortReturnValue.Migrations, g.TopologicalSortReturnValue.Err
+}
+
+func (g *MockMigrationDependencyGraph) ReverseTopologicalSort(migrations []*models.Migration) ([]*models.Migration, error) {
+ g.ReverseTopologicalSortCallCount++
+ return g.ReverseTopologicalSortReturnValue.Migrations, g.ReverseTopologicalSortReturnValue.Err
+}
+
+func (g *MockMigrationDependencyGraph) CheckDependenciesApplied(
+ migration *models.Migration,
+ allMigrations []*models.Migration,
+) error {
+ g.CheckDependenciesAppliedCallCount++
+ return g.CheckDependenciesAppliedReturnValue.Err
+}
+
+func (g *MockMigrationDependencyGraph) CheckNoDependentsApplied(
+ migration *models.Migration,
+ allMigrations []*models.Migration,
+) error {
+ g.CheckNoDependentsAppliedCallCount++
+ return g.CheckNoDependentsAppliedReturnValue.Err
+}
+
+func (g *MockMigrationDependencyGraph) FindLeafNodes(localMigrations map[string]*models.Migration) ([]string, error) {
+ g.FindLeafNodesCallCount++
+ return g.FindLeafNodesReturnValue.LeafNodes, g.FindLeafNodesReturnValue.Err
+}
diff --git a/internal/bolttest/mock_migration_executor.go b/internal/bolttest/mock_migration_executor.go
new file mode 100644
index 0000000..74eda4f
--- /dev/null
+++ b/internal/bolttest/mock_migration_executor.go
@@ -0,0 +1,26 @@
+package bolttest
+
+import "git.sr.ht/~eugenetriguba/bolt/internal/models"
+
+type MockMigrationExecutor struct {
+ ApplyReturnValue ExecutorApplyReturnValue
+ ApplyCallCount int
+ RevertReturnValue ExecutorRevertReturnValue
+ RevertCallCount int
+}
+
+type ExecutorApplyReturnValue struct {
+ Err error
+}
+
+type ExecutorRevertReturnValue = ExecutorApplyReturnValue
+
+func (e *MockMigrationExecutor) Apply(migration *models.Migration) error {
+ e.ApplyCallCount++
+ return e.ApplyReturnValue.Err
+}
+
+func (e *MockMigrationExecutor) Revert(migration *models.Migration) error {
+ e.RevertCallCount++
+ return e.RevertReturnValue.Err
+}
diff --git a/internal/bolttest/mock_migration_query_service.go b/internal/bolttest/mock_migration_query_service.go
new file mode 100644
index 0000000..9200929
--- /dev/null
+++ b/internal/bolttest/mock_migration_query_service.go
@@ -0,0 +1,31 @@
+package bolttest
+
+import "git.sr.ht/~eugenetriguba/bolt/internal/models"
+
+type MockMigrationQueryService struct {
+ ListMigrationsReturnValue QueryListMigrationsReturnValue
+ ListMigrationsCallCount int
+ CombineMigrationsReturnValue QueryCombineMigrationsReturnValue
+ CombineMigrationsCallCount int
+}
+
+type QueryListMigrationsReturnValue struct {
+ Migrations []*models.Migration
+ Err error
+}
+
+type QueryCombineMigrationsReturnValue = QueryListMigrationsReturnValue
+
+func (s *MockMigrationQueryService) ListMigrations(order interface{}) ([]*models.Migration, error) {
+ s.ListMigrationsCallCount++
+ return s.ListMigrationsReturnValue.Migrations, s.ListMigrationsReturnValue.Err
+}
+
+func (s *MockMigrationQueryService) CombineMigrations(
+ localMigrations map[string]*models.Migration,
+ appliedMigrations map[string]*models.Migration,
+ order interface{},
+) ([]*models.Migration, error) {
+ s.CombineMigrationsCallCount++
+ return s.CombineMigrationsReturnValue.Migrations, s.CombineMigrationsReturnValue.Err
+}