forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestValidateArtifacts.groovy
87 lines (72 loc) · 3.36 KB
/
TestValidateArtifacts.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
/*
* 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 com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat
import static org.junit.jupiter.api.Assertions.assertThrows
class TestValidateArtifacts extends BuildPipelineTest {
@Override
@Before
void setUp() {
helper.registerSharedLibrary(
library().name('jenkins')
.defaultVersion('4.2.2')
.allowOverride(true)
.implicit(true)
.targetPath('vars')
.retriever(gitSource('https://github.com/opensearch-project/opensearch-build-libraries.git'))
.build()
)
super.setUp()
binding.setVariable('BUILD_NUMBER', '123')
binding.setVariable('VERSION', "2.3.0")
binding.setVariable('OS_BUILD_NUMBER', "6039")
binding.setVariable('OSD_BUILD_NUMBER', "4104")
binding.setVariable('DISTRIBUTION', "docker tar rpm yum")
binding.setVariable('ARCHITECTURE', "x64 arm64")
binding.setVariable('OPTIONAL_ARGS', "using-staging-artifact-only")
helper.registerAllowedMethod('fileExists', [String.class], { args ->
return true;
})
helper.registerAllowedMethod('unstash', [String.class], null)
}
@Test
public void testValidateArtifactsPipeline() {
super.testPipeline("jenkins/validate-artifacts/validate-artifacts.jenkinsfile",
"tests/jenkins/jenkinsjob-regression-files/validate-artifacts/validate-artifacts.jenkinsfile")
assertThat(getCommandExecutions('sh', 'validation.sh'), hasItem('/tmp/workspace/validation.sh --version 2.3.0 --distribution docker --arch x64 --os-build-number 6039 --osd-build-number 4104 --using-staging-artifact-only '))
assertThat(getCommandExecutions('sh', 'validation.sh'), hasItem('/tmp/workspace/validation.sh --version 2.3.0 --distribution tar --arch arm64'))
assertThat(getCommandExecutions('sh', 'validation.sh'), hasItem('/tmp/workspace/validation.sh --version 2.3.0 --distribution rpm --arch x64'))
assertThat(getCommandExecutions('sh', 'validation.sh'), hasItem('/tmp/workspace/validation.sh --version 2.3.0 --distribution yum --arch arm64'))
}
@Test
public void testDockerArgs() {
binding.setVariable('OS_BUILD_NUMBER', "")
binding.setVariable('OSD_BUILD_NUMBER', "")
runScript('jenkins/validate-artifacts/validate-artifacts.jenkinsfile')
assertJobStatusFailure()
assertThat(getCommandExecutions('error', ''), hasItem('Provide OS_BUILD_NUMBER and OSD_BUILD_NUMBER args for Docker Validation'))
}
def getCommandExecutions(methodName, command) {
def shCommands = helper.callStack.findAll {
call ->
call.methodName == methodName
}.
collect {
call ->
callArgsToString(call)
}.findAll {
shCommand ->
shCommand.contains(command)
}
return shCommands
}
}