2018-10-25 16:56:09 +02:00
|
|
|
import org.junit.Before
|
|
|
|
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.JenkinsLoggingRule
|
|
|
|
import util.JenkinsReadJsonRule
|
|
|
|
import util.JenkinsReadYamlRule
|
2019-11-21 17:34:22 +02:00
|
|
|
import util.JenkinsShellCallRule
|
2018-10-25 16:56:09 +02:00
|
|
|
import util.JenkinsStepRule
|
2019-11-21 17:34:22 +02:00
|
|
|
import util.JenkinsWriteFileRule
|
2018-10-25 16:56:09 +02:00
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.*
|
|
|
|
import static org.junit.Assert.assertThat
|
|
|
|
|
|
|
|
class GithubPublishReleaseTest extends BasePiperTest {
|
2019-11-21 17:34:22 +02:00
|
|
|
|
|
|
|
private JenkinsCredentialsRule credentialsRule = new JenkinsCredentialsRule(this)
|
2019-01-22 10:30:19 +02:00
|
|
|
private JenkinsReadJsonRule readJsonRule = new JenkinsReadJsonRule(this)
|
2019-11-21 17:34:22 +02:00
|
|
|
private JenkinsShellCallRule shellCallRule = new JenkinsShellCallRule(this)
|
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
|
|
|
private JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this)
|
|
|
|
|
|
|
|
private List withEnvArgs = []
|
2018-10-25 16:56:09 +02:00
|
|
|
|
|
|
|
@Rule
|
|
|
|
public RuleChain rules = Rules
|
|
|
|
.getCommonRules(this)
|
|
|
|
.around(new JenkinsReadYamlRule(this))
|
2019-11-21 17:34:22 +02:00
|
|
|
.around(credentialsRule)
|
2019-01-22 10:30:19 +02:00
|
|
|
.around(readJsonRule)
|
2019-11-21 17:34:22 +02:00
|
|
|
.around(shellCallRule)
|
2019-01-22 10:25:42 +02:00
|
|
|
.around(stepRule)
|
2019-11-21 17:34:22 +02:00
|
|
|
.around(writeFileRule)
|
2019-07-16 20:31:46 +02:00
|
|
|
|
2018-10-25 16:56:09 +02:00
|
|
|
@Before
|
2019-11-21 17:34:22 +02:00
|
|
|
void init() {
|
|
|
|
helper.registerAllowedMethod("withEnv", [List.class, Closure.class], {arguments, closure ->
|
|
|
|
arguments.each {arg ->
|
|
|
|
withEnvArgs.add(arg.toString())
|
2018-10-25 16:56:09 +02:00
|
|
|
}
|
2019-11-21 17:34:22 +02:00
|
|
|
return closure()
|
2018-10-25 16:56:09 +02:00
|
|
|
})
|
2019-11-21 17:34:22 +02:00
|
|
|
credentialsRule.withCredentials('githubTokenId', 'thisIsATestToken')
|
2019-11-25 09:58:16 +02:00
|
|
|
shellCallRule.setReturnValue('./piper getConfig --contextConfig --stepMetadata \'metadata/githubrelease.yaml\'', '{"githubTokenCredentialsId":"githubTokenId"}')
|
2018-10-25 16:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2019-11-21 17:34:22 +02:00
|
|
|
void testGithubPublishReleaseDefault() {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.githubPublishRelease(
|
2019-11-21 17:34:22 +02:00
|
|
|
juStabUtils: utils,
|
|
|
|
testParam: "This is test content",
|
|
|
|
script: nullScript
|
2018-10-25 16:56:09 +02:00
|
|
|
)
|
|
|
|
// asserts
|
2019-11-21 17:34:22 +02:00
|
|
|
assertThat(writeFileRule.files['metadata/githubrelease.yaml'], containsString('name: githubPublishRelease'))
|
|
|
|
assertThat(withEnvArgs[0], allOf(startsWith('PIPER_parametersJSON'), containsString('"testParam":"This is test content"')))
|
|
|
|
assertThat(withEnvArgs[1], is('PIPER_owner='))
|
|
|
|
assertThat(withEnvArgs[2], is('PIPER_repository='))
|
|
|
|
assertThat(withEnvArgs[3], is('PIPER_version='))
|
|
|
|
assertThat(shellCallRule.shell[1], is('./piper githubPublishRelease --token thisIsATestToken'))
|
2018-10-25 16:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2019-11-21 17:34:22 +02:00
|
|
|
void testGithubPublishReleaseWithEnv() {
|
2018-10-25 16:56:09 +02:00
|
|
|
|
2019-11-21 17:34:22 +02:00
|
|
|
nullScript.commonPipelineEnvironment.setArtifactVersion('1.0.0')
|
|
|
|
nullScript.commonPipelineEnvironment.setGithubOrg('TestOrg')
|
|
|
|
nullScript.commonPipelineEnvironment.setGithubRepo('TestRepo')
|
2018-10-25 16:56:09 +02:00
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.githubPublishRelease(
|
2019-11-21 17:34:22 +02:00
|
|
|
juStabUtils: utils,
|
|
|
|
script: nullScript
|
2018-10-25 16:56:09 +02:00
|
|
|
)
|
|
|
|
// asserts
|
2019-11-21 17:34:22 +02:00
|
|
|
assertThat(withEnvArgs[1], is('PIPER_owner=TestOrg'))
|
|
|
|
assertThat(withEnvArgs[2], is('PIPER_repository=TestRepo'))
|
|
|
|
assertThat(withEnvArgs[3], is('PIPER_version=1.0.0'))
|
2018-10-25 16:56:09 +02:00
|
|
|
}
|
|
|
|
}
|