Skip to content

Commit

Permalink
chore(tests): backfill tests (#756)
Browse files Browse the repository at this point in the history
**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [ ] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [x] ⚖️ My code follows the style guidelines of this project
- [x] 👀 I have performed a self-review of my own code
- [ ] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [x] ⚠️ My changes generate no new warnings
- [x] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [ ] ⬆️ I increased versions for any altered app according to semantic
versioning
- [x] I made sure the title starts with `feat(chart-name):`,
`fix(chart-name):` or `chore(chart-name):`

**➕ App addition**

If this PR is an app addition please make sure you have done the
following.

- [ ] 🖼️ I have added an icon in the Chart's root directory called
`icon.png`

---

_Please don't blindly check all the boxes. Read them and only check
those that apply.
Those checkboxes are there for the reviewer to see what is this all
about and
the status of this PR with a quick glance._
  • Loading branch information
stavros-k authored Mar 16, 2024
1 parent 7d1bcdb commit a192b2a
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 3 deletions.
98 changes: 98 additions & 0 deletions library/common-test/tests/cnpg/cluster_spec_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,104 @@ tests:
- CREATE EXTENSION IF NOT EXISTS timescaledb;
- CREATE EXTENSION IF NOT EXISTS some-extension;

- it: should pass with postgis
set:
postgresPostgis16Image:
repository: postgis/postgisdb
tag: "some-tag"
cnpg:
my-pg:
enabled: true
user: app
database: app
type: postgis
cluster:
initdb:
postInitApplicationSQL:
- CREATE EXTENSION IF NOT EXISTS some-extension;
postgresql:
key1: value1
key2: '{{ printf "test-tpl" }}'
preloadLibraries:
- pg_stat_statements
- pg_cron
asserts:
- documentIndex: *clusterDoc
isKind:
of: Cluster
- documentIndex: *clusterDoc
isSubset:
path: spec
content:
postgresql:
parameters:
key1: value1
key2: test-tpl
shared_preload_libraries:
- pg_stat_statements
- pg_cron
bootstrap:
initdb:
secret:
name: test-release-name-common-test-cnpg-my-pg-user
database: app
owner: app
dataChecksums: true
postInitApplicationSQL:
- CREATE EXTENSION IF NOT EXISTS postgis;
- CREATE EXTENSION IF NOT EXISTS postgis_topology;
- CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
- CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;
- CREATE EXTENSION IF NOT EXISTS some-extension;

- it: should pass with vectors
set:
postgresVectors16Image:
repository: vectors/vectors
tag: "some-tag"
cnpg:
my-pg:
enabled: true
user: app
database: app
type: vectors
cluster:
initdb:
postInitApplicationSQL:
- CREATE EXTENSION IF NOT EXISTS some-extension;
postgresql:
key1: value1
key2: '{{ printf "test-tpl" }}'
preloadLibraries:
- pg_stat_statements
- pg_cron
asserts:
- documentIndex: *clusterDoc
isKind:
of: Cluster
- documentIndex: *clusterDoc
isSubset:
path: spec
content:
postgresql:
parameters:
key1: value1
key2: test-tpl
shared_preload_libraries:
- pg_stat_statements
- pg_cron
- vectors.so
bootstrap:
initdb:
secret:
name: test-release-name-common-test-cnpg-my-pg-user
database: app
owner: app
dataChecksums: true
postInitApplicationSQL:
- CREATE EXTENSION IF NOT EXISTS vectors;
- CREATE EXTENSION IF NOT EXISTS some-extension;

- it: should pass with enabled monitoring
set:
postgresTimescaledb16Image:
Expand Down
26 changes: 26 additions & 0 deletions library/common-test/tests/cnpg/pg_version_configmap_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ tests:
path: data.version
value: "15"

- it: should generate correct configmap with defaults being a number instead of string
set:
global:
fallbackDefaults:
pgVersion: 15
cnpg:
my-pg:
enabled: true
user: test-user
database: test-db
asserts:
- documentIndex: *cmDoc
isKind:
of: ConfigMap
- documentIndex: *cmDoc
isAPIVersion:
of: v1
- documentIndex: *cmDoc
equal:
path: metadata.name
value: test-release-name-common-test-cnpg-my-pg-pgversion
- documentIndex: *cmDoc
equal:
path: data.version
value: "15"

- it: should generate correct configmap with changed at cnpg level
set:
cnpg:
Expand Down
15 changes: 15 additions & 0 deletions library/common-test/tests/workload/validation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ tests:
- failedTemplate:
errorMessage: Name [test-release-name-common-test-other-workload-name-super-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters.

- it: should fail with namespace starts with ix- but its not in ixContext
set:
global:
ixChartsContext: {}
workload:
workload-name:
enabled: true
primary: true
namespace: ix-test
type: Deployment
podSpec: {}
asserts:
- failedTemplate:
errorMessage: Deployment - Namespace [ix-test] is not allowed to have [ix-] prefix when installed outside of SCALE-Apps

- it: should fail with name starting with underscore
set:
workload:
Expand Down
6 changes: 3 additions & 3 deletions library/common/templates/lib/metadata/_namespace.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
{{- fail (printf "%s - Namespace [%v] expected to have [ix-] prefix when installed in TrueNAS SCALE" $caller $namespace) -}}
{{- end -}}
{{- end -}}
{{- else if and (hasPrefix "ix-" $namespace) ( not $rootCtx.Values.global.ixChartContext ) -}}
{{/* Users should not use SCALE-reserved Namespace prefixes to hack things into the SCALE GUI */}}
{{- fail (printf "%s - Namespace [%v] is not allowed to have [ix-] prefix when installed outside of SCALE-Apps" $caller $namespace) -}}
{{- else if (hasPrefix "ix-" $namespace) -}}
{{/* Users should not use SCALE-reserved Namespace prefixes to hack things into the SCALE GUI */}}
{{- fail (printf "%s - Namespace [%v] is not allowed to have [ix-] prefix when installed outside of SCALE-Apps" $caller $namespace) -}}
{{- end -}}

{{- $namespace -}}
Expand Down

0 comments on commit a192b2a

Please sign in to comment.