Skip to content

Commit

Permalink
Tweak test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon committed Sep 20, 2023
1 parent 85070bf commit cd5b810
Show file tree
Hide file tree
Showing 7 changed files with 2,430 additions and 2,872 deletions.
2 changes: 1 addition & 1 deletion tests/data/opensearch-1.3.0-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build:
platform: linux
architecture: x64
id: c3ff7a232d25403fa8cc14c97799c323
id: 29
name: OpenSearch
version: 1.3.0
distribution: tar
Expand Down
5,232 changes: 2,382 additions & 2,850 deletions tests/data/tar/builds/opensearch/manifest.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/jenkins/TestUploadMinSnapshotsToS3.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class TestUploadMinSnapshotsToS3 extends BuildPipelineTest {
@Before
void setUp() {
List <Closure> fileActions = ['createSha512Checksums']
this.registerLibTester(new UploadMinSnapshotsToS3LibTester( fileActions, 'tests/data/opensearch-1.3.0-build.yml' ))
this.registerLibTester(new UploadMinSnapshotsToS3LibTester( fileActions, 'tests/data/opensearch-1.3.0.yml', 'tar' ))
super.setUp()
}

@Test
public void test() {
super.testPipeline("tests/jenkins/jobs/uploadMinSnapshotsToS3_Jenkinsfile")
}
}
}
4 changes: 2 additions & 2 deletions tests/jenkins/jobs/uploadMinSnapshotsToS3_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ pipeline {
script {
uploadMinSnapshotsToS3(
fileActions: [createSha512Checksums()],
manifest: 'tests/data/opensearch-1.3.0-build.yml',
manifest: 'tests/data/opensearch-1.3.0.yml',
distribution: 'tar'
)
}
}
}
}
}
}
38 changes: 25 additions & 13 deletions tests/jenkins/jobs/uploadMinSnapshotsToS3_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,42 @@
uploadMinSnapshotsToS3_Jenkinsfile.stage(uploadMinSnapshotsToS3, groovy.lang.Closure)
uploadMinSnapshotsToS3_Jenkinsfile.script(groovy.lang.Closure)
uploadMinSnapshotsToS3_Jenkinsfile.createSha512Checksums()
uploadMinSnapshotsToS3_Jenkinsfile.uploadMinSnapshotsToS3({fileActions=[groovy.lang.Closure], manifest=tests/data/opensearch-1.3.0-build.yml, distribution=tar})
uploadMinSnapshotsToS3_Jenkinsfile.uploadMinSnapshotsToS3({fileActions=[groovy.lang.Closure], manifest=tests/data/opensearch-1.3.0.yml, distribution=tar})
uploadMinSnapshotsToS3.legacySCM(groovy.lang.Closure)
uploadMinSnapshotsToS3.library({identifier=jenkins@main, retriever=null})
uploadMinSnapshotsToS3.readYaml({file=tests/data/opensearch-1.3.0-build.yml})
uploadMinSnapshotsToS3.readYaml({file=tests/data/opensearch-1.3.0.yml})
InputManifest.asBoolean()
uploadMinSnapshotsToS3.echo(Retreving build manifest from: tests/data/tar/builds/opensearch/manifest.yml)
uploadMinSnapshotsToS3.readYaml({file=tests/data/tar/builds/opensearch/manifest.yml})
BuildManifest.asBoolean()
uploadMinSnapshotsToS3.echo(Create .sha512 for Min Snapshots Artifacts)
createSha512Checksums.sh({script=find tests/data/null/builds/opensearch/dist -type f, returnStdout=true})
createSha512Checksums.echo(Not generating sha for bbb in tests/data/null/builds/opensearch/dist, doesn't match allowed types [.tar.gz, .zip, .rpm, .deb])
createSha512Checksums.echo(Not generating sha for ccc in tests/data/null/builds/opensearch/dist, doesn't match allowed types [.tar.gz, .zip, .rpm, .deb])
uploadMinSnapshotsToS3.echo(Start copying files: ver-1.2.2-SNAPSHOT arch-x64 plat-linux build-29 dist-null ext-tar.gz)
createSha512Checksums.sh({script=find tests/data/tar/builds/opensearch/dist -type f, returnStdout=true})
createSha512Checksums.echo(Creating sha for opensearch-min-1.3.0-linux-x64.tar.gz)
createSha512Checksums.sh({script=sha512sum opensearch-min-1.3.0-linux-x64.tar.gz, returnStdout=true})
createSha512Checksums.sh({script=basename ccc, returnStdout=true})
createSha512Checksums.writeFile({file=opensearch-min-1.3.0-linux-x64.tar.gz.sha512, text=bbb
bbb
ccc
})
createSha512Checksums.echo(Creating sha for opensearch-dashboards-min-1.3.0-linux-x64.tar.gz)
createSha512Checksums.sh({script=sha512sum opensearch-dashboards-min-1.3.0-linux-x64.tar.gz, returnStdout=true})
createSha512Checksums.sh({script=basename ccc, returnStdout=true})
createSha512Checksums.writeFile({file=opensearch-dashboards-min-1.3.0-linux-x64.tar.gz.sha512, text=bbb
bbb
ccc
})
uploadMinSnapshotsToS3.echo(Start copying files: ver-1.3.0 arch-x64 plat-linux build-29 dist-tar ext-tar.gz)
uploadMinSnapshotsToS3.sh(
cp -v tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64.tar.gz tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz
cp -v tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64.tar.gz.sha512 tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512
cp -v tests/data/null/builds/opensearch/dist/../manifest.yml tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.build-manifest.yml
sed -i "s/.tar.gz/-latest.tar.gz/g" tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512
cp -v tests/data/tar/builds/opensearch/dist/opensearch-min-1.3.0-linux-x64.tar.gz tests/data/tar/builds/opensearch/dist/opensearch-min-1.3.0-linux-x64-latest.tar.gz
cp -v tests/data/tar/builds/opensearch/dist/opensearch-min-1.3.0-linux-x64.tar.gz.sha512 tests/data/tar/builds/opensearch/dist/opensearch-min-1.3.0-linux-x64-latest.tar.gz.sha512
cp -v tests/data/tar/builds/opensearch/dist/../manifest.yml tests/data/tar/builds/opensearch/dist/opensearch-min-1.3.0-linux-x64-latest.tar.gz.build-manifest.yml
sed -i "s/.tar.gz/-latest.tar.gz/g" tests/data/tar/builds/opensearch/dist/opensearch-min-1.3.0-linux-x64-latest.tar.gz.sha512
)
uploadMinSnapshotsToS3.string({credentialsId=jenkins-artifact-promotion-role, variable=ARTIFACT_PROMOTION_ROLE_NAME})
uploadMinSnapshotsToS3.string({credentialsId=jenkins-aws-production-account, variable=AWS_ACCOUNT_ARTIFACT})
uploadMinSnapshotsToS3.string({credentialsId=jenkins-artifact-production-bucket-name, variable=ARTIFACT_PRODUCTION_BUCKET_NAME})
uploadMinSnapshotsToS3.withCredentials([ARTIFACT_PROMOTION_ROLE_NAME, AWS_ACCOUNT_ARTIFACT, ARTIFACT_PRODUCTION_BUCKET_NAME], groovy.lang.Closure)
uploadMinSnapshotsToS3.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadMinSnapshotsToS3.s3Upload({file=tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.2.2-SNAPSHOT/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz})
uploadMinSnapshotsToS3.s3Upload({file=tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.2.2-SNAPSHOT/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512})
uploadMinSnapshotsToS3.s3Upload({file=tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.build-manifest.yml, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.2.2-SNAPSHOT/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.build-manifest.yml})
uploadMinSnapshotsToS3.s3Upload({file=tests/data/tar/builds/opensearch/dist/opensearch-min-1.3.0-linux-x64-latest.tar.gz, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.3.0/opensearch-min-1.3.0-linux-x64-latest.tar.gz})
uploadMinSnapshotsToS3.s3Upload({file=tests/data/tar/builds/opensearch/dist/opensearch-min-1.3.0-linux-x64-latest.tar.gz.sha512, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.3.0/opensearch-min-1.3.0-linux-x64-latest.tar.gz.sha512})
uploadMinSnapshotsToS3.s3Upload({file=tests/data/tar/builds/opensearch/dist/opensearch-min-1.3.0-linux-x64-latest.tar.gz.build-manifest.yml, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.3.0/opensearch-min-1.3.0-linux-x64-latest.tar.gz.build-manifest.yml})
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@ class UploadMinSnapshotsToS3LibTester extends LibFunctionTester {

private List<Closure> fileActions
private String manifest
private String distribution

public UploadMinSnapshotsToS3LibTester(fileActions, manifest){
public UploadMinSnapshotsToS3LibTester(fileActions, manifest, distribution){
this.fileActions = fileActions
this.manifest = manifest
this.distribution = distribution
}

void parameterInvariantsAssertions(call){
assertThat(call.args.fileActions.first(), notNullValue())
assertThat(call.args.manifest.first(), notNullValue())
assertThat(call.args.distribution.first(), notNullValue())
}

boolean expectedParametersMatcher(call) {
boolean actionMatch = call.args.fileActions.size() == 0
for (actionCall in call.args.fileActions) {
actionMatch = this.fileActions.any( actionThis -> actionCall.toString().contains(actionThis.toString()) )
}
return actionMatch && call.args.manifest.first().toString().equals(this.manifest)
return actionMatch && call.args.manifest.first().toString().equals(this.manifest) && call.args.distribution.first().toString().equals(this.distribution)
}

String libFunctionName(){
Expand Down
15 changes: 13 additions & 2 deletions vars/uploadMinSnapshotsToS3.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,30 @@ void call(Map args = [:]) {
def lib = library(identifier: 'jenkins@main', retriever: legacySCM(scm))
List<Closure> fileActions = args.fileActions ?: []
String manifest = args.manifest ?: "manifests/${INPUT_MANIFEST}"
String distribution_arg = args.distribution ?: 'None'

if (distribution_arg == 'None') {
echo("Missing distribution type")
System.exit(1)
}

def inputManifest = lib.jenkins.InputManifest.new(readYaml(file: manifest))
String productName = inputManifest.build.getFilename()
echo("Retreving build manifest from: $WORKSPACE/${args.distribution}/builds/${productName}/manifest.yml")
echo("Retreving build manifest from: $WORKSPACE/${distribution_arg}/builds/${productName}/manifest.yml")

def buildManifest = lib.jenkins.BuildManifest.new(readYaml(file: "$WORKSPACE/${args.distribution}/builds/${productName}/manifest.yml"))
def buildManifest = lib.jenkins.BuildManifest.new(readYaml(file: "$WORKSPACE/${distribution_arg}/builds/${productName}/manifest.yml"))
String version = buildManifest.build.version
String architecture = buildManifest.build.architecture
String platform = buildManifest.build.platform
String id = buildManifest.build.id
String distribution = buildManifest.build.distribution
String extension = buildManifest.build.getExtension()

if (distribution_arg != distribution) {
echo("User enters $distribution_arg does not match build manifest $distribution")
System.exit(1)
}

// Setup src & dst variables for artifacts
// Replace backslash with forward slash ('\' to '/') in path
// Compatible with both Windows as well as any nix* env
Expand Down

0 comments on commit cd5b810

Please sign in to comment.