Skip to content

Commit

Permalink
Data Prepper Unit Test & Test Refactoring (#1451)
Browse files Browse the repository at this point in the history
* Added a unit test for the Data Prepper build.

Signed-off-by: David Venable <[email protected]>
  • Loading branch information
dlvenable authored Jan 12, 2022
1 parent d0ac211 commit f769760
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 8 deletions.
25 changes: 25 additions & 0 deletions tests/jenkins/BaseJobPipelineTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package jenkins.tests

import jenkins.tests.CommonPipelineTest
import org.junit.Before

/**
* Base class for testing jobs which do not need the implementation
* details of the Jenkins library exposed.
*/
abstract class BaseJobPipelineTest extends CommonPipelineTest {
@Override
@Before
void setUp() {
super.setUp()

binding.setVariable('scm', {})
helper.registerAllowedMethod('legacySCM', [Closure.class], null)
helper.registerAllowedMethod("library", [Map.class], {})
}
}
14 changes: 6 additions & 8 deletions tests/jenkins/BuildPipelineTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import com.lesfurets.jenkins.unit.declarative.*
import static org.junit.Assert.*
import org.yaml.snakeyaml.Yaml

abstract class BuildPipelineTest extends DeclarativePipelineTest {
/**
* Base test class for testing Jenkins library code. This base test
* sets up the project directory as the library and will execute
* library code.
*/
abstract class BuildPipelineTest extends CommonPipelineTest {
@Override
@Before
void setUp() {
Expand Down Expand Up @@ -46,11 +51,4 @@ abstract class BuildPipelineTest extends DeclarativePipelineTest {
return new LibClassLoader(helper, null)
})
}

void testPipeline(String jenkinsScript, String regressionFilename = null) {
runScript(jenkinsScript)
RegressionTestHelper.testNonRegression(helper, regressionFilename ?: jenkinsScript)
assertJobStatusSuccess()
printCallStack()
}
}
31 changes: 31 additions & 0 deletions tests/jenkins/CommonPipelineTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package jenkins.tests

import com.lesfurets.jenkins.unit.RegressionTestHelper
import com.lesfurets.jenkins.unit.declarative.DeclarativePipelineTest
import org.junit.Before


/**
* This base test class holds common functions, but does not perform
* any additional setup. Test authors can extend from this class if
* they don't need common setup. Otherwise, please see the sub-classes.
*/
abstract class CommonPipelineTest extends DeclarativePipelineTest {
@Override
@Before
void setUp() {
super.setUp()
}

void testPipeline(String jenkinsScript, String regressionFilename = null) {
runScript(jenkinsScript)
RegressionTestHelper.testNonRegression(helper, regressionFilename ?: jenkinsScript)
assertJobStatusSuccess()
printCallStack()
}
}
37 changes: 37 additions & 0 deletions tests/jenkins/TestDataPrepperDistributionArtifacts.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import jenkins.tests.BaseJobPipelineTest
import org.junit.Before
import org.junit.Test

class TestDataPrepperDistributionArtifacts extends BaseJobPipelineTest {

@Before
void setUp() {
super.setUp()

binding.setVariable('VERSION', '0.22.1')
binding.setVariable('BRANCH', 'refs/tags/0.22.1')

binding.setVariable('JOB_BASE_NAME', 'data-prepper-distribution-artifacts')
binding.setVariable('BUILD_NUMBER', '7654321')
binding.setVariable('WORKSPACE', '/tmp/workspace')

binding.setVariable('ARTIFACT_BUCKET_NAME', 'job-s3-bucket-name')

helper.registerAllowedMethod('checkout', [Map], {})
helper.registerAllowedMethod('signArtifacts', [Map], {})
helper.registerAllowedMethod('uploadToS3', [Map], {})
helper.registerAllowedMethod('printArtifactDownloadUrlsForStaging', [Map], {})
helper.registerAllowedMethod('postCleanup', [], {})
}

@Test
void dataPrepperDistributionArtifacts_builds_consistently() {
testPipeline('jenkins/data-prepper/distribution-artifacts.jenkinsfile',
'tests/jenkins/jobs/data-prepper/distribution-artifacts.jenkinsfile')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
distribution-artifacts.run()
distribution-artifacts.legacySCM(groovy.lang.Closure)
distribution-artifacts.library({identifier=jenkins@20211123, retriever=null})
distribution-artifacts.pipeline(groovy.lang.Closure)
distribution-artifacts.echo(Executing on agent [docker:[image:opensearchstaging/ci-runner:ci-runner-centos7-v1, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:Jenkins-Agent-al2-x64-c54xlarge-Docker-Host]])
distribution-artifacts.stage(Build Data Prepper, groovy.lang.Closure)
distribution-artifacts.script(groovy.lang.Closure)
distribution-artifacts.checkout({changelog=false, poll=false, scm={$class=GitSCM, branches=[{name=refs/tags/0.22.1}], userRemoteConfigs=[{url=https://github.com/opensearch-project/data-prepper.git}]}})
distribution-artifacts.sh(./gradlew clean :release:archives:linux:linuxTar -Prelease)
distribution-artifacts.sh({script=find /tmp/workspace/release/archives/linux/build/distributions | sed -n "s|^/tmp/workspace/release/archives/linux/build/distributions/||p", returnStdout=true})
distribution-artifacts.stage(Sign Artifacts, groovy.lang.Closure)
distribution-artifacts.script(groovy.lang.Closure)
distribution-artifacts.signArtifacts({artifactPath=/tmp/workspace/release/archives/linux/build/distributions, signatureType=.sig, distributionPlatform=linux})
distribution-artifacts.stage(Upload Artifacts to Staging Distribution Bucket, groovy.lang.Closure)
distribution-artifacts.script(groovy.lang.Closure)
distribution-artifacts.uploadToS3({sourcePath=/tmp/workspace/release/archives/linux/build/distributions, bucket=job-s3-bucket-name, path=data-prepper-distribution-artifacts/0.22.1/7654321/builds/signed})
distribution-artifacts.printArtifactDownloadUrlsForStaging({artifactFileNames=[bbb, bbb.sig, ccc, ccc.sig], uploadPath=data-prepper-distribution-artifacts/0.22.1/7654321/builds/signed})
distribution-artifacts.script(groovy.lang.Closure)
distribution-artifacts.postCleanup()

0 comments on commit f769760

Please sign in to comment.