@@ -2,7 +2,9 @@ import static org.hamcrest.Matchers.equalTo
22import static org.hamcrest.Matchers.hasItem
33import static org.hamcrest.Matchers.instanceOf
44import static org.hamcrest.MatcherAssert.assertThat
5+ import static org.mockito.Mockito.any
56import static org.mockito.Mockito.doReturn;
7+ import static org.mockito.Mockito.eq
68import static org.mockito.Mockito.mock;
79import static org.mockito.Mockito.spy;
810import static org.mockito.Mockito.verify;
@@ -39,16 +41,6 @@ class FlywayMigrationPluginTest {
3941 }
4042 }
4143
42- @Nested
43- public class ConvertOutputToEnvironmentVariable {
44- @Test
45- void isFluent () {
46- def result = FlywayMigrationPlugin . convertOutputToEnvironmentVariable(' output' , ' VARIABLE' )
47-
48- assertThat (result, equalTo(FlywayMigrationPlugin . class))
49- }
50- }
51-
5244 @Nested
5345 public class WithPasswordFromEnvironmentVariable {
5446 @Test
@@ -83,6 +75,58 @@ class FlywayMigrationPluginTest {
8375
8476 assertThat (iWasCalled, equalTo(true ))
8577 }
78+
79+ @Test
80+ void setsTheListOfOptionalEnvironmentVariables () {
81+ def plugin = spy(new FlywayMigrationPlugin ())
82+ def expectedList = [' KEY=value' ]
83+ doReturn(expectedList). when(plugin). buildEnvironmentVariableList(any(List . class))
84+ def flywayClosure = plugin. flywayInfoClosure()
85+ def mockWorkflowScript = spy(new MockWorkflowScript ())
86+ flywayClosure. delegate = mockWorkflowScript
87+
88+ flywayClosure { -> }
89+
90+ verify(mockWorkflowScript). withEnv(eq(expectedList), any(Closure . class))
91+ }
92+ }
93+
94+ @Nested
95+ public class BuildEnvironmentVariableList {
96+ @Test
97+ void returnsEmptyListByDefault () {
98+ def plugin = new FlywayMigrationPlugin ()
99+
100+ def result = plugin. buildEnvironmentVariableList(null )
101+
102+ assertThat (result, equalTo([]))
103+ }
104+
105+ @Test
106+ void setsPasswordWhenVariableProvided () {
107+ def expectedVariable = ' MY_PASSWORD_VARIABLE'
108+ def expectedValue = ' somePass'
109+ FlywayMigrationPlugin . withPasswordFromEnvironmentVariable(expectedVariable)
110+ def plugin = new FlywayMigrationPlugin ()
111+ def env = [(expectedVariable): expectedValue]
112+
113+ def result = plugin. buildEnvironmentVariableList(env)
114+
115+ assertThat (result, equalTo([" FLYWAY_PASSWORD=${ expectedValue} " ]))
116+ }
117+
118+ @Test
119+ void setsUserWhenVariableProvided () {
120+ def expectedVariable = ' MY_USER_VARIABLE'
121+ def expectedValue = ' someUser'
122+ FlywayMigrationPlugin . withUserFromEnvironmentVariable(expectedVariable)
123+ def plugin = new FlywayMigrationPlugin ()
124+ def env = [(expectedVariable): expectedValue]
125+
126+ def result = plugin. buildEnvironmentVariableList(env)
127+
128+ assertThat (result, equalTo([" FLYWAY_USER=${ expectedValue} " ]))
129+ }
86130 }
87131}
88132
0 commit comments