Skip to content
Snippets Groups Projects
Verified Commit edb6bef4 authored by Vincent Sellier's avatar Vincent Sellier
Browse files

swh/graphql: implement helm unit tests

Implement unit tests for the graphql descriptors.
Some changes were needed outside graphql in order to allow the generation
with the default values.

Related swh/infra/sysadm-environment#4765
parent 16334582
No related branches found
No related tags found
1 merge request!27swh/graphql: implements helm unit tests
__snapshot__
# Software Heritage stack helm chart
## Tests
The test are done with [helm-unittest](https://github.com/quintush/helm-unittest)
helm-unit can be launched in docker or used as a [helm plugin](https://github.com/quintush/helm-unittest#install).
For a run in docker, run this command:
```
docker run -ti --rm -v $(pwd)/..:/apps quintush/helm-unittest:3.11.1-0.3.0 --color --debug swh
```
warning: It tests the helm chart behavior, not the descriptors are valid for kubernetes
Example of outputs:
```
docker run -ti --rm -v $(pwd)/..:/apps quintush/helm-unittest:3.11.1-0.3.0 --color --debug swh
### Chart [ Argocd applications commonly used in to configure a SWH cluster ] .
PASS test cluster configuration application tests/basic-applications_test.yaml
PASS test cluster metallb application tests/metallb-application_test.yaml
### Chart [ swh ] swh
PASS test graphql deployment swh/tests/graphql_configmap_test.yaml
PASS test graphql deployment swh/tests/graphql_deployment_test.yaml
PASS test graphql deployment swh/tests/graphql_global_test.yaml
PASS test graphql deployment swh/tests/graphql_service_test.yaml
Charts: 1 passed, 1 total
Test Suites: 4 passed, 4 total
Tests: 9 passed, 9 total
Snapshot: 0 passed, 0 total
Time: 29.410877ms
```
......@@ -6,6 +6,7 @@ metadata:
name: graphql
namespace: {{ .Values.namespace }}
data:
# TODO: rename to not have a dot in the name to allow testing
config.yml: |
{{- range $backend, $backend_config := .Values.graphql.backends }}
{{ $backend }}:
......
......@@ -9,7 +9,7 @@ metadata:
app: graphql
spec:
revisionHistoryLimit: 2
replicas: {{ .Values.graphql.replicas }}
replicas: {{ .Values.graphql.replicas | default 1 }}
selector:
matchLabels:
app: graphql
......@@ -47,15 +47,17 @@ spec:
env:
- name: PORT
value: "5013"
- name: THREADS
value: {{ .Values.graphql.gunicorn.threads | quote }}
- name: WORKERS
value: {{ .Values.graphql.gunicorn.workers | quote }}
- name: LOG_LEVEL
value: {{ .Values.graphql.logLevel | quote }}
{{ if .Values.graphql.gunicorn -}}
- name: THREADS
value: {{ .Values.graphql.gunicorn.threads | default 5 | quote }}
- name: WORKERS
value: {{ .Values.graphql.gunicorn.workers | default 2 | quote }}
- name: TIMEOUT
value: {{ .Values.graphql.gunicorn.timeout | quote }}
{{ if .Values.graphql.sentry_enabled -}}
value: {{ .Values.graphql.gunicorn.timeout | default 60 | quote }}
{{ end -}}
{{ if .Values.graphql.sentry.enabled -}}
- name: SWH_SENTRY_ENVIRONMENT
value: {{ $.Values.sentry.environment }}
- name: SWH_MAIN_PACKAGE
......@@ -63,12 +65,12 @@ spec:
- name: SWH_SENTRY_DSN
valueFrom:
secretKeyRef:
name: common-secrets
key: graphql-sentry-dsn
# 'name' secret should exist & include key "host"
name: {{ $.Values.graphql.sentry.secretKeyRef }}
key: {{ $.Values.graphql.sentry.secretKeyName }}
# 'name' secret should exist & include key
# if the setting doesn't exist, sentry pushes will be disabled
optional: true
{{ end }}
{{ end -}}
volumeMounts:
- name: config
mountPath: /etc/swh/config.yml
......
{{ if .Values.graphql.enabled -}}
{{ if .Values.graphql.ingress.enabled -}}
{{ if and .Values.graphql.ingress .Values.graphql.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
......
suite: test graphql deployment
templates:
- graphql/configmap.yaml
tests:
- it: Graphql configmap is deployed when activated
set:
graphql.enabled: true
asserts:
- containsDocument:
kind: ConfigMap
apiVersion: v1
- equal:
path: metadata.namespace
value: swh
# not testable as there is a dot in the entry name
# - contains:
# path: data.config.yml
# content:
# debug: false
# count: 1
- it: Graphql namespace
set:
graphql.enabled: true
namespace: mynamespace
asserts:
- equal:
path: metadata.namespace
value: mynamespace
suite: test graphql deployment
templates:
- graphql/configmap.yaml
- graphql/deployment.yaml
tests:
- it: Graphql deployment is deployed with default values when activated
templates:
- graphql/deployment.yaml
set:
graphql.enabled: true
swh_graphql_image: image
swh_graphql_image_version: version
asserts:
- containsDocument:
kind: Deployment
apiVersion: apps/v1
- equal:
path: metadata.namespace
value: swh
- equal:
path: spec.replicas
value: 1
- lengthEqual:
path: spec.template.spec.containers
count: 1
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].image
value: image:version
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "LOG_LEVEL")].value
value: "INFO"
- isNull:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "THREADS")]
- isNull:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "WORKERS")]
- isNull:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "TIMEOUT")]
- isNull:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_SENTRY_ENVIRONMENT")]
- isNull:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_MAIN_PACKAGE")]
- isNull:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_SENTRY_DSN")]
- it: Graphql gunicorn workers configuration
templates:
- graphql/deployment.yaml
set:
graphql.enabled: true
swh_graphql_image: image
swh_graphql_image_version: version
graphql.gunicorn.threads: 101
graphql.gunicorn.workers: 102
graphql.gunicorn.timeout: 103
asserts:
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "THREADS")].value
value: "101"
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "WORKERS")].value
value: "102"
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "TIMEOUT")].value
value: "103"
- it: Graphql sentry default configuration
templates:
- graphql/deployment.yaml
set:
graphql.enabled: true
graphql.sentry.enabled: true
swh_graphql_image: image
swh_graphql_image_version: version
asserts:
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_SENTRY_ENVIRONMENT")].value
value: production
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_MAIN_PACKAGE")].value
value: swh.graphql
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_SENTRY_DSN")].valueFrom.secretKeyRef.name
value: common-secrets
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_SENTRY_DSN")].valueFrom.secretKeyRef.key
value: graphql-sentry-dsn
- it: Graphql sentry default configuration
templates:
- graphql/deployment.yaml
set:
sentry.environment: my-environment
graphql.enabled: true
graphql.sentry.enabled: true
graphql.sentry.secretKeyRef: my-secret
graphql.sentry.secretKeyName: my-key
swh_graphql_image: image
swh_graphql_image_version: version
asserts:
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_SENTRY_ENVIRONMENT")].value
value: my-environment
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_MAIN_PACKAGE")].value
value: swh.graphql
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_SENTRY_DSN")].valueFrom.secretKeyRef.name
value: my-secret
- equal:
path: spec.template.spec.containers[?(@.name == "graphql")].env[?(@.name == "SWH_SENTRY_DSN")].valueFrom.secretKeyRef.key
value: my-key
suite: test graphql deployment
templates:
- graphql/deployment.yaml
- graphql/configmap.yaml
- graphql/ingress.yaml
- graphql/service.yaml
tests:
- it: Graphql is not deployed by default
values:
- ../values.yaml
asserts:
- hasDocuments:
count: 0
suite: test graphql deployment
templates:
- graphql/service.yaml
tests:
- it: Graphql service is deployed when activated
set:
graphql.enabled: true
namespace: mynamespace
asserts:
- containsDocument:
kind: Service
apiVersion: v1
- equal:
path: metadata.namespace
value: mynamespace
namespace: swh
sentry:
environment: production
# Example of services activation
# Only implemented for storage_replayer for now
#storage:
# enabled: false
#
#graphql:
# enabled: false
graphql:
enabled: false
logLevel: INFO
debug: no
introspection: yes
sentry:
enabled: false
# name of the secret containing the $secretKeyName value
# it defines the sentry token, host and projet to access
# like https://token@sentry.host/id
secretKeyRef: common-secrets
secretKeyName: graphql-sentry-dsn
# ingress:
# enabled: false
# httpPath: /graphql
# host: my_host # Optional
# backends:
# storage:
# host: http://my-storage
# port: 5002
# search:
# host: http://my-search
# port: 5010
# Allow to specify a specific configuration for pod's /tmp
# directory. Mostly used to configure the loaders to work
......@@ -91,6 +117,9 @@ checker_deposit:
indexers:
enabled: false
listers:
enabled: false
statsd_exporter:
enabled: false
image: prom/statsd-exporter
......
......@@ -412,7 +412,8 @@ indexers:
graphql:
enabled: true
sentry_enabled: true
sentry:
enabled: true
backends:
storage:
host: webapp.internal.staging.swh.network
......
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