Skip to content
Snippets Groups Projects
Commit 705d73cd authored by Ole Langbehn's avatar Ole Langbehn
Browse files

Merge branch 'HOLI-9454_smoketest' into 'main'

HOLI-9454 implement a smoketest in the pipeline.

See merge request app/holi-unified-api!122
parents 7a9255b3 a181cc4f
No related branches found
No related tags found
No related merge requests found
......@@ -10,12 +10,9 @@ default:
stages:
- build
- build_staging
- deploy_staging
- deploy_review
- build_production
- deploy_production
- test
- deploy
- smoketest
- destroy
variables:
# This variable needs to be named differently than in triggering projects
......@@ -46,12 +43,14 @@ variables:
resource_group: $ENVIRONMENT_ID # never execute terraform in parallel on the same environment
interruptible: false
.e2e:
image: 'europe-north1-docker.pkg.dev/holi-shared/docker-hub-remote/archlinux:latest'
.smoketest:
stage: "smoketest"
image: 'europe-north1-docker.pkg.dev/holi-shared/docker/holi-docker/holi-k6-builder'
script:
- API_DOMAIN=`cat $API_DOMAIN_FILE`
- echo "e2e tests against $CI_ENVIRONMENT_SLUG environment go here and against $API_DOMAIN"
- API_DOMAIN=$(cat $API_DOMAIN_FILE)
- terraform/environments/scripts/wait-for-ssl.sh "https://${API_DOMAIN}"
- BASE_URL="https://${API_DOMAIN}/graphql" /tmp/k6 run smoketest/main.js
# TODO should/could we roll back the service to the last working revision on test failure?
# end job templates
......@@ -77,6 +76,7 @@ install_lint_test:
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
sast:
needs: ['install_lint_test']
stage: build
include:
- template: Security/SAST.gitlab-ci.yml
......@@ -108,7 +108,7 @@ include:
- docker push $GCR_IMAGE:$CI_COMMIT_REF_SLUG # just for easyly knowing which is the last image for a branch
build_mesh_staging:
stage: build_staging
stage: build
extends: .build_mesh
variables:
# these could be fetched via terraform output ("gcr_location" in infra project), but then we would need an extra job for terraform
......@@ -124,7 +124,7 @@ build_mesh_staging:
REDIS_DB: 5
build_docker_staging:
stage: build_staging
stage: build
extends: .build_docker
needs: ['build_mesh_staging']
variables:
......@@ -132,7 +132,7 @@ build_docker_staging:
## review environments
deploy_review:
stage: deploy_review
stage: deploy
extends: .deploy
needs: ['build_docker_staging']
environment:
......@@ -145,9 +145,8 @@ deploy_review:
- production
- /^noenv\/.*/
e2e_review:
stage: test
extends: .e2e
smoketest_review:
extends: .smoketest
needs: ['deploy_review']
except:
- main
......@@ -155,6 +154,7 @@ e2e_review:
- /^noenv\/.*/
destroy_review:
stage: destroy
needs: ['deploy_review']
image:
name: 'europe-north1-docker.pkg.dev/holi-shared/docker-hub-remote/hashicorp/terraform:1.6.6'
......@@ -186,7 +186,7 @@ destroy_review:
## staging environment
deploy_staging:
stage: deploy_staging
stage: deploy
extends: .deploy
needs: ['build_docker_staging']
environment:
......@@ -198,8 +198,8 @@ deploy_staging:
only:
- main
e2e_staging:
extends: .e2e
smoketest_staging:
extends: .smoketest
needs: ['deploy_staging']
only:
- main
......@@ -207,7 +207,7 @@ e2e_staging:
## production environment
build_mesh_production:
stage: build_production
stage: build
extends: .build_mesh
variables:
# these could be fetched via terraform output ("gcr_location" in infra project), but then we would need an extra job for terraform
......@@ -225,7 +225,7 @@ build_mesh_production:
- production
build_docker_production:
stage: build_production
stage: build
extends: .build_docker
needs: ['build_mesh_production']
variables:
......@@ -234,7 +234,7 @@ build_docker_production:
- production
deploy_production:
stage: deploy_production
stage: deploy
extends: .deploy
needs: ['build_docker_production']
allow_failure: false
......@@ -247,7 +247,14 @@ deploy_production:
only:
- production
smoketest_staging:
extends: .smoketest
needs: ['deploy_production']
only:
- production/home/ole/projects/holi/holi-meta/holi-okuna/smoketest
trigger_docs_generation:
stage: deploy
needs: ['deploy_production']
trigger:
project: app/app.gitlab-pages.holi.team
......
import http from 'k6/http'
import { check, sleep } from 'k6'
import exec from 'k6/execution'
// This configuration only executes 1 test, enough for a smoketest
export const options = {
vus: 1,
iterations: 1,
}
export default () => {
// define the graphql request
const params = {
headers: {
'Content-Type': 'application/json',
},
}
const query = `query{topics{totalResults}}`
// perform the graphql request
const response = http.post(`${__ENV.BASE_URL}`, JSON.stringify({ query }), params)
// define the tests
const testResults = [
check(response, {
'is status 200': (r) => r.status === 200,
}),
check(JSON.parse(response.body), {
// there can be multiple tests here, e.g.
//"contains topics object": (r) => typeof r.data.topics != null,
'contains totalResults count': (r) => typeof r.data.topics.totalResults == 'number',
}),
]
// fail on any unmet expectations. We need to do this explicitly, because k6 is a load testing tool
if (testResults.includes(false)) {
exec.test.abort('smoke test failed')
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment