Skip to content

Commit

Permalink
e2e-test with kuttl
Browse files Browse the repository at this point in the history
  • Loading branch information
tstenner committed Jul 5, 2023
1 parent 722b2cf commit c923de5
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 0 deletions.
13 changes: 13 additions & 0 deletions kuttl-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# code: language=yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/kudobuilder/kuttl/main/crds/testsuite-json-schema.yaml
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
startKIND: false
startControlPlane: true
testDirs:
- tests/kuttle_e2e/
timeout: 15
crdDir: config/crd/bases
commands:
- command: ./bin/manager
background: true
10 changes: 10 additions & 0 deletions tests/kuttle_e2e/basic/00-0createdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: db.movetokube.com/v1alpha1
kind: Postgres
metadata:
name: basicdbcr
spec:
database: basicdb
dropOnDelete: true
masterRole: noprefix-basicdb-group
schemas:
- testschema
13 changes: 13 additions & 0 deletions tests/kuttle_e2e/basic/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: db.movetokube.com/v1alpha1
kind: Postgres
metadata:
name: basicdbcr
status:
dbname: pref-basicdb
roles:
owner: noprefix-basicdb-group
reader: pref-basicdb-reader
writer: pref-basicdb-writer
schemas:
- testschema
succeeded: true
9 changes: 9 additions & 0 deletions tests/kuttle_e2e/basic/02-0createuser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: db.movetokube.com/v1alpha1
kind: PostgresUser
metadata:
name: basicdbuser
spec:
role: basicdb-user1
database: basicdbcr
secretName: basicdbuser-secret
privileges: OWNER
16 changes: 16 additions & 0 deletions tests/kuttle_e2e/basic/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
data:
DATABASE_NAME: cHJlZi1iYXNpY2Ri
# LOGIN/ROLE etc are generated
kind: Secret
metadata:
labels:
app: basicdbuser
name: basicdbuser-secret-basicdbuser
ownerReferences:
- apiVersion: db.movetokube.com/v1alpha1
blockOwnerDeletion: true
controller: true
kind: PostgresUser
name: basicdbuser
type: Opaque
10 changes: 10 additions & 0 deletions tests/kuttle_e2e/basic/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 10
commands:
- script: |
set -eu
pgurl="$(kubectl -n "$NAMESPACE" get secrets basicdbuser-secret-basicdbuser -o 'jsonpath={.data.POSTGRES_URL}' | base64 -d)"
echo "$pgurl";
set -x
psql "$pgurl" -tA -c 'SELECT 1;'
10 changes: 10 additions & 0 deletions tests/kuttle_e2e/basic/04-0dropdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
# TODO: DB zuerst
- apiVersion: db.movetokube.com/v1alpha1
kind: PostgresUser
name: basicdbuser
- apiVersion: db.movetokube.com/v1alpha1
kind: Postgres
name: basicdbcr
4 changes: 4 additions & 0 deletions tests/kuttle_e2e/basic/04-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: db.movetokube.com/v1alpha1
kind: Postgres
metadata:
name: basicdbcr
7 changes: 7 additions & 0 deletions tests/kuttle_e2e/basic/10-0createdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# reapply the DB from step 00
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- 00-0createdb.yaml
assert:
- 00-assert.yaml
10 changes: 10 additions & 0 deletions tests/kuttle_e2e/basic/11-0duplicatedb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: db.movetokube.com/v1alpha1
kind: Postgres
metadata:
name: basicdb-duplicate
spec:
database: basicdb
dropOnDelete: true
masterRole: basicdb-newowner
schemas:
- testschema3
12 changes: 12 additions & 0 deletions tests/kuttle_e2e/basic/11-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: db.movetokube.com/v1alpha1
kind: Postgres
metadata:
name: basicdb-duplicate
status:
roles:
owner: basicdb-newowner
reader: pref-basicdb-reader
writer: pref-basicdb-writer
schemas:
- testschema3
succeeded: true
5 changes: 5 additions & 0 deletions tests/kuttle_e2e/basic/12-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 10
commands:
- script: test "$(psql -t -A -d postgres -c "SELECT datname, r.rolname FROM pg_database d JOIN pg_roles r ON d.datdba = r.oid WHERE datname='pref-basicdb'")" = "pref-basicdb|basicdb-newowner"

0 comments on commit c923de5

Please sign in to comment.