2018-02-07 14:17:33 +02:00
|
|
|
package com.sap.piper.versioning
|
|
|
|
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.ExpectedException
|
|
|
|
import org.junit.rules.RuleChain
|
2018-06-06 11:19:19 +02:00
|
|
|
import util.BasePiperTest
|
2018-02-07 14:17:33 +02:00
|
|
|
import util.JenkinsLoggingRule
|
|
|
|
import util.JenkinsReadFileRule
|
|
|
|
import util.JenkinsWriteFileRule
|
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals
|
|
|
|
import static org.junit.Assert.assertTrue
|
|
|
|
|
2018-06-06 11:19:19 +02:00
|
|
|
class DockerArtifactVersioningTest extends BasePiperTest{
|
2018-02-07 14:17:33 +02:00
|
|
|
|
|
|
|
DockerArtifactVersioning av
|
|
|
|
|
|
|
|
String passedDir
|
|
|
|
|
2018-08-31 14:13:11 +02:00
|
|
|
JenkinsReadFileRule jrfr = new JenkinsReadFileRule(this, 'test/resources/versioning/DockerArtifactVersioning')
|
2019-01-22 10:29:15 +02:00
|
|
|
JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this)
|
2019-01-22 10:22:15 +02:00
|
|
|
JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
2018-02-07 14:17:33 +02:00
|
|
|
ExpectedException thrown = ExpectedException.none()
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
public RuleChain ruleChain = Rules
|
|
|
|
.getCommonRules(this)
|
|
|
|
.around(jrfr)
|
2019-01-22 10:29:15 +02:00
|
|
|
.around(writeFileRule)
|
2019-01-22 10:22:15 +02:00
|
|
|
.around(loggingRule)
|
2018-02-07 14:17:33 +02:00
|
|
|
.around(thrown)
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void init() {
|
|
|
|
|
|
|
|
helper.registerAllowedMethod("dir", [String.class, Closure.class], { s, closure ->
|
|
|
|
passedDir = s
|
|
|
|
return closure()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testVersioningFrom() {
|
2018-09-10 16:50:53 +02:00
|
|
|
av = new DockerArtifactVersioning(nullScript, [filePath: 'Dockerfile', dockerVersionSource: 'FROM'])
|
2018-02-07 14:17:33 +02:00
|
|
|
assertEquals('1.2.3', av.getVersion())
|
|
|
|
av.setVersion('1.2.3-20180101')
|
2019-01-22 10:29:15 +02:00
|
|
|
assertEquals('1.2.3-20180101', writeFileRule.files['VERSION'])
|
2019-01-22 10:22:15 +02:00
|
|
|
assertTrue(loggingRule.log.contains('[DockerArtifactVersioning] Version from Docker base image tag: 1.2.3'))
|
2018-02-07 14:17:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void testVersioningEnv() {
|
2018-09-10 16:50:53 +02:00
|
|
|
av = new DockerArtifactVersioning(nullScript, [filePath: 'Dockerfile', dockerVersionSource: 'TEST'])
|
2018-02-07 14:17:33 +02:00
|
|
|
assertEquals('2.3.4', av.getVersion())
|
2019-01-22 10:22:15 +02:00
|
|
|
assertTrue(loggingRule.log.contains('[DockerArtifactVersioning] Version from Docker environment variable TEST: 2.3.4'))
|
2018-02-07 14:17:33 +02:00
|
|
|
}
|
|
|
|
}
|