2019-11-07 16:40:45 +02:00
|
|
|
import java.util.Map
|
|
|
|
import static org.hamcrest.Matchers.hasItem
|
|
|
|
import static org.junit.Assert.assertThat
|
|
|
|
|
|
|
|
import org.hamcrest.Matchers
|
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
|
|
import static org.hamcrest.Matchers.equalTo
|
|
|
|
import org.junit.Before
|
2020-01-22 11:50:26 +02:00
|
|
|
import org.junit.After
|
2019-11-07 16:40:45 +02:00
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.ExpectedException
|
|
|
|
import org.junit.rules.RuleChain
|
|
|
|
|
|
|
|
import util.BasePiperTest
|
|
|
|
import util.JenkinsCredentialsRule
|
|
|
|
import util.JenkinsStepRule
|
2019-12-16 23:02:30 +02:00
|
|
|
import util.JenkinsReadJsonRule
|
2019-11-07 16:40:45 +02:00
|
|
|
import util.JenkinsLoggingRule
|
|
|
|
import util.JenkinsReadYamlRule
|
2019-12-16 23:02:30 +02:00
|
|
|
import util.JenkinsDockerExecuteRule
|
2020-02-04 12:43:27 +02:00
|
|
|
import util.JenkinsWriteFileRule
|
2019-11-07 16:40:45 +02:00
|
|
|
import util.JenkinsShellCallRule
|
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
import hudson.AbortException
|
|
|
|
|
|
|
|
public class AbapEnvironmentPullGitRepoTest extends BasePiperTest {
|
|
|
|
|
|
|
|
private ExpectedException thrown = new ExpectedException()
|
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
|
|
|
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
2019-12-16 23:02:30 +02:00
|
|
|
private JenkinsDockerExecuteRule dockerExecuteRule = new JenkinsDockerExecuteRule(this)
|
2019-11-07 16:40:45 +02:00
|
|
|
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
2019-12-16 23:02:30 +02:00
|
|
|
private JenkinsReadJsonRule readJsonRule = new JenkinsReadJsonRule(this)
|
2019-11-12 18:40:59 +02:00
|
|
|
private JenkinsCredentialsRule credentialsRule = new JenkinsCredentialsRule(this).withCredentials('test_credentialsId', 'user', 'password')
|
2020-02-04 12:43:27 +02:00
|
|
|
private JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this)
|
2019-11-07 16:40:45 +02:00
|
|
|
|
|
|
|
@Rule
|
2020-02-04 12:43:27 +02:00
|
|
|
public RuleChain ruleChain = Rules
|
|
|
|
.getCommonRules(this)
|
2019-11-07 16:40:45 +02:00
|
|
|
.around(new JenkinsReadYamlRule(this))
|
|
|
|
.around(thrown)
|
2019-12-16 23:02:30 +02:00
|
|
|
.around(dockerExecuteRule)
|
2019-11-07 16:40:45 +02:00
|
|
|
.around(stepRule)
|
|
|
|
.around(loggingRule)
|
2019-12-16 23:02:30 +02:00
|
|
|
.around(readJsonRule)
|
2019-11-12 18:40:59 +02:00
|
|
|
.around(credentialsRule)
|
2019-11-07 16:40:45 +02:00
|
|
|
.around(shellRule)
|
2020-02-04 12:43:27 +02:00
|
|
|
.around(writeFileRule)
|
2019-11-07 16:40:45 +02:00
|
|
|
|
2020-02-04 12:43:27 +02:00
|
|
|
private List withEnvArgs = []
|
2019-11-07 16:40:45 +02:00
|
|
|
|
|
|
|
@Test
|
2020-02-04 12:43:27 +02:00
|
|
|
public void test() {
|
2019-11-07 16:40:45 +02:00
|
|
|
|
2020-02-04 12:43:27 +02:00
|
|
|
helper.registerAllowedMethod("withEnv", [List.class, Closure.class], {arguments, closure ->
|
|
|
|
arguments.each {arg ->
|
|
|
|
withEnvArgs.add(arg.toString())
|
2019-12-16 23:02:30 +02:00
|
|
|
}
|
2020-02-04 12:43:27 +02:00
|
|
|
return closure()
|
2019-12-16 23:02:30 +02:00
|
|
|
})
|
2020-02-04 12:43:27 +02:00
|
|
|
credentialsRule.withCredentials('credentialsId', 'testUser', 'testPassword')
|
|
|
|
shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, /.\/piper getConfig --contextConfig --stepMetadata 'metadata\/abapEnvironmentPullGitRepo.yaml'/, /{"credentialsId":"credentialsId"}/ )
|
2019-12-16 23:02:30 +02:00
|
|
|
|
2020-02-04 12:43:27 +02:00
|
|
|
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, juStabUtils: utils, host: 'example.com', repositoryName: 'Z_DEMO_DM', credentialsId: 'test_credentialsId')
|
2019-11-07 16:40:45 +02:00
|
|
|
|
2020-02-04 12:43:27 +02:00
|
|
|
assertThat(shellRule.shell[0], containsString(/.\/piper getConfig --contextConfig --stepMetadata 'metadata\/abapEnvironmentPullGitRepo.yaml'/))
|
|
|
|
assertThat(shellRule.shell[1], containsString(/.\/piper abapEnvironmentPullGitRepo/))
|
2019-11-07 16:40:45 +02:00
|
|
|
}
|
|
|
|
}
|