Skip to content

Commit

Permalink
Add boolean param and the tests
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Zhu <zhujiaxi@amazon.com>
  • Loading branch information
peterzhuamazon committed May 8, 2023
1 parent c2f602f commit f724938
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions tests/jenkins/TestCopyContainer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class TestCopyContainer extends BuildPipelineTest {
public void testCopyContainerDockerStagingToDockerProd_verifyShellCommand() {
super.testPipeline("tests/jenkins/jobs/DockerCopy_Jenkinsfile")

String gcrane_str = '''\n set +x\n\n if [ null = 'true' ]; then\n echo \"Recursive copy from opensearchstaging/alpine to opensearchproject/alpine\"\n for source_entry in `gcrane ls opensearchstaging/alpine`; do\n image_tag=`echo $source_entry | cut -d/ -f3 | cut -d: -f2`\n destination_entry=\"opensearchproject/alpine:$image_tag\"\n gcrane cp $source_entry $destination_entry\n done\n else\n echo \"Normal copy from opensearchstaging/alpine:3.15.4 to opensearchproject/alpine:3.15.4\"\n gcrane cp opensearchstaging/alpine:3.15.4 opensearchproject/alpine:3.15.4\n fi\n\n docker logout\n docker logout opensearchproject\n '''
String gcrane_str = '''\n set +x\n\n if [ false = true ]; then\n echo \"Copying all image tags recursively from opensearchstaging/alpine to opensearchproject/alpine\"\n for source_entry in `gcrane ls opensearchstaging/alpine`; do\n image_tag=`echo $source_entry | cut -d/ -f3 | cut -d: -f2`\n destination_entry=\"opensearchproject/alpine:$image_tag\"\n gcrane cp $source_entry $destination_entry\n done\n else\n echo \"Copying single image tag from opensearchstaging/alpine:3.15.4 to opensearchproject/alpine:3.15.4\"\n gcrane cp opensearchstaging/alpine:3.15.4 opensearchproject/alpine:3.15.4\n fi\n\n docker logout\n docker logout opensearchproject\n '''
assertThat(getShellCommands('sh', 'gcrane'), hasItem(gcrane_str))
}

@Test
public void testCopyContainerDockerStagingToDockerProdRecursive_verifyShellCommand() {
super.testPipeline("tests/jenkins/jobs/DockerCopyRecursive_Jenkinsfile")

String gcrane_recursive_str = '''\n set +x\n\n if [ true = 'true' ]; then\n echo \"Recursive copy from opensearchstaging/alpine to opensearchproject/alpine\"\n for source_entry in `gcrane ls opensearchstaging/alpine`; do\n image_tag=`echo $source_entry | cut -d/ -f3 | cut -d: -f2`\n destination_entry=\"opensearchproject/alpine:$image_tag\"\n gcrane cp $source_entry $destination_entry\n done\n else\n echo \"Normal copy from opensearchstaging/alpine:3.15.4 to opensearchproject/alpine:3.15.4\"\n gcrane cp opensearchstaging/alpine:3.15.4 opensearchproject/alpine:3.15.4\n fi\n\n docker logout\n docker logout opensearchproject\n '''
String gcrane_recursive_str = '''\n set +x\n\n if [ true = true ]; then\n echo \"Copying all image tags recursively from opensearchstaging/alpine to opensearchproject/alpine\"\n for source_entry in `gcrane ls opensearchstaging/alpine`; do\n image_tag=`echo $source_entry | cut -d/ -f3 | cut -d: -f2`\n destination_entry=\"opensearchproject/alpine:$image_tag\"\n gcrane cp $source_entry $destination_entry\n done\n else\n echo \"Copying single image tag from opensearchstaging/alpine:3.15.4 to opensearchproject/alpine:3.15.4\"\n gcrane cp opensearchstaging/alpine:3.15.4 opensearchproject/alpine:3.15.4\n fi\n\n docker logout\n docker logout opensearchproject\n '''

assertThat(getShellCommands('sh', 'gcrane'), hasItem(gcrane_recursive_str))
}
Expand Down
6 changes: 3 additions & 3 deletions tests/jenkins/jobs/DockerCopyRecursive_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
copyContainer.sh(
set +x

if [ true = 'true' ]; then
echo "Recursive copy from opensearchstaging/alpine to opensearchproject/alpine"
if [ true = true ]; then
echo "Copying all image tags recursively from opensearchstaging/alpine to opensearchproject/alpine"
for source_entry in `gcrane ls opensearchstaging/alpine`; do
image_tag=`echo $source_entry | cut -d/ -f3 | cut -d: -f2`
destination_entry="opensearchproject/alpine:$image_tag"
gcrane cp $source_entry $destination_entry
done
else
echo "Normal copy from opensearchstaging/alpine:3.15.4 to opensearchproject/alpine:3.15.4"
echo "Copying single image tag from opensearchstaging/alpine:3.15.4 to opensearchproject/alpine:3.15.4"
gcrane cp opensearchstaging/alpine:3.15.4 opensearchproject/alpine:3.15.4
fi

Expand Down
6 changes: 3 additions & 3 deletions tests/jenkins/jobs/DockerCopy_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
copyContainer.sh(
set +x

if [ null = 'true' ]; then
echo "Recursive copy from opensearchstaging/alpine to opensearchproject/alpine"
if [ false = true ]; then
echo "Copying all image tags recursively from opensearchstaging/alpine to opensearchproject/alpine"
for source_entry in `gcrane ls opensearchstaging/alpine`; do
image_tag=`echo $source_entry | cut -d/ -f3 | cut -d: -f2`
destination_entry="opensearchproject/alpine:$image_tag"
gcrane cp $source_entry $destination_entry
done
else
echo "Normal copy from opensearchstaging/alpine:3.15.4 to opensearchproject/alpine:3.15.4"
echo "Copying single image tag from opensearchstaging/alpine:3.15.4 to opensearchproject/alpine:3.15.4"
gcrane cp opensearchstaging/alpine:3.15.4 opensearchproject/alpine:3.15.4
fi

Expand Down
8 changes: 4 additions & 4 deletions vars/copyContainer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
void call(Map args = [:]) {

recursive_copy = args.recursiveCopy
recursive_copy = args.recursiveCopy ?: false
source_image = args.sourceImage
source_image_no_tag = source_image.split(':')[0]
source_registry = args.sourceRegistry
Expand Down Expand Up @@ -57,15 +57,15 @@ def gcraneCopy() {
sh """
set +x
if [ ${recursive_copy} = 'true' ]; then
echo "Recursive copy from ${source_registry}/${source_image_no_tag} to ${destination_registry}/${destination_image_no_tag}"
if [ ${recursive_copy} = true ]; then
echo "Copying all image tags recursively from ${source_registry}/${source_image_no_tag} to ${destination_registry}/${destination_image_no_tag}"
for source_entry in `gcrane ls ${source_registry}/${source_image_no_tag}`; do
image_tag=`echo \$source_entry | cut -d/ -f3 | cut -d: -f2`
destination_entry="${destination_registry}/${destination_image_no_tag}:\$image_tag"
gcrane cp \$source_entry \$destination_entry
done
else
echo "Normal copy from ${source_registry}/${source_image} to ${destination_registry}/${destination_image}"
echo "Copying single image tag from ${source_registry}/${source_image} to ${destination_registry}/${destination_image}"
gcrane cp ${source_registry}/${source_image} ${destination_registry}/${destination_image}
fi
Expand Down

0 comments on commit f724938

Please sign in to comment.