2020-04-17 11:59:51 +02:00
|
|
|
import hudson.AbortException
|
2018-10-17 16:44:20 +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.*
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.*
|
|
|
|
import static org.junit.Assert.assertThat
|
|
|
|
|
|
|
|
class GaugeExecuteTestsTest extends BasePiperTest {
|
2019-01-22 10:25:42 +02:00
|
|
|
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
2019-01-22 10:22:15 +02:00
|
|
|
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
2019-01-22 10:19:28 +02:00
|
|
|
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
2019-01-22 10:27:45 +02:00
|
|
|
private JenkinsEnvironmentRule environmentRule = new JenkinsEnvironmentRule(this)
|
2018-10-17 16:44:20 +02:00
|
|
|
private ExpectedException thrown = ExpectedException.none()
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
public RuleChain rules = Rules
|
|
|
|
.getCommonRules(this)
|
|
|
|
.around(new JenkinsReadYamlRule(this))
|
2019-01-22 10:19:28 +02:00
|
|
|
.around(shellRule)
|
2019-01-22 10:22:15 +02:00
|
|
|
.around(loggingRule)
|
2019-01-22 10:27:45 +02:00
|
|
|
.around(environmentRule)
|
2019-01-22 10:25:42 +02:00
|
|
|
.around(stepRule)
|
2018-10-17 16:44:20 +02:00
|
|
|
.around(thrown)
|
|
|
|
|
|
|
|
def gitParams = [:]
|
|
|
|
def seleniumParams = [:]
|
|
|
|
|
|
|
|
@Before
|
|
|
|
void init() throws Exception {
|
|
|
|
helper.registerAllowedMethod("git", [Map.class], { map -> gitParams = map })
|
|
|
|
helper.registerAllowedMethod("unstash", [String.class], { s -> return [s]})
|
|
|
|
|
|
|
|
helper.registerAllowedMethod('seleniumExecuteTests', [Map.class, Closure.class], {map, body ->
|
|
|
|
seleniumParams = map
|
|
|
|
return body()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testExecuteGaugeDefaultSuccess() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.gaugeExecuteTests(
|
2018-10-17 16:44:20 +02:00
|
|
|
script: nullScript,
|
|
|
|
juStabUtils: utils,
|
|
|
|
testServerUrl: 'http://test.url'
|
|
|
|
)
|
2019-01-22 10:19:28 +02:00
|
|
|
assertThat(shellRule.shell, hasItem(stringContainsInOrder([
|
2018-10-17 16:44:20 +02:00
|
|
|
'export HOME=${HOME:-$(pwd)}',
|
|
|
|
'if [ "$HOME" = "/" ]; then export HOME=$(pwd); fi',
|
|
|
|
'export PATH=$HOME/bin/gauge:$PATH',
|
|
|
|
'mkdir -p $HOME/bin/gauge',
|
|
|
|
'curl -SsL https://downloads.gauge.org/stable | sh -s -- --location=$HOME/bin/gauge',
|
|
|
|
'gauge telemetry off',
|
|
|
|
'gauge install java',
|
|
|
|
'gauge install html-report',
|
|
|
|
'gauge install xml-report',
|
|
|
|
'mvn test-compile gauge:execute -DspecsDir=specs'
|
|
|
|
])))
|
|
|
|
assertThat(seleniumParams.dockerImage, is('maven:3.5-jdk-8'))
|
|
|
|
assertThat(seleniumParams.dockerEnvVars, hasEntry('TARGET_SERVER_URL', 'http://test.url'))
|
|
|
|
assertThat(seleniumParams.dockerName, is('maven'))
|
|
|
|
assertThat(seleniumParams.dockerWorkspace, is(''))
|
|
|
|
assertThat(seleniumParams.stashContent, hasSize(2))
|
|
|
|
assertThat(seleniumParams.stashContent, allOf(hasItem('buildDescriptor'), hasItem('tests')))
|
|
|
|
assertJobStatusSuccess()
|
|
|
|
}
|
|
|
|
|
2019-07-25 11:57:21 +02:00
|
|
|
@Test
|
|
|
|
void testDockerFromCustomStepConfiguration() {
|
|
|
|
|
|
|
|
def expectedImage = 'image:test'
|
|
|
|
def expectedEnvVars = ['HUB':'', 'HUB_URL':'', 'env1': 'value1', 'env2': 'value2']
|
|
|
|
def expectedOptions = '--opt1=val1 --opt2=val2 --opt3'
|
|
|
|
def expectedWorkspace = '/path/to/workspace'
|
|
|
|
|
|
|
|
nullScript.commonPipelineEnvironment.configuration = [steps:[gaugeExecuteTests:[
|
|
|
|
dockerImage: expectedImage,
|
|
|
|
dockerOptions: expectedOptions,
|
|
|
|
dockerEnvVars: expectedEnvVars,
|
|
|
|
dockerWorkspace: expectedWorkspace
|
|
|
|
]]]
|
|
|
|
|
|
|
|
stepRule.step.gaugeExecuteTests(
|
|
|
|
script: nullScript,
|
|
|
|
juStabUtils: utils
|
|
|
|
)
|
|
|
|
|
|
|
|
assert expectedImage == seleniumParams.dockerImage
|
|
|
|
assert expectedOptions == seleniumParams.dockerOptions
|
|
|
|
assert expectedEnvVars.equals(seleniumParams.dockerEnvVars)
|
|
|
|
assert expectedWorkspace == seleniumParams.dockerWorkspace
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:44:20 +02:00
|
|
|
@Test
|
|
|
|
void testExecuteGaugeNode() throws Exception {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.gaugeExecuteTests(
|
2018-10-17 16:44:20 +02:00
|
|
|
script: nullScript,
|
|
|
|
buildTool: 'npm',
|
|
|
|
dockerEnvVars: ['TARGET_SERVER_URL':'http://custom.url'],
|
|
|
|
juStabUtils: utils,
|
|
|
|
testOptions: 'testSpec'
|
|
|
|
)
|
2019-01-22 10:19:28 +02:00
|
|
|
assertThat(shellRule.shell, hasItem(stringContainsInOrder([
|
2018-10-17 16:44:20 +02:00
|
|
|
'gauge install js',
|
|
|
|
'gauge run testSpec'
|
|
|
|
])))
|
2020-01-29 12:17:56 +02:00
|
|
|
assertThat(seleniumParams.dockerImage, is('node:lts-stretch'))
|
2018-10-17 16:44:20 +02:00
|
|
|
assertThat(seleniumParams.dockerEnvVars, hasEntry('TARGET_SERVER_URL', 'http://custom.url'))
|
|
|
|
assertThat(seleniumParams.dockerName, is('npm'))
|
|
|
|
assertThat(seleniumParams.dockerWorkspace, is('/home/node'))
|
|
|
|
assertJobStatusSuccess()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testExecuteCustomWithError() throws Exception {
|
|
|
|
helper.registerAllowedMethod("sh", [String.class], { s ->
|
|
|
|
throw new RuntimeException('Test Error')
|
|
|
|
})
|
2020-04-17 11:59:51 +02:00
|
|
|
thrown.expect(AbortException)
|
|
|
|
thrown.expectMessage('ERROR: The execution of the gauge tests failed, see the log for details.')
|
2018-10-17 16:44:20 +02:00
|
|
|
try {
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.gaugeExecuteTests(
|
2018-10-17 16:44:20 +02:00
|
|
|
script: nullScript,
|
|
|
|
juStabUtils: utils,
|
|
|
|
dockerImage: 'testImage',
|
|
|
|
dockerName: 'testImageName',
|
|
|
|
dockerWorkspace: '/home/test',
|
|
|
|
failOnError: true,
|
|
|
|
stashContent: ['testStash'],
|
|
|
|
)
|
|
|
|
|
|
|
|
} finally{
|
|
|
|
assertThat(seleniumParams.dockerImage, is('testImage'))
|
|
|
|
assertThat(seleniumParams.dockerName, is('testImageName'))
|
|
|
|
assertThat(seleniumParams.dockerWorkspace, is('/home/test'))
|
|
|
|
assertThat(seleniumParams.stashContent, hasSize(1))
|
2019-01-22 10:22:15 +02:00
|
|
|
assertThat(loggingRule.log, containsString('[gaugeExecuteTests] One or more tests failed'))
|
2018-10-17 16:44:20 +02:00
|
|
|
assertThat(nullScript.currentBuild.result, is('UNSTABLE'))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testExecuteGaugeCustomRepo() throws Exception {
|
|
|
|
helper.registerAllowedMethod('git', [String.class], null)
|
|
|
|
helper.registerAllowedMethod('stash', [String.class], null)
|
|
|
|
|
2019-01-22 10:25:42 +02:00
|
|
|
stepRule.step.gaugeExecuteTests(
|
2018-10-17 16:44:20 +02:00
|
|
|
script: nullScript,
|
|
|
|
juStabUtils: utils,
|
|
|
|
testRepository: 'myTestRepo',
|
|
|
|
failOnError: true
|
|
|
|
)
|
|
|
|
|
|
|
|
// nested matchers do not work correctly
|
|
|
|
assertThat(seleniumParams.stashContent, hasItem(startsWith('testContent-')))
|
|
|
|
assertJobStatusSuccess()
|
|
|
|
}
|
|
|
|
}
|