From e8df2195117e7c9522cf9afb0a18ffde05e0cf58 Mon Sep 17 00:00:00 2001 From: Ryan Garcia Date: Tue, 1 Jun 2021 21:25:13 +0000 Subject: [PATCH] feat: Helm test-lib library and enhanced helm testing --- chart/Chart.lock | 6 ++++ chart/Chart.yaml | 6 +++- chart/charts/gluon-0.1.1.tgz | Bin 0 -> 2691 bytes chart/templates/tests/test-api.yaml | 7 +++++ chart/templates/tests/test-ui.yaml | 7 +++++ chart/tests/cypress/cypress.json | 5 ++++ chart/tests/cypress/twistlock-health.spec.js | 13 ++++++++ chart/tests/scripts/check-api.sh | 28 ++++++++++++++++++ tests/cypress.json | 8 ----- .../integration/twistlock-health.spec.js | 6 ---- tests/test-values.yml | 12 ++++++++ 11 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 chart/Chart.lock create mode 100644 chart/charts/gluon-0.1.1.tgz create mode 100644 chart/templates/tests/test-api.yaml create mode 100644 chart/templates/tests/test-ui.yaml create mode 100644 chart/tests/cypress/cypress.json create mode 100644 chart/tests/cypress/twistlock-health.spec.js create mode 100644 chart/tests/scripts/check-api.sh delete mode 100644 tests/cypress.json delete mode 100644 tests/cypress/integration/twistlock-health.spec.js diff --git a/chart/Chart.lock b/chart/Chart.lock new file mode 100644 index 0000000..507aa7a --- /dev/null +++ b/chart/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: gluon + repository: oci://registry.dso.mil/platform-one/big-bang/apps/library-charts/gluon + version: 0.1.1 +digest: sha256:cf1107c00a11cde8074a39624643312fe85ee11250bb7d9380e3787bde0af0f7 +generated: "2021-06-01T10:06:05.8383699-06:00" diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 143e0cb..571ee7b 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -1,4 +1,8 @@ apiVersion: v2 name: twistlock -version: 0.0.4-bb.2 +version: 0.0.4-bb.3 appVersion: 21.04.412 +dependencies: + - name: gluon + version: 0.1.1 + repository: oci://registry.dso.mil/platform-one/big-bang/apps/library-charts/gluon diff --git a/chart/charts/gluon-0.1.1.tgz b/chart/charts/gluon-0.1.1.tgz new file mode 100644 index 0000000000000000000000000000000000000000..b4a4878dae126348cdee9d80977a15121ba59f9f GIT binary patch literal 2691 zcmV-}3Vih+iwG0|00000|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PGuUbK5pDpZP2H7*A^ZN>EZPyQfZjlP0-dX4*89bTZfJWHKPR zq7Z`s4*=yjPVTqgfDehHNIh)D&gFy;76~jC*e9`zb<8s<{Kpfj47sEUzxNqhuh;9H zo}A>ry zs{zSnpP-5nE*R%fJems$e?0p27no@YP!WO5Oqv-m69k1i4)Fa2srx=++D22iIrs^rNgY_!KGz2+CrC5X-4kOft32I%_(W)r{)d+`L zW-7!Z=h*-B$+1L6IA#LDZBpt&32r{!RN20?(i} z+J75frV6zVr5Lj~q3QLV!W#SUKRg{S+W(+89Gvd$|2EpPY2@N3rS!eI_^n;djD?MX zyv_}p1VKKddxW5%0mob+7mgc!=bVXX1dsDIex<3CprH{pbmRaOhYR=W3P^E0eQu5X z(!1ac1KCW4W zAytHF!z5wSXW|`(W(4k-a*Y;<(*Sw7p2e2i%?L_jO9FICLmYu6;w5sV8gnx8Zp)8~ z*sCizB>!L>HTjv#0Nla|OH%z~_lP{w1)ty}2wH5gev|UtB@_<(g^Ze>d@IjwmvA@qkh}EmJ9F+j#jtSO zU7y0Pv5K(^Fj94a5vmLu)6nQn2z;MPRV}JfO<9PK!cb zQzlTAT=7aVuauytEvtIKza&Sml=Ex8OV` z@APIfX8228s|_7i`m8bmo);*2p;19NQ8GdByb02X+wlhv%GvPrU(bGj`}nsfPk%W0 z`w@Kn*w$ZLVU>-ohFP?=&0rVJsV2x$%^*etvqOg!XqV@L$_^@w59Y#Nk~7TkN669O z^_Hk195ZJbcc_qF7dLpGja$7j<5=l|-(c&^SzNF47NtCQt4%o<_PSsdI#h^4Po&YX zY@z^$D)64cH}MCSg7>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L(F9W2{qw_iTGPk$f;pdgp`^|t)Gg>xeo&4Jd}pRRNo!X zo8XrqMLyGR2~t$RnLy%@C$HYVGE$*)A0Epjkpf;negzRz+95GBe*U-EzC(f!%Fq8+ z9h2C%f2vnK75*GiK*RGag)!r(onxXeQs_vDi8Ok8>YhQ^jPa;n|a? x+99cuHf(nYi;(&SxRUQ2GS#7s(EoaGjrMKd_U&tE{|x{D|Nn#y-Ua|n0063gS|tDg literal 0 HcmV?d00001 diff --git a/chart/templates/tests/test-api.yaml b/chart/templates/tests/test-api.yaml new file mode 100644 index 0000000..37e825e --- /dev/null +++ b/chart/templates/tests/test-api.yaml @@ -0,0 +1,7 @@ +{{- include "gluon.tests.script-configmap.overrides" (list . "twistlock-test.script-configmap") }} +{{- define "twistlock-test.script-configmap" }} +{{- end }} +--- +{{- include "gluon.tests.script-runner.overrides" (list . "twistlock-test.script-runner") -}} +{{- define "twistlock-test.script-runner" -}} +{{- end }} diff --git a/chart/templates/tests/test-ui.yaml b/chart/templates/tests/test-ui.yaml new file mode 100644 index 0000000..c308e60 --- /dev/null +++ b/chart/templates/tests/test-ui.yaml @@ -0,0 +1,7 @@ +{{- include "gluon.tests.cypress-configmap.overrides" (list . "twistlock-test.cypress-configmap") }} +{{- define "twistlock-test.cypress-configmap" }} +{{- end }} +--- +{{- include "gluon.tests.cypress-runner.overrides" (list . "twistlock-test.cypress-runner") -}} +{{- define "twistlock-test.cypress-runner" -}} +{{- end }} diff --git a/chart/tests/cypress/cypress.json b/chart/tests/cypress/cypress.json new file mode 100644 index 0000000..e36f984 --- /dev/null +++ b/chart/tests/cypress/cypress.json @@ -0,0 +1,5 @@ +{ + "pluginsFile": false, + "supportFile": false, + "fixturesFolder": false +} diff --git a/chart/tests/cypress/twistlock-health.spec.js b/chart/tests/cypress/twistlock-health.spec.js new file mode 100644 index 0000000..251bb65 --- /dev/null +++ b/chart/tests/cypress/twistlock-health.spec.js @@ -0,0 +1,13 @@ +describe('Twistlock Healthcheck', function() { + it('Check console is accessible', function() { + cy.visit('/', { timeout: 5000 }) + cy.title().should('eq', 'Prisma Cloud') + }) + + /* Below section should work, but times out because either one of Cypress or Twistlock doesn't play nice. + it('Create admin user', function() { + cy.get('input[type="text"]').type("admin") + cy.get('input[type="password"]').type(Cypress.env('twistlock_password')) + cy.get('button[type="submit"]').click() + })*/ +}) diff --git a/chart/tests/scripts/check-api.sh b/chart/tests/scripts/check-api.sh new file mode 100644 index 0000000..c49f607 --- /dev/null +++ b/chart/tests/scripts/check-api.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -ex + +echo "Hitting Twistlock API endpoint..." +curl -sISk -H 'Authorization: Basic "${api_auth}"' "${twistlock_host}/" &>/dev/null || export TW_DOWN="true" +if [[ ${TW_DOWN} == "true" ]]; then + echo "Test 1 Failure: Cannot hit Twistlock endpoint." + echo "Debug information (curl response):" + echo $(curl -k -H 'Authorization: Basic "${api_auth}"' "${twistlock_host}/") + exit 1 +fi +echo "Test 1 Success: Twistlock API is up." + +# A license is required to do more +#echo "Creating admin user for further testing" +#curl -k -H 'Content-Type: application/json' -XPOST -d '{"username": "admin", "password": "admin"}' "${twistlock_host}/api/v1/signup" &>/dev/null +#echo "Created admin user for further testing." +# +#echo "Hitting Twistlock API Version endpoint..." +#version_response=$(curl -k -H 'Content-Type: application/json' -H 'Authorization: Basic YWRtaW46YWRtaW4=' "${twistlock_host}/api/v1/version" 2>/dev/null) +#current_version=$(echo ${version_response} | xargs) +#if [ ! ${desired_version} == ${current_version} ]; then +# echo "Test 2 Failure: Twistlock version does not match." +# echo "Debug information (curl response):" +# echo $(curl -k -H 'Content-Type: application/json' -H 'Authorization: Basic "${api_auth}"' "${twistlock_host}/api/v1/version") +# exit 1 +#fi +#echo "Test 2 Success: Twistlock Version Matches." diff --git a/tests/cypress.json b/tests/cypress.json deleted file mode 100644 index 81dd4b8..0000000 --- a/tests/cypress.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "pluginsFile": false, - "supportFile": false, - "fixturesFolder": false, - "env": { - "twistlock_url": "twistlock.bigbang.dev" - } -} diff --git a/tests/cypress/integration/twistlock-health.spec.js b/tests/cypress/integration/twistlock-health.spec.js deleted file mode 100644 index 7b2114c..0000000 --- a/tests/cypress/integration/twistlock-health.spec.js +++ /dev/null @@ -1,6 +0,0 @@ -describe('Basic Twistlock Up', function() { - it('Check console is accessible', () => { - cy.visit(Cypress.env('twistlock_url')); - cy.title().should('eq', 'Prisma Cloud'); - }); -}) diff --git a/tests/test-values.yml b/tests/test-values.yml index 2986adb..520f8ce 100644 --- a/tests/test-values.yml +++ b/tests/test-values.yml @@ -7,3 +7,15 @@ imagePullSecrets: console: persistence: size: 5Gi + +bbtests: + enabled: true + cypress: + artifacts: true + envs: + cypress_baseUrl: "http://{{ .Release.Name }}-console.{{ .Release.Namespace }}.svc.cluster.local:8081" + scripts: + image: registry1.dso.mil/ironbank/stedolan/jq:1.6 + envs: + twistlock_host: "https://{{ .Release.Name }}-console.{{ .Release.Namespace }}.svc.cluster.local:8083" + desired_version: "{{ .Values.console.image.tag }}" -- GitLab