forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestDockerCopy.groovy
73 lines (57 loc) · 2.32 KB
/
TestDockerCopy.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
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.equalTo
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.CoreMatchers.hasItems
import static org.hamcrest.CoreMatchers.notNullValue
import static org.hamcrest.MatcherAssert.assertThat
class TestDockerCopy extends BuildPipelineTest {
String sourceImageRegistry = 'opensearchstaging'
String sourceImage = 'opensearch:1.3.2'
String destinationImageRegistry = 'opensearchproject'
String destinationImage = 'opensearch:1.3.2'
@Override
@Before
void setUp() {
super.setUp()
// Variables
binding.setVariable('SOURCE_IMAGE_REGISTRY', sourceImageRegistry)
binding.setVariable('SOURCE_IMAGE', sourceImage)
binding.setVariable('DESTINATION_IMAGE_REGISTRY', destinationImageRegistry)
binding.setVariable('DESTINATION_IMAGE', destinationImage)
}
@Test
void DockerCopyRegression() {
super.testPipeline('jenkins/docker/docker-copy.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/docker/docker-copy.jenkinsfile')
}
@Test
public void DockerCopyExecuteWithoutErrors() {
runScript("jenkins/docker/docker-copy.jenkinsfile")
assertJobStatusSuccess()
// Ensure the gcrane is executed in an external shell script exactely once
def copyContainerCommand = getCommands('docker').findAll {
shCommand -> shCommand.contains('gcrane cp opensearchstaging/opensearch:1.3.2 opensearchproject/opensearch:1.3.2; docker logout')
}
assertThat(copyContainerCommand.size(), equalTo(1))
// Validating docker-copy.jenkinsfile does run copyContainer.groovy
assertCallStack().contains("docker-copy.copyContainer")
printCallStack()
}
def getCommands(String commandString) {
def shCurlCommands = helper.callStack.findAll { call ->
call.methodName == 'sh'
}.collect { call ->
callArgsToString(call)
}.findAll { externalCommand ->
externalCommand.contains(commandString)
}
return shCurlCommands
}
}