mirror of
https://github.com/SAP/jenkins-library.git
synced 2026-06-19 22:58:55 +02:00
handle test repositories (#324)
* handle test repositories
* use GitUtils
* add test case
* fix test cases
* return stash name
* handle seleniumExecuteTests step
* Revert "handle seleniumExecuteTests step"
This reverts commit 2b33d274fe.
* handle seleniumExecuteTests step
* add import of GitUtils
This commit is contained in:
@@ -37,3 +37,18 @@ String[] extractLogLines(String filter = '',
|
||||
?.findAll { line -> line ==~ /${filter}/ }
|
||||
|
||||
}
|
||||
|
||||
static String handleTestRepository(Script steps, Map config){
|
||||
def stashName = "testContent-${UUID.randomUUID()}".toString()
|
||||
def options = [url: config.testRepository]
|
||||
if (config.gitSshKeyCredentialsId)
|
||||
options.put('credentialsId', config.gitSshKeyCredentialsId)
|
||||
if (config.gitBranch)
|
||||
options.put('branch', config.gitBranch)
|
||||
// checkout test repository
|
||||
steps.git options
|
||||
// stash test content
|
||||
steps.stash stashName
|
||||
// return stash name
|
||||
return stashName
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import util.*
|
||||
|
||||
import static org.hamcrest.Matchers.hasItem
|
||||
import static org.hamcrest.Matchers.is
|
||||
import static org.hamcrest.Matchers.startsWith
|
||||
import static org.junit.Assert.assertThat
|
||||
|
||||
class BatsExecuteTestsTest extends BasePiperTest {
|
||||
@@ -104,7 +105,7 @@ class BatsExecuteTestsTest extends BasePiperTest {
|
||||
gitRepository = m
|
||||
})
|
||||
helper.registerAllowedMethod('stash', [String.class], {s ->
|
||||
assertThat(s, is('batsTests'))
|
||||
assertThat(s, startsWith('testContent-'))
|
||||
})
|
||||
|
||||
jsr.step.batsExecuteTests(
|
||||
@@ -115,7 +116,7 @@ class BatsExecuteTestsTest extends BasePiperTest {
|
||||
|
||||
assertThat(gitRepository.size(), is(1))
|
||||
assertThat(gitRepository.url, is('testRepo'))
|
||||
assertThat(jder.dockerParams.stashContent, hasItem('batsTests'))
|
||||
assertThat(jder.dockerParams.stashContent, hasItem(startsWith('testContent-')))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,7 +126,7 @@ class BatsExecuteTestsTest extends BasePiperTest {
|
||||
gitRepository = m
|
||||
})
|
||||
helper.registerAllowedMethod('stash', [String.class], {s ->
|
||||
assertThat(s, is('batsTests'))
|
||||
assertThat(s, startsWith('testContent-'))
|
||||
})
|
||||
|
||||
jsr.step.batsExecuteTests(
|
||||
|
||||
@@ -31,6 +31,7 @@ class SeleniumExecuteTestsTest extends BasePiperTest {
|
||||
@Before
|
||||
void init() throws Exception {
|
||||
bodyExecuted = false
|
||||
helper.registerAllowedMethod('stash', [String.class], null)
|
||||
helper.registerAllowedMethod('git', [Map.class], {m ->
|
||||
gitMap = m
|
||||
})
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
package com.sap.piper
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo
|
||||
import static org.hamcrest.Matchers.hasEntry
|
||||
import static org.hamcrest.Matchers.hasItem
|
||||
import static org.hamcrest.Matchers.is
|
||||
import static org.hamcrest.Matchers.notNullValue
|
||||
import static org.hamcrest.Matchers.startsWith
|
||||
|
||||
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.JenkinsLoggingRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.Rules
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.hamcrest.Matchers.equalTo
|
||||
import static org.junit.Assert.assertTrue
|
||||
import static org.junit.Assert.assertFalse
|
||||
import static org.hamcrest.Matchers.is
|
||||
import static org.hamcrest.Matchers.notNullValue
|
||||
import static org.junit.Assert.assertNotNull
|
||||
import static org.junit.Assert.assertNull
|
||||
import static org.junit.Assert.assertThat
|
||||
@@ -26,11 +32,15 @@ class GitUtilsTest extends BasePiperTest {
|
||||
@Autowired
|
||||
GitUtils gitUtils
|
||||
|
||||
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
ExpectedException thrown = ExpectedException.none()
|
||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
private ExpectedException thrown = ExpectedException.none()
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules.getCommonRules(this).around(jscr).around(thrown)
|
||||
public RuleChain ruleChain = Rules.getCommonRules(this)
|
||||
.around(jlr)
|
||||
.around(jscr)
|
||||
.around(thrown)
|
||||
|
||||
@Before
|
||||
void init() throws Exception {
|
||||
@@ -96,4 +106,24 @@ class GitUtilsTest extends BasePiperTest {
|
||||
assertNotNull(log)
|
||||
assertThat(log.size(),is(equalTo(0)))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHandleTestRepository() {
|
||||
def result, gitMap, stashName, config = [
|
||||
testRepository: 'repoUrl',
|
||||
gitSshKeyCredentialsId: 'abc',
|
||||
gitBranch: 'master'
|
||||
]
|
||||
|
||||
helper.registerAllowedMethod('git', [Map.class], {m -> gitMap = m })
|
||||
helper.registerAllowedMethod("stash", [String.class], { s -> stashName = s})
|
||||
|
||||
result = GitUtils.handleTestRepository(nullScript, config)
|
||||
// asserts
|
||||
assertThat(gitMap, hasEntry('url', config.testRepository))
|
||||
assertThat(gitMap, hasEntry('credentialsId', config.gitSshKeyCredentialsId))
|
||||
assertThat(gitMap, hasEntry('branch', config.gitBranch))
|
||||
assertThat(stashName, startsWith('testContent-'))
|
||||
assertThat(result, startsWith('testContent-'))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import com.sap.piper.Utils
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
import groovy.text.SimpleTemplateEngine
|
||||
import groovy.transform.Field
|
||||
|
||||
@Field String STEP_NAME = 'batsExecuteTests'
|
||||
@Field Set STEP_CONFIG_KEYS = [
|
||||
'dockerImage', //
|
||||
'dockerImage',
|
||||
'dockerWorkspace',
|
||||
'envVars',
|
||||
'failOnError',
|
||||
@@ -39,17 +40,9 @@ def call(Map parameters = [:]) {
|
||||
|
||||
script.commonPipelineEnvironment.setInfluxStepData('bats', false)
|
||||
|
||||
|
||||
if (config.testRepository) {
|
||||
def gitParameters = [url: config.testRepository]
|
||||
if (config.gitSshKeyCredentialsId?.length()>0) gitParameters.credentialsId = config.gitSshKeyCredentialsId
|
||||
if (config.gitBranch?.length()>0) gitParameters.branch = config.gitBranch
|
||||
git gitParameters
|
||||
stash 'batsTests'
|
||||
config.stashContent = ['batsTests']
|
||||
} else {
|
||||
config.stashContent = utils.unstashAll(config.stashContent)
|
||||
}
|
||||
config.stashContent = config.testRepository
|
||||
?[GitUtils.handleTestRepository(this, config)]
|
||||
:utils.unstashAll(config.stashContent)
|
||||
|
||||
//resolve commonPipelineEnvironment references in envVars
|
||||
config.envVarList = []
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import com.sap.piper.Utils
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
import groovy.transform.Field
|
||||
import groovy.text.SimpleTemplateEngine
|
||||
import groovy.transform.Field
|
||||
|
||||
@Field String STEP_NAME = 'newmanExecute'
|
||||
@Field Set STEP_CONFIG_KEYS = [
|
||||
@@ -35,16 +35,9 @@ def call(Map parameters = [:]) {
|
||||
|
||||
new Utils().pushToSWA([step: STEP_NAME], config)
|
||||
|
||||
if (config.testRepository) {
|
||||
def gitParameters = [url: config.testRepository]
|
||||
if (config.gitSshKeyCredentialsId) gitParameters.credentialsId = config.gitSshKeyCredentialsId
|
||||
if (config.gitBranch) gitParameters.branch = config.gitBranch
|
||||
git gitParameters
|
||||
stash 'newmanContent'
|
||||
config.stashContent = ['newmanContent']
|
||||
} else {
|
||||
config.stashContent = utils.unstashAll(config.stashContent)
|
||||
}
|
||||
config.stashContent = config.testRepository
|
||||
?[GitUtils.handleTestRepository(this, config)]
|
||||
:utils.unstashAll(config.stashContent)
|
||||
|
||||
List collectionList = findFiles(glob: config.newmanCollection)?.toList()
|
||||
if (collectionList.isEmpty()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import com.sap.piper.Utils
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
import com.sap.piper.k8s.ContainerMap
|
||||
import groovy.transform.Field
|
||||
@@ -54,14 +55,9 @@ def call(Map parameters = [:], Closure body) {
|
||||
sidecarVolumeBind: config.sidecarVolumeBind
|
||||
) {
|
||||
try {
|
||||
if (config.testRepository) {
|
||||
def gitParameters = [url: config.testRepository]
|
||||
if (config.gitSshKeyCredentialsId) gitParameters.credentialsId = config.gitSshKeyCredentialsId
|
||||
if (config.gitBranch) gitParameters.branch = config.gitBranch
|
||||
git gitParameters
|
||||
} else {
|
||||
config.stashContent = utils.unstashAll(config.stashContent)
|
||||
}
|
||||
config.stashContent = config.testRepository
|
||||
?[GitUtils.handleTestRepository(this, config)]
|
||||
:utils.unstashAll(config.stashContent)
|
||||
body()
|
||||
} catch (err) {
|
||||
if (config.failOnError) {
|
||||
|
||||
Reference in New Issue
Block a user