|
| 1 | +package octopus.teamcity.agent; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.mockito.Mockito.mock; |
| 5 | +import static org.mockito.Mockito.when; |
| 6 | + |
| 7 | +import java.util.HashMap; |
| 8 | +import java.util.Map; |
| 9 | + |
| 10 | +import jetbrains.buildServer.agent.AgentRunningBuild; |
| 11 | +import jetbrains.buildServer.agent.BuildProgressLogger; |
| 12 | +import jetbrains.buildServer.agent.BuildRunnerContext; |
| 13 | +import octopus.teamcity.common.OctopusConstants; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | + |
| 16 | +class OctopusDeployReleaseBuildProcessTest { |
| 17 | + |
| 18 | + @Test |
| 19 | + void buildCommand_includesWaitForDeployment_whenWaitingWithTimeout() { |
| 20 | + final OctopusConstants constants = OctopusConstants.Instance; |
| 21 | + Map<String, String> params = new HashMap<>(); |
| 22 | + params.put(constants.getServerKey(), "https://octopus.example.com"); |
| 23 | + params.put(constants.getApiKey(), "API-KEY"); |
| 24 | + params.put(constants.getProjectNameKey(), "MyProject"); |
| 25 | + params.put(constants.getDeployToKey(), "Production"); |
| 26 | + params.put(constants.getWaitForDeployments(), "true"); |
| 27 | + params.put(constants.getDeploymentTimeout(), "00:30:00"); |
| 28 | + |
| 29 | + AgentRunningBuild runningBuild = mock(AgentRunningBuild.class); |
| 30 | + BuildProgressLogger logger = mock(BuildProgressLogger.class); |
| 31 | + BuildRunnerContext context = mock(BuildRunnerContext.class); |
| 32 | + when(context.getRunnerParameters()).thenReturn(params); |
| 33 | + when(runningBuild.getBuildLogger()).thenReturn(logger); |
| 34 | + |
| 35 | + OctopusDeployReleaseBuildProcess proc = |
| 36 | + new OctopusDeployReleaseBuildProcess(runningBuild, context); |
| 37 | + |
| 38 | + String[] command = proc.createCommand().buildCommand(); |
| 39 | + |
| 40 | + // --deploymenttimeout/--cancelontimeout are silently ignored by the Octopus CLI unless |
| 41 | + // --waitfordeployment is also passed, so it must be present when waiting on a deployment. |
| 42 | + assertThat(command).contains("--waitfordeployment"); |
| 43 | + assertThat(command).contains("--deploymenttimeout", "00:30:00"); |
| 44 | + } |
| 45 | +} |
0 commit comments