mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
72 lines
2.3 KiB
Groovy
72 lines
2.3 KiB
Groovy
|
package com.sap.piper.versioning
|
||
|
|
||
|
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||
|
import org.junit.Before
|
||
|
import org.junit.Rule
|
||
|
import org.junit.Test
|
||
|
import org.junit.rules.ExpectedException
|
||
|
import org.junit.rules.RuleChain
|
||
|
import util.JenkinsLoggingRule
|
||
|
import util.JenkinsReadFileRule
|
||
|
import util.JenkinsReadMavenPomRule
|
||
|
import util.JenkinsShellCallRule
|
||
|
import util.JenkinsWriteFileRule
|
||
|
import util.Rules
|
||
|
|
||
|
import static org.junit.Assert.assertEquals
|
||
|
import static org.junit.Assert.assertTrue
|
||
|
|
||
|
class DockerArtifactVersioningTest extends BasePipelineTest{
|
||
|
|
||
|
DockerArtifactVersioning av
|
||
|
|
||
|
String passedDir
|
||
|
|
||
|
JenkinsReadFileRule jrfr = new JenkinsReadFileRule(this, 'test/resources/DockerArtifactVersioning')
|
||
|
JenkinsWriteFileRule jwfr = new JenkinsWriteFileRule(this)
|
||
|
JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||
|
ExpectedException thrown = ExpectedException.none()
|
||
|
|
||
|
@Rule
|
||
|
public RuleChain ruleChain = Rules
|
||
|
.getCommonRules(this)
|
||
|
.around(jrfr)
|
||
|
.around(jwfr)
|
||
|
.around(jlr)
|
||
|
.around(thrown)
|
||
|
|
||
|
@Before
|
||
|
public void init() {
|
||
|
|
||
|
helper.registerAllowedMethod("dir", [String.class, Closure.class], { s, closure ->
|
||
|
passedDir = s
|
||
|
return closure()
|
||
|
})
|
||
|
|
||
|
prepareObjectInterceptors(this)
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
void testVersioningFrom() {
|
||
|
av = new DockerArtifactVersioning(this, [filePath: 'Dockerfile', dockerVersionSource: 'FROM'])
|
||
|
assertEquals('1.2.3', av.getVersion())
|
||
|
av.setVersion('1.2.3-20180101')
|
||
|
assertEquals('1.2.3-20180101', jwfr.files['VERSION'])
|
||
|
assertTrue(jlr.log.contains('[DockerArtifactVersioning] Version from Docker base image tag: 1.2.3'))
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
void testVersioningEnv() {
|
||
|
av = new DockerArtifactVersioning(this, [filePath: 'Dockerfile', dockerVersionSource: 'TEST'])
|
||
|
assertEquals('2.3.4', av.getVersion())
|
||
|
assertTrue(jlr.log.contains('[DockerArtifactVersioning] Version from Docker environment variable TEST: 2.3.4'))
|
||
|
}
|
||
|
|
||
|
|
||
|
void prepareObjectInterceptors(object) {
|
||
|
object.metaClass.invokeMethod = helper.getMethodInterceptor()
|
||
|
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()
|
||
|
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
|
||
|
}
|
||
|
}
|