2018-06-06 11:19:19 +02:00
|
|
|
import util.BasePiperTest
|
2018-01-26 15:55:15 +02:00
|
|
|
import util.Rules
|
2018-01-16 10:33:13 +02:00
|
|
|
|
2017-11-24 14:59:40 +02:00
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.ExpectedException
|
2018-01-16 10:33:13 +02:00
|
|
|
import org.junit.rules.RuleChain
|
2017-11-24 14:59:40 +02:00
|
|
|
|
2018-08-31 10:22:43 +02:00
|
|
|
import util.JenkinsReadYamlRule
|
2018-02-28 14:11:09 +02:00
|
|
|
import util.JenkinsStepRule
|
2018-01-26 14:35:49 +02:00
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
class PipelineExecuteTest extends BasePiperTest {
|
2018-01-16 10:33:13 +02:00
|
|
|
private ExpectedException thrown = new ExpectedException().none()
|
2019-01-22 10:25:42 +02:00
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
2018-01-16 10:33:13 +02:00
|
|
|
|
2017-11-24 14:59:40 +02:00
|
|
|
@Rule
|
2018-02-28 14:11:09 +02:00
|
|
|
public RuleChain ruleChain = Rules
|
|
|
|
.getCommonRules(this)
|
2018-08-31 10:22:43 +02:00
|
|
|
.around(new JenkinsReadYamlRule(this))
|
2018-02-28 14:11:09 +02:00
|
|
|
.around(thrown)
|
2019-01-22 10:25:42 +02:00
|
|
|
.around(stepRule)
|
2017-11-24 14:59:40 +02:00
|
|
|
|
|
|
|
def pipelinePath
|
|
|
|
def checkoutParameters = [:]
|
|
|
|
def load
|
|
|
|
|
|
|
|
@Before
|
2018-01-16 10:33:13 +02:00
|
|
|
void init() {
|
2017-11-24 14:59:40 +02:00
|
|
|
pipelinePath = null
|
|
|
|
checkoutParameters.clear()
|
|
|
|
load = null
|
|
|
|
|
|
|
|
helper.registerAllowedMethod('deleteDir', [], null)
|
|
|
|
helper.registerAllowedMethod('checkout', [Map], { m ->
|
|
|
|
checkoutParameters.branch = m.branches[0].name
|
|
|
|
checkoutParameters.repoUrl = m.userRemoteConfigs[0].url
|
|
|
|
checkoutParameters.credentialsId = m.userRemoteConfigs[0].credentialsId
|
|
|
|
checkoutParameters.path = m.extensions[0].sparseCheckoutPaths[0].path
|
|
|
|
})
|
|
|
|
helper.registerAllowedMethod('load', [String], { s -> load = s })
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void straightForwardTest() {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.pipelineExecute(repoUrl: "https://test.com/myRepo.git")
|
2017-11-28 10:34:54 +02:00
|
|
|
assert load == "Jenkinsfile"
|
2017-11-24 14:59:40 +02:00
|
|
|
assert checkoutParameters.branch == 'master'
|
|
|
|
assert checkoutParameters.repoUrl == "https://test.com/myRepo.git"
|
|
|
|
assert checkoutParameters.credentialsId == ''
|
|
|
|
assert checkoutParameters.path == 'Jenkinsfile'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void parameterizeTest() {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.pipelineExecute(repoUrl: "https://test.com/anotherRepo.git",
|
2018-01-16 18:06:25 +02:00
|
|
|
branch: 'feature',
|
|
|
|
path: 'path/to/Jenkinsfile',
|
|
|
|
credentialsId: 'abcd1234')
|
|
|
|
|
2017-11-28 10:34:54 +02:00
|
|
|
assert load == "path/to/Jenkinsfile"
|
2017-11-24 14:59:40 +02:00
|
|
|
assert checkoutParameters.branch == 'feature'
|
|
|
|
assert checkoutParameters.repoUrl == "https://test.com/anotherRepo.git"
|
|
|
|
assert checkoutParameters.credentialsId == 'abcd1234'
|
|
|
|
assert checkoutParameters.path == 'path/to/Jenkinsfile'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void noRepoUrlTest() {
|
|
|
|
thrown.expect(Exception)
|
|
|
|
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR repoUrl")
|
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.pipelineExecute()
|
2017-11-24 14:59:40 +02:00
|
|
|
}
|
|
|
|
}
|