-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding TestDockerCopy.groovy (#2792)
* Add TestDockerCopy.groovy Signed-off-by: Jeff Lu <[email protected]> * update TestDockerCopy.groovy Signed-off-by: Jeff Lu <[email protected]> * update TestDoickerCopy.groovy test cases Signed-off-by: Jeff Lu <[email protected]> * update code comment Signed-off-by: Jeff Lu <[email protected]> Signed-off-by: Jeff Lu <[email protected]>
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/jenkins/jenkinsjob-regression-files/docker/docker-copy.jenkinsfile.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
docker-copy.run() | ||
docker-copy.modernSCM({$class=GitSCMSource, remote=https://github.com/opensearch-project/opensearch-build-libraries.git}) | ||
docker-copy.library({[email protected], retriever=null}) | ||
docker-copy.pipeline(groovy.lang.Closure) | ||
docker-copy.timeout({time=30}) | ||
docker-copy.echo(Executing on agent [label:none]) | ||
docker-copy.stage(Parameters Check, groovy.lang.Closure) | ||
docker-copy.script(groovy.lang.Closure) | ||
docker-copy.stage(Copy Image to ECR/DockerHub, groovy.lang.Closure) | ||
docker-copy.script(groovy.lang.Closure) | ||
docker-copy.copyContainer({sourceImage=opensearch:1.3.2, sourceRegistry=opensearchstaging, destinationImage=opensearch:1.3.2, destinationRegistry=opensearchproject}) | ||
copyContainer.usernamePassword({credentialsId=jenkins-production-dockerhub-credential, usernameVariable=DOCKER_USERNAME, passwordVariable=DOCKER_PASSWORD}) | ||
copyContainer.withCredentials([[DOCKER_USERNAME, DOCKER_PASSWORD]], groovy.lang.Closure) | ||
copyContainer.sh({returnStdout=true, script=echo DOCKER_PASSWORD | docker login --username DOCKER_USERNAME --password-stdin}) | ||
copyContainer.sh(gcrane cp opensearchstaging/opensearch:1.3.2 opensearchproject/opensearch:1.3.2; docker logout) | ||
docker-copy.script(groovy.lang.Closure) | ||
docker-copy.postCleanup() | ||
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) | ||
docker-copy.sh(docker logout opensearchproject && docker image prune -f --all) |