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

Golden Tests improvements #1302

Draft
wants to merge 73 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
cd0ff7d
Refactor and add new feature to improve automatic tests of the QS
jorge-romero Jun 22, 2023
554c0c5
Change the way we get the token to interact with jenkins
jorge-romero Jun 28, 2023
ff63fc0
Replace ods-env configuration with enviroment variables
jorge-romero Jun 30, 2023
3d08e97
remove dead code
jorge-romero Jun 30, 2023
2fac3b3
Fix linting error
jorge-romero Jul 4, 2023
619b8ce
Improve quickstater-test.sh adding log file processing
jorge-romero Jul 4, 2023
b2d849f
Unify golden files verification
jorge-romero Jul 7, 2023
c6be933
match Shared library to branch used instead of agent tag
BraisVQ Nov 28, 2023
431969d
restore config
BraisVQ Nov 28, 2023
407e7f9
private qs test
May 20, 2024
e2ebc7d
revert
May 23, 2024
03bccdf
private qs test 2
May 27, 2024
95fb2e6
golden test
May 29, 2024
1ebbde7
golden test
May 29, 2024
35a21a4
golden test
May 29, 2024
bf85fa5
golden test
May 29, 2024
d491a3e
golden test
May 29, 2024
0d1f2cd
golden test
May 30, 2024
52162e5
golden test
May 30, 2024
7d93e2a
golden test
May 30, 2024
1b20197
golden test
May 30, 2024
a29151a
golden test
May 30, 2024
04348e2
golden test
May 30, 2024
3f308e0
golden test
May 30, 2024
b2da2ac
golden test
May 30, 2024
b191d09
golden test
May 30, 2024
afbe0da
golden test
May 30, 2024
e7edae0
golden test
May 30, 2024
9588f50
golden test
May 31, 2024
3bb9cd1
golden test
May 31, 2024
77fda33
golden test
May 31, 2024
e178b9b
golden test
May 31, 2024
6d25671
golden test
Jun 4, 2024
93b3b4c
golden test
Jul 3, 2024
6e07b3d
golden test
Jul 3, 2024
b070dd8
golden test
Jul 3, 2024
e5aca74
golden test
Jul 3, 2024
417a4a9
golden test
Jul 4, 2024
36fd3e8
golden test
Jul 4, 2024
156fe72
golden test
Jul 4, 2024
e05bc36
golden test
Jul 4, 2024
c4a2018
golden test
Jul 4, 2024
6902307
golden test
Jul 4, 2024
25ab230
golden test
Jul 4, 2024
d7b2697
golden test
Aug 23, 2024
fa75db4
golden test
Aug 23, 2024
7dbb4e5
golden test
Aug 26, 2024
0fd4aef
remove commented code
Aug 26, 2024
71b2175
fix parameters
Aug 26, 2024
f3c6740
update go version to 1.22
Aug 26, 2024
8164355
golden test
Sep 2, 2024
e03a0df
golden test
Sep 2, 2024
faf2a33
revert go version
Sep 2, 2024
826a930
golden test
Sep 2, 2024
ae22888
golden test
Sep 2, 2024
14c3c6d
golden test
Sep 2, 2024
39f4fdc
update golang to 1.23 and tidy packages
BraisVQ Sep 2, 2024
d114605
golden test
Sep 2, 2024
d65fc86
golden test
Sep 2, 2024
9649326
golden test
Sep 2, 2024
440dbc5
golden test
Sep 3, 2024
a650ff6
Merge branch 'master' into feature/quickstarter-golden-test
BraisVQ Sep 9, 2024
189ba87
update github actions to go 1.23
BraisVQ Sep 16, 2024
1c415a5
fix format
BraisVQ Sep 16, 2024
f035678
changelog
BraisVQ Sep 16, 2024
fadbefd
format golang files
BraisVQ Sep 16, 2024
3d7ae16
go mod tidy
BraisVQ Sep 16, 2024
b7dd84e
Jenkins Pipeline creation in makefile
BraisVQ Sep 25, 2024
51575f0
Fix git url
BraisVQ Sep 25, 2024
9293c24
fix test jenkisfile location
BraisVQ Sep 25, 2024
45bd474
fix git url
BraisVQ Sep 25, 2024
71fd5d7
use cd-user-with-password
BraisVQ Sep 25, 2024
28623c2
add configurationRef parameter
BraisVQ Sep 25, 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
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ jobs:
name: Checkout repository
uses: actions/checkout@v4.1.7
-
name: Setup Go 1.18
name: Setup Go 1.23
uses: actions/setup-go@v5
with:
go-version: 1.18
go-version: 1.23
-
name: Verify all Go files are formatted with gofmt
working-directory: tests
Expand All @@ -186,7 +186,7 @@ jobs:
name: Verify all Go tests pass linting
uses: golangci/golangci-lint-action@v6
with:
version: v1.49.0
version: v1.60.1
working-directory: tests
args: --timeout=10m
-
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Webhook Proxy maintenance ([#1298](https://github.com/opendevstack/ods-core/pull/1298))
- Update SonarQube to 10.x non LTS ([#1300](https://github.com/opendevstack/ods-core/issues/1300))
- Jenkins maintenance ([#1299](https://github.com/opendevstack/ods-core/pull/1299)) and update java version in Jenkins ([#1295](https://github.com/opendevstack/ods-core/issues/1295))
- Update and fix golden tests ([#1233](https://github.com/opendevstack/ods-core/issues/1233))

### Fixed

Expand Down
181 changes: 181 additions & 0 deletions tests/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
properties([
parameters([
string(
name: 'Quickstarter',
description: 'Enter the quickstarter name which is to be tested. Use "all" to test all the quickstarters together'
),
string(
name: 'QuickstarterRepository',
defaultValue: 'ods-quickstarters',
description: 'Enter the repository name for the quickstarter which is to be tested'
),
string(
name: 'quickstarterRef',
defaultValue: '4.x',
description: 'Enter the reference for the quickstarter (e.g., branch, tag, or commit)'
),
string(
name: 'configurationRef',
defaultValue: 'master',
description: 'Enter the reference for the configuration (e.g., branch, tag, or commit)'
),
string(
name: 'Project',
description: 'Enter the project name (in lower case) where the quickstarter will be provisioned'
),
string(
name: 'ODS_NAMESPACE',
defaultValue: 'ods',
description: 'Enter the ods namespae to fetch the jenkins agent. Include "-cd" if the ODS Namespace is not ods as default'
),
string(
name: 'ODS_URL',
defaultValue: 'https://github.com/opendevstack',
description: 'Enter the whole URL of the ODS files (https included)'
),
string(
name: 'JENKINS_AGENT_TAG',
defaultValue: '4.x',
description: 'Enter the tag for the jenkins golang agent'
),
string(
name: 'SONAR_QUALITY_PROFILE',
description: 'Enter the tag for the jenkins golang agent'
),
text(
name: 'excludedQuickstarters',
defaultValue: '''inf-terraform-aws
inf-terraform-azure
ods-document-gen-svc
ods-provisioning-app
release-manager
ds-jupyter-lab
ds-rshiny''',
description: 'Enter the list of excluded quickstarters, one per line'
)
]),
disableConcurrentBuilds(),
buildDiscarder(logRotator(numToKeepStr: '10')),
])

// The project that we will use to test the quickstarters
def project = params.Project
// The Quickstarter to test
def quickstarter = params.Quickstarter
// Namespace fo the cd project
def odsNamespace = params.ODS_NAMESPACE
// odsReference
def odsRef = params.quickstarterRef?:"master"
// configurationReference
def confRef = params.configurationRef?:"master"
// QS repo
def QUICKSTARTER_REPO = params.QuickstarterRepository

// URIS of the repositories used
def QUICK_STARTERS_URL = "${ODS_URL}/${QUICKSTARTER_REPO}.git"
def QUICK_STARTERS_BRANCH = "${quickstarterRef}"

def ODS_CONFIGURATION_URL = "${ODS_URL}/ods-configuration.git"
def ODS_CONFIGURATION_BRANCH = "${confRef}"

def ODS_CORE_URL = "${ODS_URL}/ods-core.git"
def ODS_CORE_BRANCH = "${quickstarterRef}"

def JENKINS_AGENT_TAG = "${JENKINS_AGENT_TAG}"
def SONAR_QUALITY_PROFILE = "${SONAR_QUALITY_PROFILE}"

// List of QS that we want to exclude from the execution of the job.
def excludedQS = params.excludedQuickstarters?:''


echo "QUICKSTARTER_REPO : ${QUICKSTARTER_REPO}"

// Jenkins DeploymentConfig environment variables
def dockerRegistry
node {
dockerRegistry = env.DOCKER_REGISTRY
}

// We need a golang version >= 17, so if we don't have one we need to build it.
// trigger pipeline

def conts = containerTemplate(
name: 'jnlp',
image: "${dockerRegistry}/${odsNamespace}/jenkins-agent-golang:${JENKINS_AGENT_TAG}",
workingDir: '/tmp',
alwaysPullImage: true,
args: ''
)
def podLabel = "qs-tests"

podTemplate(
label: podLabel,
cloud: 'openshift',
containers: [conts],
volumes: [],
serviceAccount: 'jenkins'
) {
node(podLabel) {

stage('Init') {
currentBuild.description = "Testing QS"

dir("${QUICKSTARTER_REPO}"){
git branch: "${QUICK_STARTERS_BRANCH}",
credentialsId: "${project}-cd-cd-user-with-password",
url: "${QUICK_STARTERS_URL}"
}
dir('ods-configuration'){
git branch: "${ODS_CONFIGURATION_BRANCH}",
credentialsId: "${project}-cd-cd-user-with-password",
url: "${ODS_CONFIGURATION_URL}"
}

dir('ods-core'){
git branch: "${ODS_CORE_BRANCH}",
credentialsId: "${project}-cd-cd-user-with-password",
url: "${ODS_CORE_URL}"

// Write the file used to exclude Quickstarters in the tests
echo "Writing file quickStartersExclusionList.txt"
writeFile file: './tests/quickStartersExclusionList.txt', text: excludedQS
}
}

stage('Test') {
echo "${WORKSPACE}"

// If we select 'all' no one parameter will be provided, so it will try to test all the Quickstarters
// that have a test defined in the testdata folder.
def quickstarter_to_test = ""
quickstarter_to_test = "-q ${quickstarter}"

echo "QUICKSTARTER TO TEST : ${quickstarter_to_test}"
echo "QUICKSTARTER REPO : ${QUICKSTARTER_REPO}"
echo "Project : ${project}"

// In different environments SONAR_QUALITY_PROFILE can be different, with this env variable we provide
// the needed value
withEnv([
"CGO_ENABLED=0",
"GOMODCACHE=${WORKSPACE}/.cache",
"SONAR_QUALITY_PROFILE=${SONAR_QUALITY_PROFILE}",
"ODS_GIT_REF=${odsRef}"]) {
sh """
cd ods-core/tests
ls -lrta
./quickstarter-test.sh -p ${project} -qf "${QUICKSTARTER_REPO}/..." ${quickstarter_to_test} || true
"""
}

}

stage('Get test results') {
archiveArtifacts artifacts: 'ods-core/tests/*.txt', followSymlinks: false
archiveArtifacts artifacts: 'ods-core/tests/test-quickstarter-report.xml', followSymlinks: false
junit(testResults:"ods-core/tests/test-quickstarter-report.xml", allowEmptyResults:true)

}
}
}

21 changes: 18 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ MAKEFLAGS += --no-builtin-rules
### By default we test all quickstarters located in ods-quickstarters
QS := ods-quickstarters/...

# Load environment variables from .env file
include ../../ods-configuration/ods-core.env
export $(shell sed 's/=.*//' ../../ods-configuration/ods-core.env)

### By default we do not parallelize tests
PARALLEL := 1
PROJECT := unitt
SONAR_PROFILE := "Sonar way"
QUICKSTARTER_REPOSITORY := ods-quickstarters
configurationRef := master

## Full test of existing ODS core installation. Caution: Creates UNITT project and ODSVERIFY project.
test: smoketest verify test-create-projects
Expand All @@ -33,21 +41,28 @@ test-create-projects:
@(./create-projects-test.sh)
.PHONY: test-create-projects

## Run quickstarter tests within existing ODS installation. Depends on UNITT project.
## Create Jenkins pipeline using REST API
jenkins-pipeline:
@(envsubst < jenkinsPipelineCreation.sh)
@(./jenkinsPipelineCreation.sh -p $(PROJECT) -q $(QUICKSTARTER_REPOSITORY) -s $(SONAR_PROFILE) -c $(configurationRef))
.PHONY: jenkins-pipeline

## Run quickstarter tests within existing ODS installation. Depends on UNITT project (default).
test-quickstarter:
@(./quickstarter-test.sh $(QS) $(PARALLEL))
@(./quickstarter-test.sh -p $(PROJECT) -q $(QS) -pa $(PARALLEL))
.PHONY: test-quickstarter

## Install tools required for tests.
prep-tools:
which go-junit-report || go get github.com/jstemmer/go-junit-report
which golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.60.1
.PHONY: prep-tools

## Lint
lint:
echo "Checking code ..."
golangci-lint --version
golangci-lint run --go=1.18
golangci-lint run --go=1.23
.PHONY: lint

### HELP
Expand Down
29 changes: 20 additions & 9 deletions tests/go.mod
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
module github.com/opendevstack/ods-core/tests

go 1.13
go 1.23

require (
github.com/ghodss/yaml v1.0.0
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.5.1
github.com/jstemmer/go-junit-report v0.9.1
github.com/openshift/api v0.0.0-20180801171038-322a19404e37
github.com/openshift/client-go v3.9.0+incompatible
k8s.io/api v0.0.0-20190222213804-5cb15d344471
k8s.io/apimachinery v0.0.0-20190221213512-86fb29eff628
k8s.io/client-go v0.0.0-20190228174230-b40b2a5939e4
)

require (
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.1
github.com/google/gofuzz v1.0.0 // indirect
github.com/googleapis/gnostic v0.4.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/json-iterator/go v1.1.8 // indirect
github.com/jstemmer/go-junit-report v0.9.1
github.com/kr/pretty v0.2.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/openshift/api v0.0.0-20180801171038-322a19404e37
github.com/openshift/client-go v3.9.0+incompatible
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/protobuf v1.23.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
k8s.io/api v0.0.0-20190222213804-5cb15d344471
k8s.io/apimachinery v0.0.0-20190221213512-86fb29eff628
k8s.io/client-go v0.0.0-20190228174230-b40b2a5939e4
k8s.io/klog v1.0.0 // indirect
sigs.k8s.io/yaml v1.1.0 // indirect
)
Expand Down
Loading
Loading