forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestDockerReRelease.groovy
93 lines (78 loc) · 3.71 KB
/
TestDockerReRelease.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test
import org.yaml.snakeyaml.Yaml
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
class TestDockerReRelease extends BuildPipelineTest {
@Override
@Before
void setUp() {
helper.registerSharedLibrary(
library().name('jenkins')
.defaultVersion('6.2.0')
.allowOverride(true)
.implicit(true)
.targetPath('vars')
.retriever(gitSource('https://github.com/opensearch-project/opensearch-build-libraries.git'))
.build()
)
helper.registerAllowedMethod('parameterizedCron', [String], null)
super.setUp()
// Variables
addParam('PRODUCT', 'opensearch')
addParam('TAG', '1')
def inputManifest = "tests/jenkins/data/opensearch-1.3.0.yml"
helper.registerAllowedMethod('readYaml', [Map.class], { args ->
return new Yaml().load((inputManifest as File).text)
})
helper.addShMock("""docker inspect --format '{{ index .Config.Labels "org.label-schema.version"}}' opensearchproject/opensearch:1""") { script ->
return [stdout: "1.3.0", exitValue: 0]
}
helper.addShMock("""docker inspect --format '{{ index .Config.Labels "org.label-schema.description"}}' opensearchproject/opensearch:1""") { script ->
return [stdout: "7756", exitValue: 0]
}
helper.addShMock("""date +%Y%m%d""") { script ->
return [stdout: "20230619", exitValue: 0]
}
helper.addShMock("""docker inspect --format '{{ index .Config.Labels "org.label-schema.version"}}' opensearchproject/opensearch:latest""") { script ->
return [stdout: "2.5.0", exitValue: 0]
}
}
@Test
void testReRelease() {
super.testPipeline('jenkins/docker/docker-re-release.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/docker/docker-re-release.jenkinsfile')
}
@Test
void checkForTriggeredJobs(){
runScript('jenkins/docker/docker-re-release.jenkinsfile')
assertThat(getCommandExecutions('build', ''), hasItem('{job=docker-build, propagate=true, wait=true, parameters=[null, null, null]}'))
assertThat(getCommandExecutions('build', ''), hasItem('{job=docker-scan, propagate=true, wait=true, parameters=[null]}'))
assertThat(getCommandExecutions('build', ''), hasItem('{job=docker-promotion, propagate=true, wait=true, parameters=[null, null, null]}'))
assertThat(getCommandExecutions('parameterizedCron', ''), hasItem('\n H 19 15 * * %PRODUCT=opensearch;TAG=1\n H 19 15 * * %PRODUCT=opensearch-dashboards;TAG=1\n H 19 15 * * %PRODUCT=opensearch;TAG=2\n H 19 15 * * %PRODUCT=opensearch-dashboards;TAG=2\n '))
}
def getCommandExecutions(methodName, command) {
def shCommands = helper.callStack.findAll {
call ->
call.methodName == methodName
}.
collect {
call ->
callArgsToString(call)
}.findAll {
shCommand ->
shCommand.contains(command)
}
return shCommands
}
}