1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Merge remote-tracking branch 'github/master' into HEAD

This commit is contained in:
Marcus Holl 2018-09-12 11:14:03 +02:00
commit 8afec9b4dc
6 changed files with 14 additions and 176 deletions

View File

@ -23,13 +23,4 @@ class ConfigurationMerger {
merged = merge(parameters, parameterKeys, merged)
return merged
}
@NonCPS
static Map merge(
def script, def stepName,
Map parameters, Set parameterKeys,
Set stepConfigurationKeys
) {
merge(script, stepName, parameters, parameterKeys, [:], stepConfigurationKeys)
}
}

View File

@ -1,9 +1,13 @@
#!groovy
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import com.sap.piper.GitUtils
import util.BasePiperTest
import util.JenkinsDockerExecuteRule
import util.JenkinsEnvironmentRule
@ -26,6 +30,16 @@ import static org.junit.Assert.assertEquals
class ArtifactSetVersionTest extends BasePiperTest {
Map dockerParameters
def GitUtils gitUtils = new GitUtils() {
boolean insideWorkTree() {
return true
}
String getGitCommitIdOrNull() {
return 'testCommitId'
}
}
def sshAgentList = []
private ExpectedException thrown = ExpectedException.none()
@ -61,10 +75,8 @@ class ArtifactSetVersionTest extends BasePiperTest {
return closure()
})
jscr.setReturnValue('git rev-parse HEAD', 'testCommitId')
jscr.setReturnValue("date --universal +'%Y%m%d%H%M%S'", '20180101010203')
jscr.setReturnValue('git diff --quiet HEAD', 0)
jscr.setReturnValue('git rev-parse --is-inside-work-tree 1>/dev/null 2>&1', 0)
helper.registerAllowedMethod('fileExists', [String.class], {true})
}

View File

@ -1,12 +1,9 @@
import org.junit.Before
import org.junit.BeforeClass
import org.junit.ClassRule
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import org.junit.rules.TemporaryFolder
import org.yaml.snakeyaml.parser.ParserException
import hudson.AbortException
@ -23,9 +20,6 @@ public class MtaBuildTest extends BasePiperTest {
def toolMtaValidateCalled = false
def toolJavaValidateCalled = false
@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder()
private ExpectedException thrown = new ExpectedException()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@ -43,11 +37,6 @@ public class MtaBuildTest extends BasePiperTest {
.around(jder)
.around(jsr)
@BeforeClass
static void createTestFiles() {
}
@Before
void init() {

View File

@ -17,9 +17,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
@TestExecutionListeners(listeners = [LibraryLoadingTestExecutionListener.class], mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
abstract class BasePiperTest extends BasePipelineTest {
@Autowired
MockHelper mockHelper
@Autowired
Script nullScript

View File

@ -36,10 +36,4 @@ class BasePiperTestContext {
LibraryLoadingTestExecutionListener.prepareObjectInterceptors(mockUtils)
return mockUtils
}
@Bean
MockHelper mockHelper() {
return new MockHelper()
}
}

View File

@ -1,145 +0,0 @@
#!groovy
package util
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import hudson.tasks.junit.TestResult
import org.yaml.snakeyaml.Yaml
/**
* This is a Helper class for mocking.
*
* It can be used to load test data or to mock Jenkins or Maven specific objects.
**/
class MockHelper {
/**
* load properties from resources for mocking return value of readProperties method
* @param path to properties
* @return properties file
*/
Properties loadProperties( String path ){
Properties p = new Properties()
File pFile = new File( path )
p.load( pFile.newDataInputStream() )
return p
}
/**
* load JSON from resources for mocking return value of readJSON method
* @param path to json file
* @return json file
*/
Object loadJSON( String path ){
def js = new JsonSlurper()
def reader = new BufferedReader(new FileReader( path ))
def j = js.parse(reader)
return j
}
/**
* load YAML from resources for mocking return value of readYaml method
* @param path to yaml file
* @return yaml file
*/
Object loadYAML( String path ){
return new Yaml().load(new FileReader(path))
}
/**
* creates HTTP response for mocking return value of httpRequest method
* @param text - text to parse into json object
* @return json Object
*/
Object createResponse( String text ){
def response = new JsonBuilder(new JsonSlurper().parseText( text ))
return response
}
/**
* load File from resources for mocking return value of readFile method
* @param path to file
* @return File
*/
File loadFile( String path ){
return new File( path )
}
/**
* load POM from resources for mocking return value of readMavenPom method
* @param path to pom file
* @return Pom class
*/
MockPom loadPom(String path ){
return new MockPom( path )
}
/**
* Inner class to mock maven descriptor
*/
class MockPom {
def f
def pom
MockPom(String path){
this.f = new File( path )
if ( f.exists() ){
this.pom = new XmlSlurper().parse(f)
}
else {
throw new FileNotFoundException( 'Failed to find file: ' + path )
}
}
String getVersion(){
return pom.version
}
String getGroupId(){
return pom.groupId
}
String getArtifactId(){
return pom.artifactId
}
String getPackaging(){
return pom.packaging
}
String getName(){
return pom.name
}
}
MockBuild loadMockBuild(){
return new MockBuild()
}
MockBuild loadMockBuild(TestResult result){
return new MockBuild(result)
}
/**
* Inner class to mock Jenkins' currentBuild return object in scripts
*/
class MockBuild {
TestResult testResult
MockBuild(){}
MockBuild(TestResult result){
testResult = result
}
MockLibrary getAction(Class c){
println("MockLibrary -> getAction - arg: " + c.toString() )
return new MockLibrary()
}
class MockLibrary {
MockLibrary(){}
// return default
List getLibraries(){
println("MockLibrary -> getLibraries")
return [ [name: 'default-library', version: 'default-master', trusted: true] ]
}
TestResult getResult() {
println("MockLibrary -> getResult")
return testResult
}
}
}
}