You've already forked prometheus-postgres-exporter
Initial Commit
This commit is contained in:
45
unittests/deployment/deployment.yaml
Normal file
45
unittests/deployment/deployment.yaml
Normal file
@@ -0,0 +1,45 @@
|
||||
chart:
|
||||
appVersion: 0.1.0
|
||||
version: 0.1.0
|
||||
suite: Deployment template (basic)
|
||||
release:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
templates:
|
||||
- templates/prometheus-postgres-exporter/deployment.yaml
|
||||
tests:
|
||||
- it: Rendering default
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
- notExists:
|
||||
path: metadata.annotations
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].envFrom
|
||||
content:
|
||||
secretRef:
|
||||
name: prometheus-postgres-exporter-unittest-database-env
|
||||
|
||||
- it: Test custom database secret
|
||||
set:
|
||||
config.database.existingSecret.enabled: true
|
||||
config.database.existingSecret.secretName: custom-database-secret
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.template.spec.containers[0].envFrom
|
||||
content:
|
||||
secretRef:
|
||||
name: custom-database-secret
|
140
unittests/ingress/ingress.yaml
Normal file
140
unittests/ingress/ingress.yaml
Normal file
@@ -0,0 +1,140 @@
|
||||
chart:
|
||||
appVersion: 0.1.0
|
||||
version: 0.1.0
|
||||
suite: Ingress template (basic)
|
||||
release:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
templates:
|
||||
- templates/prometheus-postgres-exporter/ingress.yaml
|
||||
tests:
|
||||
- it: Skip ingress by default.
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Skip ingress, when service is disabled.
|
||||
set:
|
||||
services.http.enabled: false
|
||||
ingress.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Render ingress with default values.
|
||||
set:
|
||||
ingress.enabled: true
|
||||
ingress.hosts:
|
||||
- host: postgres-exporter.example.local
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
ingress.tls:
|
||||
- secretName: postgres-exporter-http-tls
|
||||
hosts:
|
||||
- postgres-exporter.example.local
|
||||
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
- notExists:
|
||||
path: metadata.annotations
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
- equal:
|
||||
path: spec.ingressClassName
|
||||
value: nginx
|
||||
- contains:
|
||||
path: spec.rules
|
||||
content:
|
||||
host: postgres-exporter.example.local
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
port:
|
||||
number: 9187
|
||||
- contains:
|
||||
path: spec.tls
|
||||
content:
|
||||
hosts:
|
||||
- postgres-exporter.example.local
|
||||
secretName: postgres-exporter-http-tls
|
||||
|
||||
- it: Render ingress with custom values.
|
||||
set:
|
||||
ingress.enabled: true
|
||||
ingress.annotations:
|
||||
foo: bar
|
||||
ingress.className: nginx
|
||||
ingress.labels:
|
||||
bar: foo
|
||||
ingress.hosts:
|
||||
- host: postgres-exporter.example.local
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
ingress.tls:
|
||||
- secretName: postgres-exporter-http-tls
|
||||
hosts:
|
||||
- postgres-exporter.example.local
|
||||
|
||||
services.http.port: 8080
|
||||
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
- equal:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
foo: bar
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
bar: foo
|
||||
- equal:
|
||||
path: spec.ingressClassName
|
||||
value: nginx
|
||||
- contains:
|
||||
path: spec.rules
|
||||
content:
|
||||
host: postgres-exporter.example.local
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
port:
|
||||
number: 8080
|
||||
- contains:
|
||||
path: spec.tls
|
||||
content:
|
||||
hosts:
|
||||
- postgres-exporter.example.local
|
||||
secretName: postgres-exporter-http-tls
|
172
unittests/podMonitors/podMonitorHTTP.yaml
Normal file
172
unittests/podMonitors/podMonitorHTTP.yaml
Normal file
@@ -0,0 +1,172 @@
|
||||
chart:
|
||||
appVersion: 0.1.0
|
||||
version: 0.1.0
|
||||
suite: PodMonitor http template (basic)
|
||||
release:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
templates:
|
||||
- templates/prometheus-postgres-exporter/podMonitor.yaml
|
||||
tests:
|
||||
- it: Skip podMonitor when metrics are disabled.
|
||||
set:
|
||||
prometheus.metrics.enabled: false
|
||||
prometheus.metrics.podMonitor.enabled: true
|
||||
prometheus.metrics.serviceMonitor.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Skip podMonitor when podMonitor is disabled.
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.podMonitor.enabled: false
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Skip podMonitor when both monitor types are enabled.
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.podMonitor.enabled: true
|
||||
prometheus.metrics.serviceMonitor.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Rendering podMonitor with default values - enabled manually.
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.podMonitor.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: PodMonitor
|
||||
name: prometheus-postgres-exporter-unittest-http
|
||||
namespace: testing
|
||||
- notExists:
|
||||
path: metadata.annotations
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].enableHttp2
|
||||
value: false
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].followRedirects
|
||||
value: false
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].honorLabels
|
||||
value: false
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].interval
|
||||
value: 60s
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].path
|
||||
value: /metrics
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].port
|
||||
value: http
|
||||
- notExists:
|
||||
path: spec.podMetricsEndpoints[0].relabelings
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].scrapeTimeout
|
||||
value: 30s
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].scheme
|
||||
value: http
|
||||
- contains:
|
||||
path: spec.namespaceSelector.matchNames
|
||||
content:
|
||||
testing
|
||||
- equal:
|
||||
path: spec.selector.matchLabels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
|
||||
- it: Render podMonitor with custom annotations and labels.
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.podMonitor.enabled: true
|
||||
prometheus.metrics.podMonitor.annotations:
|
||||
foo: bar
|
||||
prometheus.metrics.podMonitor.labels:
|
||||
bar: foo
|
||||
asserts:
|
||||
- equal:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
foo: bar
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
bar: foo
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
|
||||
- it: Change defaults
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.podMonitor.enabled: true
|
||||
prometheus.metrics.podMonitor.enableHttp2: true
|
||||
prometheus.metrics.podMonitor.followRedirects: true
|
||||
prometheus.metrics.podMonitor.honorLabels: true
|
||||
prometheus.metrics.podMonitor.interval: "180s"
|
||||
prometheus.metrics.podMonitor.path: "/my-metrics"
|
||||
prometheus.metrics.podMonitor.relabelings:
|
||||
- sourceLabels: [ container ]
|
||||
separator: ";"
|
||||
regex: "app"
|
||||
replacement: "$1"
|
||||
action: "drop"
|
||||
prometheus.metrics.podMonitor.scrapeTimeout: "5s"
|
||||
prometheus.metrics.podMonitor.scheme: "http"
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].enableHttp2
|
||||
value: true
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].followRedirects
|
||||
value: true
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].honorLabels
|
||||
value: true
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].interval
|
||||
value: 180s
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].path
|
||||
value: /my-metrics
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].port
|
||||
value: http
|
||||
- contains:
|
||||
path: spec.podMetricsEndpoints[0].relabelings
|
||||
content:
|
||||
sourceLabels: [ container ]
|
||||
separator: ";"
|
||||
regex: "app"
|
||||
replacement: "$1"
|
||||
action: "drop"
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].scrapeTimeout
|
||||
value: 5s
|
||||
- equal:
|
||||
path: spec.podMetricsEndpoints[0].scheme
|
||||
value: http
|
104
unittests/secrets/database.yaml
Normal file
104
unittests/secrets/database.yaml
Normal file
@@ -0,0 +1,104 @@
|
||||
chart:
|
||||
appVersion: 0.1.0
|
||||
version: 0.1.0
|
||||
suite: Secret database template (basic)
|
||||
release:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
templates:
|
||||
- templates/prometheus-postgres-exporter/secretDatabase.yaml
|
||||
tests:
|
||||
- it: Skip rendering by using existing secret.
|
||||
set:
|
||||
config.database.existingSecret.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Expect error when no variable is defined.
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: No `databaseConnectionUrl` defined!
|
||||
|
||||
- it: Expect error when variable `databaseUsername` is not defined.
|
||||
set:
|
||||
# config.database.secret.databaseUsername: ""
|
||||
config.database.secret.databasePassword: "postgres"
|
||||
config.database.secret.databaseConnectionUrl: "localhost:5432/postgres?sslmode=disable"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: No `databaseUsername` defined!
|
||||
|
||||
- it: Expect error when variable `databasePassword` is not defined.
|
||||
set:
|
||||
config.database.secret.databaseUsername: "postgres"
|
||||
# config.database.secret.databasePassword: "postgres"
|
||||
config.database.secret.databaseConnectionUrl: "localhost:5432/postgres?sslmode=disable"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: No `databasePassword` defined!
|
||||
|
||||
- it: Expect error when variable `databaseConnectionUrl` is not defined.
|
||||
set:
|
||||
config.database.secret.databaseUsername: "postgres"
|
||||
config.database.secret.databasePassword: "postgres"
|
||||
# config.database.secret.databaseConnectionUrl: "localhost:5432/postgres?sslmode=disable"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: No `databaseConnectionUrl` defined!
|
||||
|
||||
- it: Rendering database secret.
|
||||
set:
|
||||
config.database.secret.databaseUsername: "postgres"
|
||||
config.database.secret.databasePassword: "postgres"
|
||||
config.database.secret.databaseConnectionUrl: "localhost:5432/postgres?sslmode=disable"
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
name: prometheus-postgres-exporter-unittest-database-env
|
||||
namespace: testing
|
||||
- notExists:
|
||||
path: metadata.annotations
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
- equal:
|
||||
path: stringData.DATA_SOURCE_URI
|
||||
value: "localhost:5432/postgres?sslmode=disable"
|
||||
- equal:
|
||||
path: stringData.DATA_SOURCE_USER
|
||||
value: "postgres"
|
||||
- equal:
|
||||
path: stringData.DATA_SOURCE_PASS
|
||||
value: "postgres"
|
||||
|
||||
- it: Rendering custom annotations and labels.
|
||||
set:
|
||||
config.database.secret.annotations:
|
||||
foo: bar
|
||||
bar: foo
|
||||
config.database.secret.databaseUsername: "postgres"
|
||||
config.database.secret.databasePassword: "postgres"
|
||||
config.database.secret.databaseConnectionUrl: "localhost:5432/postgres?sslmode=disable"
|
||||
config.database.secret.labels:
|
||||
foo: bar
|
||||
bar: foo
|
||||
asserts:
|
||||
- equal:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
foo: bar
|
||||
bar: foo
|
||||
- isSubset:
|
||||
path: metadata.labels
|
||||
content:
|
||||
foo: bar
|
||||
bar: foo
|
86
unittests/secrets/exporterConfig.yaml
Normal file
86
unittests/secrets/exporterConfig.yaml
Normal file
@@ -0,0 +1,86 @@
|
||||
chart:
|
||||
appVersion: 0.1.0
|
||||
version: 0.1.0
|
||||
suite: Secret database template (basic)
|
||||
release:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
templates:
|
||||
- templates/prometheus-postgres-exporter/secretExporterConfig.yaml
|
||||
tests:
|
||||
- it: Skip rendering by using existing secret.
|
||||
set:
|
||||
config.exporterConfig.existingSecret.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Render secret, but with no value.
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- equal:
|
||||
path: stringData["exporterConfig.yaml"]
|
||||
value: |
|
||||
{}
|
||||
|
||||
- it: Rendering exporter config secret.
|
||||
set:
|
||||
config.exporterConfig.secret.exporterConfig:
|
||||
auth_modules:
|
||||
first:
|
||||
type: userpass
|
||||
userpass:
|
||||
username: first_username
|
||||
password: first_password
|
||||
options:
|
||||
sslmode: disable
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
name: prometheus-postgres-exporter-unittest-exporter-config
|
||||
namespace: testing
|
||||
- notExists:
|
||||
path: metadata.annotations
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
- equal:
|
||||
path: stringData["exporterConfig.yaml"]
|
||||
value: |
|
||||
auth_modules:
|
||||
first:
|
||||
options:
|
||||
sslmode: disable
|
||||
type: userpass
|
||||
userpass:
|
||||
password: first_password
|
||||
username: first_username
|
||||
|
||||
- it: Rendering custom annotations and labels.
|
||||
set:
|
||||
config.exporterConfig.secret.annotations:
|
||||
foo: bar
|
||||
bar: foo
|
||||
config.exporterConfig.secret.labels:
|
||||
foo: bar
|
||||
bar: foo
|
||||
asserts:
|
||||
- equal:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
foo: bar
|
||||
bar: foo
|
||||
- isSubset:
|
||||
path: metadata.labels
|
||||
content:
|
||||
foo: bar
|
||||
bar: foo
|
81
unittests/secrets/webconfig.yaml
Normal file
81
unittests/secrets/webconfig.yaml
Normal file
@@ -0,0 +1,81 @@
|
||||
chart:
|
||||
appVersion: 0.1.0
|
||||
version: 0.1.0
|
||||
suite: Secret database template (basic)
|
||||
release:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
templates:
|
||||
- templates/prometheus-postgres-exporter/secretWebConfig.yaml
|
||||
tests:
|
||||
- it: Skip rendering by using existing secret.
|
||||
set:
|
||||
config.webConfig.existingSecret.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Skip rendering when no webConfig.yaml is defined.
|
||||
set:
|
||||
config.webConfig.existingSecret.enabled: false
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Rendering database secret.
|
||||
set:
|
||||
config.webConfig.secret.webConfig:
|
||||
tls_server_config:
|
||||
cert_file: /path/to/cert.pem
|
||||
client_ca_file: /path/to/ca.pem
|
||||
key_file: /path/to/key.pem
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
name: prometheus-postgres-exporter-unittest-webconfig
|
||||
namespace: testing
|
||||
- notExists:
|
||||
path: metadata.annotations
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
- equal:
|
||||
path: stringData["webConfig.yaml"]
|
||||
value: |
|
||||
tls_server_config:
|
||||
cert_file: /path/to/cert.pem
|
||||
client_ca_file: /path/to/ca.pem
|
||||
key_file: /path/to/key.pem
|
||||
|
||||
- it: Rendering custom annotations and labels.
|
||||
set:
|
||||
config.webConfig.secret.annotations:
|
||||
foo: bar
|
||||
bar: foo
|
||||
config.webConfig.secret.labels:
|
||||
foo: bar
|
||||
bar: foo
|
||||
config.webConfig.secret.webConfig:
|
||||
tls_server_config:
|
||||
cert_file: /path/to/cert.pem
|
||||
key_file: /path/to/key.pem
|
||||
client_ca_file: /path/to/ca.pem
|
||||
asserts:
|
||||
- equal:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
foo: bar
|
||||
bar: foo
|
||||
- isSubset:
|
||||
path: metadata.labels
|
||||
content:
|
||||
foo: bar
|
||||
bar: foo
|
79
unittests/serviceAccounts/serviceAccount.yaml
Normal file
79
unittests/serviceAccounts/serviceAccount.yaml
Normal file
@@ -0,0 +1,79 @@
|
||||
chart:
|
||||
appVersion: 0.1.0
|
||||
version: 0.1.0
|
||||
suite: ServiceAccount prometheus-postgres-exporter template (basic)
|
||||
release:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
templates:
|
||||
- templates/prometheus-postgres-exporter/serviceAccount.yaml
|
||||
tests:
|
||||
- it: Skip rendering.
|
||||
set:
|
||||
serviceAccount.existing.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Rendering serviceAccount with default values.
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
- notExists:
|
||||
path: metadata.annotations
|
||||
- notExists:
|
||||
path: metadata.labels
|
||||
- equal:
|
||||
path: spec.automountServiceAccountToken
|
||||
value: true
|
||||
- notExists:
|
||||
path: spec.imagePullSecrets
|
||||
- notExists:
|
||||
path: spec.secrets
|
||||
|
||||
|
||||
- it: Rendering serviceAccount with custom values.
|
||||
set:
|
||||
serviceAccount.new.annotations:
|
||||
foo: bar
|
||||
serviceAccount.new.labels:
|
||||
bar: foo
|
||||
serviceAccount.new.automountServiceAccountToken: false
|
||||
serviceAccount.new.imagePullSecrets:
|
||||
- name: "my-pull-secret"
|
||||
serviceAccount.new.secrets:
|
||||
- name: "my-secret"
|
||||
namespace: "my-namespace"
|
||||
fieldPath: "my-path"
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- exists:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
foo: bar
|
||||
- exists:
|
||||
path: metadata.labels
|
||||
value:
|
||||
bar: foo
|
||||
- equal:
|
||||
path: metadata.name
|
||||
value: prometheus-postgres-exporter-unittest
|
||||
- equal:
|
||||
path: spec.automountServiceAccountToken
|
||||
value: false
|
||||
- equal:
|
||||
path: spec.imagePullSecrets
|
||||
value:
|
||||
- name: "my-pull-secret"
|
||||
- equal:
|
||||
path: spec.secrets
|
||||
value:
|
||||
- name: "my-secret"
|
||||
namespace: "my-namespace"
|
||||
fieldPath: "my-path"
|
172
unittests/serviceMonitors/serviceMonitorHTTP.yaml
Normal file
172
unittests/serviceMonitors/serviceMonitorHTTP.yaml
Normal file
@@ -0,0 +1,172 @@
|
||||
chart:
|
||||
appVersion: 0.1.0
|
||||
version: 0.1.0
|
||||
suite: ServiceMonitor http template (basic)
|
||||
release:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
templates:
|
||||
- templates/prometheus-postgres-exporter/serviceMonitorHTTP.yaml
|
||||
tests:
|
||||
- it: Skip serviceMonitor when service is disabled.
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.serviceMonitor.enabled: true
|
||||
services.http.enabled: false
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Skip serviceMonitor when metrics are disabled.
|
||||
set:
|
||||
prometheus.metrics.enabled: false
|
||||
prometheus.metrics.serviceMonitor.enabled: true
|
||||
services.http.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Skip serviceMonitor when serviceMonitor is disabled.
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.serviceMonitor.enabled: false
|
||||
services.http.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Rendering serviceMonitor with default values - enabled manually.
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.serviceMonitor.enabled: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: ServiceMonitor
|
||||
name: prometheus-postgres-exporter-unittest-http
|
||||
namespace: testing
|
||||
- notExists:
|
||||
path: metadata.annotations
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
- equal:
|
||||
path: spec.endpoints[0].enableHttp2
|
||||
value: false
|
||||
- equal:
|
||||
path: spec.endpoints[0].followRedirects
|
||||
value: false
|
||||
- equal:
|
||||
path: spec.endpoints[0].honorLabels
|
||||
value: false
|
||||
- equal:
|
||||
path: spec.endpoints[0].interval
|
||||
value: 60s
|
||||
- equal:
|
||||
path: spec.endpoints[0].path
|
||||
value: /metrics
|
||||
- notExists:
|
||||
path: spec.endpoints[0].relabelings
|
||||
- equal:
|
||||
path: spec.endpoints[0].scrapeTimeout
|
||||
value: 30s
|
||||
- equal:
|
||||
path: spec.endpoints[0].scheme
|
||||
value: http
|
||||
- equal:
|
||||
path: spec.endpoints[0].targetPort
|
||||
value: 9187
|
||||
- contains:
|
||||
path: spec.namespaceSelector.matchNames
|
||||
content:
|
||||
testing
|
||||
- equal:
|
||||
path: spec.selector.matchLabels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/service-name: http
|
||||
|
||||
- it: Render serviceMonitor with custom annotations and labels.
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.serviceMonitor.enabled: true
|
||||
prometheus.metrics.serviceMonitor.annotations:
|
||||
foo: bar
|
||||
prometheus.metrics.serviceMonitor.labels:
|
||||
bar: foo
|
||||
asserts:
|
||||
- equal:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
foo: bar
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
bar: foo
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
|
||||
- it: Change defaults
|
||||
set:
|
||||
prometheus.metrics.enabled: true
|
||||
prometheus.metrics.serviceMonitor.enabled: true
|
||||
prometheus.metrics.serviceMonitor.enableHttp2: true
|
||||
prometheus.metrics.serviceMonitor.followRedirects: true
|
||||
prometheus.metrics.serviceMonitor.honorLabels: true
|
||||
prometheus.metrics.serviceMonitor.interval: "180s"
|
||||
prometheus.metrics.serviceMonitor.path: "/my-metrics"
|
||||
prometheus.metrics.serviceMonitor.relabelings:
|
||||
- sourceLabels: [ container ]
|
||||
separator: ";"
|
||||
regex: "app"
|
||||
replacement: "$1"
|
||||
action: "drop"
|
||||
prometheus.metrics.serviceMonitor.scrapeTimeout: "5s"
|
||||
prometheus.metrics.serviceMonitor.scheme: "http"
|
||||
prometheus.metrics.serviceMonitor.port: 10443
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- equal:
|
||||
path: spec.endpoints[0].enableHttp2
|
||||
value: true
|
||||
- equal:
|
||||
path: spec.endpoints[0].followRedirects
|
||||
value: true
|
||||
- equal:
|
||||
path: spec.endpoints[0].honorLabels
|
||||
value: true
|
||||
- equal:
|
||||
path: spec.endpoints[0].interval
|
||||
value: 180s
|
||||
- equal:
|
||||
path: spec.endpoints[0].path
|
||||
value: /my-metrics
|
||||
- contains:
|
||||
path: spec.endpoints[0].relabelings
|
||||
content:
|
||||
sourceLabels: [ container ]
|
||||
separator: ";"
|
||||
regex: "app"
|
||||
replacement: "$1"
|
||||
action: "drop"
|
||||
- equal:
|
||||
path: spec.endpoints[0].scrapeTimeout
|
||||
value: 5s
|
||||
- equal:
|
||||
path: spec.endpoints[0].scheme
|
||||
value: http
|
||||
- equal:
|
||||
path: spec.endpoints[0].targetPort
|
||||
value: 10443
|
177
unittests/services/http.yaml
Normal file
177
unittests/services/http.yaml
Normal file
@@ -0,0 +1,177 @@
|
||||
chart:
|
||||
appVersion: 0.1.0
|
||||
version: 0.1.0
|
||||
suite: Service http template (basic)
|
||||
release:
|
||||
name: prometheus-postgres-exporter-unittest
|
||||
namespace: testing
|
||||
templates:
|
||||
- templates/prometheus-postgres-exporter/serviceHTTP.yaml
|
||||
tests:
|
||||
- it: Skip service when disabled.
|
||||
set:
|
||||
services.http.enabled: false
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 0
|
||||
|
||||
- it: Rendering service with default values.
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 1
|
||||
- containsDocument:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
name: prometheus-postgres-exporter-unittest-http
|
||||
namespace: testing
|
||||
- notExists:
|
||||
path: metadata.annotations
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/service-name: http
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
- notExists:
|
||||
path: spec.externalIPs
|
||||
- notExists:
|
||||
path: spec.externalTrafficPolicy
|
||||
- equal:
|
||||
path: spec.internalTrafficPolicy
|
||||
value: Cluster
|
||||
- notExists:
|
||||
path: spec.ipFamilies
|
||||
- notExists:
|
||||
path: spec.loadBalancerClass
|
||||
- notExists:
|
||||
path: spec.loadBalancerIP
|
||||
- notExists:
|
||||
path: spec.loadBalancerSourceRanges
|
||||
- equal:
|
||||
path: spec.ports[0].name
|
||||
value: http
|
||||
- equal:
|
||||
path: spec.ports[0].protocol
|
||||
value: TCP
|
||||
- equal:
|
||||
path: spec.ports[0].port
|
||||
value: 9187
|
||||
- equal:
|
||||
path: spec.selector
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
- equal:
|
||||
path: spec.sessionAffinity
|
||||
value: None
|
||||
- notExists:
|
||||
path: spec.sessionAffinityConfig
|
||||
- equal:
|
||||
path: spec.type
|
||||
value: ClusterIP
|
||||
|
||||
- it: Require internalTrafficPolicy.
|
||||
set:
|
||||
services.http.internalTrafficPolicy: ""
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: No internal traffic policy defined!
|
||||
|
||||
- it: Require port.
|
||||
set:
|
||||
services.http.port: ""
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: No service port defined!
|
||||
|
||||
- it: Require sessionAffinity.
|
||||
set:
|
||||
services.http.sessionAffinity: ""
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: No session affinity defined!
|
||||
|
||||
- it: Require service type.
|
||||
set:
|
||||
services.http.type: ""
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: No service type defined!
|
||||
|
||||
- it: Render service with custom annotations and labels.
|
||||
set:
|
||||
services.http.annotations:
|
||||
foo: bar
|
||||
services.http.labels:
|
||||
bar: foo
|
||||
asserts:
|
||||
- equal:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
foo: bar
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app.kubernetes.io/instance: prometheus-postgres-exporter-unittest
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/name: prometheus-postgres-exporter
|
||||
app.kubernetes.io/service-name: http
|
||||
app.kubernetes.io/version: 0.1.0
|
||||
helm.sh/chart: prometheus-postgres-exporter-0.1.0
|
||||
bar: foo
|
||||
|
||||
- it: Change defaults
|
||||
set:
|
||||
services.http.externalIPs:
|
||||
- "10.11.12.13/32"
|
||||
services.http.externalTrafficPolicy: Local
|
||||
services.http.internalTrafficPolicy: Local
|
||||
services.http.ipFamilies:
|
||||
- IPv4
|
||||
services.http.loadBalancerClass: aws
|
||||
services.http.loadBalancerIP: "11.12.13.14"
|
||||
services.http.loadBalancerSourceRanges:
|
||||
- "11.12.0.0/17"
|
||||
services.http.port: 10443
|
||||
services.http.sessionAffinity: ClientIP
|
||||
services.http.type: LoadBalancer
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.externalIPs
|
||||
value:
|
||||
- 10.11.12.13/32
|
||||
- equal:
|
||||
path: spec.externalTrafficPolicy
|
||||
value: Local
|
||||
- equal:
|
||||
path: spec.internalTrafficPolicy
|
||||
value: Local
|
||||
- equal:
|
||||
path: spec.ipFamilies
|
||||
value:
|
||||
- IPv4
|
||||
- equal:
|
||||
path: spec.loadBalancerClass
|
||||
value: aws
|
||||
- equal:
|
||||
path: spec.loadBalancerIP
|
||||
value: "11.12.13.14"
|
||||
- equal:
|
||||
path: spec.loadBalancerSourceRanges
|
||||
value:
|
||||
- "11.12.0.0/17"
|
||||
- equal:
|
||||
path: spec.ports[0].port
|
||||
value: 10443
|
||||
- equal:
|
||||
path: spec.sessionAffinity
|
||||
value: ClientIP
|
||||
- equal:
|
||||
path: spec.type
|
||||
value: LoadBalancer
|
Reference in New Issue
Block a user