@@ -39,6 +39,18 @@ class FlywayMigrationPluginTest {
3939
4040 verify(stage). decorate(TerraformEnvironmentStage . PLAN , infoClosure)
4141 }
42+
43+ @Test
44+ void addsFlywayMigrateClosureOnApply () {
45+ def migrateClosure = { -> }
46+ def plugin = spy(new FlywayMigrationPlugin ())
47+ doReturn(migrateClosure). when(plugin). flywayMigrateClosure()
48+ def stage = mock(TerraformEnvironmentStage . class)
49+
50+ plugin. apply(stage)
51+
52+ verify(stage). decorate(TerraformEnvironmentStage . APPLY , migrateClosure)
53+ }
4254 }
4355
4456 @Nested
@@ -91,6 +103,36 @@ class FlywayMigrationPluginTest {
91103 }
92104 }
93105
106+ @Nested
107+ public class FlywayMigrateClosure {
108+ @Test
109+ void runsTheNestedClosure () {
110+ def plugin = new FlywayMigrationPlugin ()
111+ def iWasCalled = false
112+ def nestedClosure = { -> iWasCalled = true }
113+
114+ def flywayClosure = plugin. flywayMigrateClosure()
115+ flywayClosure. delegate = new MockWorkflowScript ()
116+ flywayClosure(nestedClosure)
117+
118+ assertThat (iWasCalled, equalTo(true ))
119+ }
120+
121+ @Test
122+ void setsTheListOfOptionalEnvironmentVariables () {
123+ def plugin = spy(new FlywayMigrationPlugin ())
124+ def expectedList = [' KEY=value' ]
125+ doReturn(expectedList). when(plugin). buildEnvironmentVariableList(any(List . class))
126+ def flywayClosure = plugin. flywayMigrateClosure()
127+ def mockWorkflowScript = spy(new MockWorkflowScript ())
128+ flywayClosure. delegate = mockWorkflowScript
129+
130+ flywayClosure { -> }
131+
132+ verify(mockWorkflowScript). withEnv(eq(expectedList), any(Closure . class))
133+ }
134+ }
135+
94136 @Nested
95137 public class BuildEnvironmentVariableList {
96138 @Test
0 commit comments