Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-26100] Change buildEnvVars to take Run (#55)
- Loading branch information
Showing
6 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package hudson.plugins.accurev; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.Run; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyMap; | ||
import static org.mockito.Mockito.doCallRealMethod; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class AccurevSCMTest { | ||
|
||
@SuppressWarnings("deprecation") | ||
@Test | ||
public void shouldSetEnvironmentVariablesWithAccurevSCM() throws IOException { | ||
AccurevSCM scm = mockSCMForBuildEnvVars(); | ||
|
||
AccurevSCM.AccurevServer server = new AccurevSCM.AccurevServer(null, "test", "test", 5050, "user", "pass"); | ||
when(scm.getServer()).thenReturn(server); | ||
|
||
when(scm.getStream()).thenReturn("testStream"); | ||
|
||
AbstractBuild build = mock(AbstractBuild.class); | ||
Map<String, String> environment = new HashMap<>(); | ||
scm.buildEnvVars(build, environment); | ||
|
||
assertThat(environment.get("ACCUREV_SERVER_HOSTNAME"), is("test")); | ||
assertThat(environment.get("ACCUREV_SERVER_PORT"), is("5050")); | ||
assertThat(environment.get("ACCUREV_STREAM"), is("testStream")); | ||
} | ||
|
||
private AccurevSCM mockSCMForBuildEnvVars() { | ||
AccurevSCM scm = mock(AccurevSCM.class); | ||
doCallRealMethod().when(scm).buildEnvVars(any(AbstractBuild.class), anyMap()); | ||
doCallRealMethod().when(scm).buildEnvironment(any(Run.class), anyMap()); | ||
return scm; | ||
} | ||
} |