Skip to content

Commit

Permalink
WIP: start sketching out flway migrate on apply
Browse files Browse the repository at this point in the history
  • Loading branch information
kmanning committed Apr 12, 2021
1 parent 43f3365 commit a9891c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/FlywayMigrationPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FlywayMigrationPlugin implements TerraformEnvironmentStagePlugin, Resettab

public void apply(TerraformEnvironmentStage stage) {
stage.decorate(TerraformEnvironmentStage.PLAN, flywayInfoClosure())
stage.decorate(TerraformEnvironmentStage.APPLY, flywayMigrateClosure())
}

public Closure flywayInfoClosure() {
Expand All @@ -22,6 +23,14 @@ class FlywayMigrationPlugin implements TerraformEnvironmentStagePlugin, Resettab
}
}

public Closure flywayMigrateClosure() {
return { innerClosure ->
innerClosure()

sh "echo run flyway migrate"
}
}

public Collection buildEnvironmentVariableList(env) {
def list = []
if (passwordVariable) {
Expand Down
12 changes: 12 additions & 0 deletions test/FlywayMigrationPluginTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ class FlywayMigrationPluginTest {

verify(stage).decorate(TerraformEnvironmentStage.PLAN, infoClosure)
}

@Test
void addsFlywayMigrateClosureOnApply() {
def migrateClosure = { -> }
def plugin = spy(new FlywayMigrationPlugin())
doReturn(migrateClosure).when(plugin).flywayMigrateClosure()
def stage = mock(TerraformEnvironmentStage.class)

plugin.apply(stage)

verify(stage).decorate(TerraformEnvironmentStage.APPLY, migrateClosure)
}
}

@Nested
Expand Down

0 comments on commit a9891c6

Please sign in to comment.