fix: introduce unit tests for service monitor and metrics secret

Signed-off-by: Hitesh Nayak <hiteshnayak305@gmail.com>
This commit is contained in:
Hitesh Nayak 2024-04-10 22:39:37 +05:30
parent 4548175824
commit a4c8fa19bf
No known key found for this signature in database
GPG Key ID: 2E4D20F7F119206B
4 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,21 @@
suite: Metrics secret template (gitea.metrics.serviceMonitor disabled)
release:
name: gitea-unittests
namespace: testing
templates:
- templates/gitea/metrics-secret.yaml
tests:
- it: renders nothing if gitea.metrics.serviceMonitor disabled and gitea.config.metrics.TOKEN empty
set:
gitea.metrics.serviceMonitor.enabled: false
gitea.config.metrics.TOKEN: ""
asserts:
- hasDocuments:
count: 0
- it: renders nothing if gitea.metrics.serviceMonitor disabled and gitea.config.metrics.TOKEN not empty
set:
gitea.metrics.serviceMonitor.enabled: false
gitea.config.metrics.TOKEN: "test-token"
asserts:
- hasDocuments:
count: 0

View File

@ -0,0 +1,31 @@
suite: Metrics secret template (gitea.metrics.serviceMonitor enabled)
release:
name: gitea-unittests
namespace: testing
templates:
- templates/gitea/metrics-secret.yaml
tests:
- it: renders nothing if gitea.metrics.serviceMonitor enabled and gitea.config.metrics.TOKEN empty
set:
gitea.metrics.serviceMonitor.enabled: true
gitea.config.metrics.TOKEN: ""
asserts:
- hasDocuments:
count: 0
- it: renders Secret if gitea.metrics.serviceMonitor enabled and gitea.config.metrics.TOKEN not empty
set:
gitea.metrics.serviceMonitor.enabled: true
gitea.config.metrics.TOKEN: "test-token"
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
containsDocument:
kind: Secret
apiVersion: v1
name: gitea-unittests-metrics-secret
- isNotNullOrEmpty:
path: metadata.labels
- equal:
path: data.token
value: "dGVzdC10b2tlbg=="

View File

@ -0,0 +1,21 @@
suite: ServiceMonitor template (gitea.metrics.serviceMonitor disabled)
release:
name: gitea-unittests
namespace: testing
templates:
- templates/gitea/servicemonitor.yaml
tests:
- it: renders nothing if gitea.metrics.serviceMonitor disabled and gitea.config.metrics.TOKEN empty
set:
gitea.metrics.serviceMonitor.enabled: false
gitea.config.metrics.TOKEN: ""
asserts:
- hasDocuments:
count: 0
- it: renders nothing if gitea.metrics.serviceMonitor disabled and gitea.config.metrics.TOKEN not empty
set:
gitea.metrics.serviceMonitor.enabled: false
gitea.config.metrics.TOKEN: "test-token"
asserts:
- hasDocuments:
count: 0

View File

@ -0,0 +1,49 @@
suite: ServiceMonitor template (gitea.metrics.serviceMonitor enabled)
release:
name: gitea-unittests
namespace: testing
templates:
- templates/gitea/servicemonitor.yaml
tests:
- it: renders unsecure ServiceMonitor if gitea.metrics.serviceMonitor enabled and gitea.config.metrics.TOKEN empty
set:
gitea.metrics.serviceMonitor.enabled: true
gitea.config.metrics.TOKEN: ""
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
containsDocument:
kind: ServiceMonitor
apiVersion: monitoring.coreos.com/v1
name: gitea-unittests
- isNotNullOrEmpty:
path: metadata.labels
- equal:
path: spec.endpoints
value:
- port: http
- it: renders secure ServiceMonitor if gitea.metrics.serviceMonitor enabled and gitea.config.metrics.TOKEN not empty
set:
gitea.metrics.serviceMonitor.enabled: true
gitea.config.metrics.TOKEN: "test-token"
asserts:
- hasDocuments:
count: 1
- documentIndex: 0
containsDocument:
kind: ServiceMonitor
apiVersion: monitoring.coreos.com/v1
name: gitea-unittests
- isNotNullOrEmpty:
path: metadata.labels
- equal:
path: spec.endpoints
value:
- port: http
authorization:
type: Bearer
credentials:
name: gitea-unittests-metrics-secret
key: token
optional: true