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
|
2020-01-15 13:16:25 +02:00
|
|
|
import util.JenkinsFileExistsRule
|
2018-10-25 16:56:09 +02:00
|
|
|
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)
|
2020-01-15 13:16:25 +02:00
|
|
|
private JenkinsFileExistsRule fileExistsRule = new JenkinsFileExistsRule(this, [])
|
2019-11-21 17:34:22 +02:00
|
|
|
|
|
|
|
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)
|
2020-01-15 13:16:25 +02:00
|
|
|
.around(fileExistsRule)
|
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() {
|
2020-05-05 15:21:59 +02:00
|
|
|
helper.registerAllowedMethod('findFiles', [Map.class], {return null})
|
2019-11-21 17:34:22 +02:00
|
|
|
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')
|
2020-05-05 15:21:59 +02:00
|
|
|
shellCallRule.setReturnValue('./piper getConfig --contextConfig --stepMetadata \'.pipeline/tmp/metadata/githubrelease.yaml\'', '{"githubTokenCredentialsId":"githubTokenId"}')
|
2018-10-25 16:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2019-11-21 17:34:22 +02:00
|
|
|
void testGithubPublishReleaseDefault() {
|
2020-05-05 15:21:59 +02:00
|
|
|
// test
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.githubPublishRelease(
|
2020-05-05 15:21:59 +02:00
|
|
|
script: nullScript,
|
2019-11-21 17:34:22 +02:00
|
|
|
juStabUtils: utils,
|
2020-05-05 15:21:59 +02:00
|
|
|
jenkinsUtilsStub: jenkinsUtils,
|
|
|
|
testParam: "This is test content"
|
2018-10-25 16:56:09 +02:00
|
|
|
)
|
|
|
|
// asserts
|
2020-05-05 15:21:59 +02:00
|
|
|
assertThat(writeFileRule.files['.pipeline/tmp/metadata/githubrelease.yaml'], containsString('name: githubPublishRelease'))
|
2019-11-21 17:34:22 +02:00
|
|
|
assertThat(withEnvArgs[0], allOf(startsWith('PIPER_parametersJSON'), containsString('"testParam":"This is test content"')))
|
2020-02-19 10:05:53 +02:00
|
|
|
assertThat(shellCallRule.shell[1], is('./piper githubPublishRelease'))
|
2018-10-25 16:56:09 +02:00
|
|
|
}
|
|
|
|
}
|