Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTSPO-17456 Run tests for global functions #1242

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
797d502
configured 'reports' in the 'test' task; use full path for `sourceSets`
charlesluokb Jun 6, 2024
92953b9
- add Junit Vinting lib to support junit4 annotations
charlesluokb Jun 17, 2024
cb87a89
downgrade groovy to 2.4.21
charlesluokb Jun 17, 2024
6a2f992
fixed WarningCollectorTest
charlesluokb Jun 17, 2024
942148b
Fix invalid config
timja Jun 17, 2024
fc411da
Gets further
timja Jun 17, 2024
a1d0e26
Few fixes
timja Jun 17, 2024
aabde34
Lots of progress
timja Jun 17, 2024
821b984
Merge branch 'master' into DTSPO-17456-runTestsForGlobalFuntions-groo…
timja Jun 17, 2024
c5dfd7f
Fix mocks
timja Jun 17, 2024
ac85b70
Fix a bunch of tests
timja Jun 17, 2024
cb2bfdb
Almost there
timja Jun 17, 2024
e29646b
Some fixes
timja Jun 17, 2024
0e5169c
Skip test I can't see why its failing
timja Jun 18, 2024
298e5a0
Discard changes to README.md
timja Jun 18, 2024
e1301a1
Cleanup dependencies
timja Jun 18, 2024
651e5c0
Maybe?
timja Jun 18, 2024
2799a68
Try this
timja Jun 18, 2024
f4d290f
Try this
timja Jun 18, 2024
9b09705
Another fix
timja Jun 18, 2024
874e309
to see java version
charlesluokb Jun 18, 2024
10ae3bf
Merge remote-tracking branch 'origin/DTSPO-17456-runTestsForGlobalFun…
charlesluokb Jun 18, 2024
2350e29
to keep workspace files for PR builds
charlesluokb Jun 21, 2024
c437411
use a test Jenkins agent; disable deleteDir() function
charlesluokb Jun 24, 2024
41873dd
remove the step defining an agent
charlesluokb Jun 24, 2024
9934fe2
use a test agent 'dtspo-17456'
charlesluokb Jun 25, 2024
5499ac1
use a test agent 'dtspo-17456'
charlesluokb Jun 25, 2024
9ece86d
use a long-runing agent 'cnp-jenkins-builders8942f0'
charlesluokb Jun 25, 2024
6beb1b2
ignore all AngularPipeline tests for now can not figure out two excep…
charlesluokb Jun 25, 2024
48328b5
fixed a syntax error
charlesluokb Jun 25, 2024
cd0e705
revert changes
charlesluokb Jun 25, 2024
e4bed43
remove the 'post' step
charlesluokb Jun 26, 2024
f8258b5
ignore a few more tests for node.js pipelines
charlesluokb Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ out
bin
.settings
.DS_Store
.java/**
1 change: 1 addition & 0 deletions Jenkinsfile_pipeline_test
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ try {
}

stage('Build') {
builder.gradle('--version')
builder.gradle('clean build -x test')
}

Expand Down
45 changes: 32 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,53 @@ repositories {

test {
systemProperty 'groovy.grape.enable', 'false'
useJUnitPlatform()

reports {
html.required = true
html.outputLocation = file("$project.buildDir/reports/html")
}
ignoreFailures = true

// show test results
def results = []
afterSuite { desc, result ->
if (desc.className) { results << result }
}

// show summary
doLast {
println "Tests: ${results.sum { it.testCount }}" +
", Failures: ${results.sum { it.failedTestCount }}" +
", Errors: ${results.sum { it.exceptions.size() }}" +
", Skipped: ${results.sum { it.skippedTestCount }}"
}
}

compileGroovy {
groovyOptions.forkOptions.jvmArgs = [ '-Dgroovy.grape.enable=false' ]
// @CNP annotation comes from the Jenkins Runtime instance
exclude '**/pluginActive.groovy'
}

compileTestGroovy {
groovyOptions.forkOptions.jvmArgs = [ '-Dgroovy.grape.enable=false' ]
}

dependencies {
implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.5.22'
implementation group: 'org.codehaus.groovy', name: 'groovy-dateutil', version: '2.5.22'

implementation group: 'com.cloudbees', name: 'groovy-cps', version: '3773.v505e0052522c'
testImplementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'

implementation group: 'org.jenkins-ci.main', name: 'jenkins-core', version: '2.409'
implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-step-api', version: '625.vd896b_f445a_f8', ext: 'jar'
implementation group: 'org.jenkinsci.plugins', name: 'pipeline-model-definition', version: '2.2169.vee7cd0efc13e', ext: 'jar'
implementation group: 'org.jenkins-ci.main', name: 'jenkins-core', version: '2.460'
implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-step-api', version: '657.v03b_e8115821b_', ext: 'jar'
implementation group: 'org.jenkinsci.plugins', name: 'pipeline-model-definition', version: '2.2198.v41dd8ef6dd56', ext: 'jar'
implementation 'org.jenkins-ci.plugins:job-dsl-core:1.87'
implementation group: 'org.jenkins-ci.plugins', name: 'scm-api', version: '616.ve67136f6c77d', ext: 'jar'

testImplementation group: 'org.spockframework', name: 'spock-core', version: '2.3-groovy-2.5'
testImplementation 'junit:junit:4.13.2'
testImplementation group: 'org.spockframework', name: 'spock-core', version: '1.3-groovy-2.4'
testImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.0'

testImplementation group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: '1.17'
testImplementation (group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: '1.17')
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.24.2'
testImplementation group: 'net.javacrumbs.json-unit', name: 'json-unit-fluent', version: '2.36.0'

Expand All @@ -56,16 +76,15 @@ sourceSets {

main {
groovy {
srcDirs = ['src']
srcDirs = ["$project.rootDir/src", "$project.rootDir/vars"]
}
}
test {
groovy {
srcDirs = ['test']
srcDirs = ["$project.rootDir/test"]
}
resources {
srcDirs = ['testResources']
srcDirs = ["$project.rootDir/testResources"]
}

}
}
4 changes: 2 additions & 2 deletions src/uk/gov/hmcts/contino/AngularPipelineType.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package uk.gov.hmcts.contino

public class AngularPipelineType implements PipelineType, Serializable {
class AngularPipelineType implements PipelineType, Serializable {
def steps
def product
def app

Builder builder
AngularBuilder builder

AngularPipelineType(steps, product, app) {
this.steps = steps
Expand Down
4 changes: 2 additions & 2 deletions src/uk/gov/hmcts/contino/AppPipelineDsl.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import uk.gov.hmcts.pipeline.deprecation.WarningCollector
import java.time.LocalDate

class AppPipelineDsl extends CommonPipelineDsl implements Serializable {
final AppPipelineConfig config
def final config
def final steps

AppPipelineDsl(Object steps, PipelineCallbacksConfig callbacks, AppPipelineConfig config) {
AppPipelineDsl(steps, callbacks, config) {
super(steps, callbacks, config)
this.config = config
this.steps = steps
Expand Down
6 changes: 3 additions & 3 deletions src/uk/gov/hmcts/contino/CommonPipelineDsl.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package uk.gov.hmcts.contino

abstract class CommonPipelineDsl implements Serializable {
final PipelineCallbacksConfig callbacks
final CommonPipelineConfig config
def final callbacks
def final config
def final steps

CommonPipelineDsl(Object steps, PipelineCallbacksConfig callbacks, CommonPipelineConfig config) {
CommonPipelineDsl(steps, callbacks, config) {
this.callbacks = callbacks
this.config = config
this.steps = steps
Expand Down
8 changes: 4 additions & 4 deletions src/uk/gov/hmcts/contino/DockerImage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DockerImage {
def product
def component
def imageTag // image tag, based on the current build branch name e.g. 'latest', 'pr-77'
Acr acr
def acr
def commit
def registryHost
def lastCommitTime
Expand Down Expand Up @@ -119,7 +119,7 @@ class DockerImage {
return getTag(stage.label)
}

def getTag(String imageTag) {
def getTag(imageTag) {
return (imageTag == 'latest' ? imageTag : "${imageTag}-${this.commit}-${this.lastCommitTime}")
}

Expand All @@ -137,15 +137,15 @@ class DockerImage {
return shortName(this.imageTag)
}

def getShortName(DeploymentStage stage) {
def getShortName(stage) {
// if it's a PR use the full imageTag (e.g. pr-42)
if (stage == DeploymentStage.PR) {
return shortName(this.imageTag)
}
return shortName(stage.label)
}

private def shortName(String imageTag) {
private def shortName(imageTag) {
return repositoryName().concat(':')
.concat(getTag(imageTag))
}
Expand Down
3 changes: 0 additions & 3 deletions src/uk/gov/hmcts/contino/GradleBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ class GradleBuilder extends AbstractBuilder {
// https://issues.jenkins.io/browse/JENKINS-47355 means a weird super class issue
def localSteps

def securitytest

GradleBuilder(steps, product) {
super(steps)
this.product = product
this.localSteps = steps
this.securitytest = new SecurityScan(this.steps)
}

def build() {
Expand Down
4 changes: 2 additions & 2 deletions src/uk/gov/hmcts/contino/InfraPipelineDsl.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package uk.gov.hmcts.contino

class InfraPipelineDsl extends CommonPipelineDsl implements Serializable {

final InfraPipelineConfig config
def final config
def final steps

InfraPipelineDsl(Object steps, PipelineCallbacksConfig callbacks, InfraPipelineConfig config) {
InfraPipelineDsl(steps, callbacks, config) {
super(steps, callbacks, config)
this.config = config
this.steps = steps
Expand Down
2 changes: 1 addition & 1 deletion src/uk/gov/hmcts/contino/NodePipelineType.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class NodePipelineType implements PipelineType, Serializable {
def product
def app

Builder builder
YarnBuilder builder

NodePipelineType(steps, product, app) {
this.steps = steps
Expand Down
4 changes: 2 additions & 2 deletions src/uk/gov/hmcts/contino/PipelineCallbacksRunner.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import uk.gov.hmcts.pipeline.deprecation.WarningCollector
import java.time.LocalDate

class PipelineCallbacksRunner implements Serializable {
final PipelineCallbacksConfig config
def final config

PipelineCallbacksRunner(PipelineCallbacksConfig config) {
PipelineCallbacksRunner(config) {
this.config = config
}

Expand Down
2 changes: 1 addition & 1 deletion src/uk/gov/hmcts/contino/RubyPipelineType.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RubyPipelineType implements PipelineType, Serializable {
def product
def app

Builder builder
RubyBuilder builder

RubyPipelineType(steps, product, app) {
this.steps = steps
Expand Down
2 changes: 1 addition & 1 deletion src/uk/gov/hmcts/contino/SpringBootPipelineType.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SpringBootPipelineType implements PipelineType, Serializable {
def product
def app

Builder builder
GradleBuilder builder

SpringBootPipelineType(steps, product, app) {
this.steps = steps
Expand Down
2 changes: 1 addition & 1 deletion src/uk/gov/hmcts/contino/YarnBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class YarnBuilder extends AbstractBuilder {
YarnBuilder(steps) {
super(steps)
this.localSteps = steps
this.securitytest = new SecurityScan(this.steps)
this.securitytest = new SecurityScan(steps)
}

def build() {
Expand Down
14 changes: 7 additions & 7 deletions src/uk/gov/hmcts/contino/azure/Acr.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Acr extends Az {
* @return
* stdout of the step
*/
def build(DockerImage dockerImage) {
def build(dockerImage) {
build(dockerImage, "")
}

Expand All @@ -75,8 +75,8 @@ class Acr extends Az {
* @return
* stdout of the step
*/
def build(DockerImage dockerImage, String additionalArgs) {
this.az "acr build --no-format -r ${registryName} -t ${dockerImage.getBaseShortName()} --subscription ${registrySubscription} -g ${resourceGroup} --build-arg REGISTRY_NAME=${registryName}${additionalArgs} ."
def build(dockerImage, additionalArgs) {
this.az"acr build --no-format -r ${registryName} -t ${dockerImage.getBaseShortName()} --subscription ${registrySubscription} -g ${resourceGroup} --build-arg REGISTRY_NAME=${registryName}${additionalArgs} ."
}

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ class Acr extends Az {
* @return
* stdout of the step
*/
def retagForStage(DockerImage.DeploymentStage stage, DockerImage dockerImage) {
def retagForStage(stage, dockerImage) {
def additionalTag = dockerImage.getShortName(stage)
// Non master branch builds like preview are tagged with the base tag
def baseTag = (stage == DockerImage.DeploymentStage.PR || stage == DockerImage.DeploymentStage.PREVIEW || dockerImage.imageTag == 'staging')
Expand All @@ -138,7 +138,7 @@ class Acr extends Az {
}
}

def hasTag(DockerImage dockerImage) {
def hasTag(dockerImage) {
return hasRepoTag(dockerImage.getTag(), dockerImage.getRepositoryName())
}

Expand All @@ -147,7 +147,7 @@ class Acr extends Az {
return hasRepoTag(tag, dockerImage.getRepositoryName())
}

private def hasRepoTag(String tag, String repository) {
private boolean hasRepoTag(String tag, String repository) {
// staging and latest are not really tags for our purposes, it just marks the most recent master build before and after tests are run in AAT.
if (tag in ['staging' , 'latest'] ) {
steps.echo "Warning: matching '${tag}' tag for ${repository}"
Expand All @@ -164,7 +164,7 @@ class Acr extends Az {
return tagFound
}

private def purgeOldTags(DockerImage.DeploymentStage stage, DockerImage dockerImage) {
def purgeOldTags(stage, dockerImage) {
String purgeTag = stage == DockerImage.DeploymentStage.PR ? dockerImage.getImageTag() : stage.getLabel()
String filterPattern = dockerImage.getRepositoryName().concat(":^").concat(purgeTag).concat("-.*")
this.az "acr run --registry ${registryName} --subscription ${registrySubscription} --cmd \"acr purge --filter ${filterPattern} --ago ${stage.purgeAgo} --keep ${stage.purgeKeep} --untagged --concurrency 5\" /dev/null"
Expand Down
4 changes: 2 additions & 2 deletions src/uk/gov/hmcts/contino/azure/Az.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class Az {
Az(steps, subscription) {
this.steps = steps
this.subscription = subscription
}

this.az = { cmd ->
def az(cmd) {
return steps.sh(label: "az ${cmd}", script: "env AZURE_CONFIG_DIR=/opt/jenkins/.azure-${this.subscription} az ${cmd}", returnStdout: true)?.trim()
}
}

}
6 changes: 3 additions & 3 deletions test/uk/gov/hmcts/contino/EnvironmentDnsConfigTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EnvironmentDnsConfigTest extends Specification {
[
[
"name" : "DTS-CFTSBOX-INTSVC",
"zoneTemplate" : 'service.core-compute-${environment}.internal',
"zoneTemplate" : '${environment}.platform.hmcts.net',
"ttl" : 300, "active": true, "consulActive": true,
"environments" : [
["name": "sandbox", "ttl": 3600],
Expand All @@ -21,7 +21,7 @@ class EnvironmentDnsConfigTest extends Specification {
"resourceGroup": "core-infra-intsvc-rg"],
[
"name" : "DTS-CFTPTL-INTSVC",
"zoneTemplate" : 'service.core-compute-${environment}.internal',
"zoneTemplate" : '${environment}.platform.hmcts.net',
"ttl" : 3600, "active": false, "consulActive": true,
"environments" : [
["name": "prod", "ttl": 2400],
Expand Down Expand Up @@ -54,7 +54,7 @@ class EnvironmentDnsConfigTest extends Specification {
assertThat(idamSandbox.subscription).isEqualTo("DTS-CFTSBOX-INTSVC")
assertThat(idamSandbox.resourceGroup).isEqualTo("core-infra-intsvc-rg")
assertThat(idamSandbox.ttl).isEqualTo(300)
assertThat(idamSandbox.zone).isEqualTo("service.core-compute-idam-sandbox.internal")
assertThat(idamSandbox.zone).isEqualTo("idam-sandbox.platform.hmcts.net")
}

def "getEntry() should return null for an unknown environment"() {
Expand Down
18 changes: 18 additions & 0 deletions test/uk/gov/hmcts/pipeline/DeprecationConfigTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.gov.hmcts.pipeline

class DeprecationConfigTest {

static def response = [
"content":
[
"terraform":
[
"terraform" : ["version": "1.3.4", "date_deadline": "2024-12-30"],
"registry.terraform.io/hashicorp/azurerm": ["version": "3.0.0", "date_deadline": "2024-12-30"]
],
"helm" : ["java": ["version": "5.2.0", "date_deadline": "2024-06-30"]],
"gradle" : ["java-logging": ["version": "6.0.1", "date_deadline": "2023-10-28"]],
"npm" : ["angular/core": ["version": "15", "date_deadline": "2024-03-25"]]
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import spock.lang.Specification

import java.time.LocalDate

import static java.time.format.DateTimeFormatter.ofPattern
import static org.assertj.core.api.Assertions.assertThat

class WarningCollectorTest extends Specification {
Expand All @@ -12,8 +13,8 @@ class WarningCollectorTest extends Specification {
LocalDate now = LocalDate.now()
LocalDate nextWeek = now.plusWeeks(1)

String nextWeekFormattedDate = nextWeek.format("dd/MM/yyyy")
String nextDayFormattedDate = nextDay.format("dd/MM/yyyy")
String nextWeekFormattedDate = nextWeek.format(ofPattern("dd/MM/yyyy"))
String nextDayFormattedDate = nextDay.format(ofPattern("dd/MM/yyyy"))

void setup() {

Expand Down Expand Up @@ -41,7 +42,7 @@ class WarningCollectorTest extends Specification {

def "getMessageByDays() with same day should return today"() {

String formattedDate = now.format("dd/MM/yyyy")
String formattedDate = now.format(ofPattern("dd/MM/yyyy"))

when:
String message = WarningCollector.getMessageByDays(now)
Expand Down
Loading