Skip to content

Commit 71c4b3a

Browse files
authored
test: add coverage of managementPolicies to e2e (#233)
Signed-off-by: Carl Henrik Lunde <[email protected]>
1 parent 890b619 commit 71c4b3a

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

cluster/local/postgresdb_functions.sh

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,45 @@ check_schema_privileges(){
136136
echo_step_completed
137137
}
138138

139+
setup_observe_only_database(){
140+
echo_step "create pre-existing database for observe only"
141+
142+
local datname
143+
datname="$(PGPASSWORD="${postgres_root_pw}" psql -h localhost -p 5432 -U postgres -wtAc "CREATE DATABASE \"db-observe\";")"
144+
145+
echo_step_completed
146+
}
147+
148+
check_observe_only_database(){
149+
echo_step "check if observe only database is preserved after deletion"
150+
151+
# Delete the database kubernetes object, it should not delete the database
152+
kubectl delete database.postgresql.sql.crossplane.io db-observe
153+
154+
local datname
155+
datname="$(PGPASSWORD="${postgres_root_pw}" psql -h localhost -p 5432 -U postgres -wtAc "SELECT datname FROM pg_database WHERE datname = 'db-observe';")"
156+
157+
if [[ "$datname" == "db-observe" ]]; then
158+
echo "Database db-observe is still present"
159+
echo_info "OK"
160+
else
161+
echo "Database db-observe was NOT preserved"
162+
echo_error "Not OK"
163+
fi
164+
165+
# Clean up
166+
PGPASSWORD="${postgres_root_pw}" psql -h localhost -p 5432 -U postgres -wtAc "DROP DATABASE \"db-observe\";"
167+
168+
echo_step_completed
169+
}
170+
139171
delete_postgresdb_resources(){
140172
# uninstall
141173
echo_step "uninstalling ${PROJECT_NAME}"
142-
"${KUBECTL}" delete -f ${projectdir}/examples/postgresql/grant.yaml
143-
"${KUBECTL}" delete -f ${projectdir}/examples/postgresql/database.yaml
144-
"${KUBECTL}" delete -f ${projectdir}/examples/postgresql/role.yaml
145-
"${KUBECTL}" delete -f ${projectdir}/examples/postgresql/schema.yaml
174+
"${KUBECTL}" delete -f "${projectdir}/examples/postgresql/grant.yaml"
175+
"${KUBECTL}" delete --ignore-not-found=true -f "${projectdir}/examples/postgresql/database.yaml"
176+
"${KUBECTL}" delete -f "${projectdir}/examples/postgresql/role.yaml"
177+
"${KUBECTL}" delete -f "${projectdir}/examples/postgresql/schema.yaml"
146178
echo "${PROVIDER_CONFIG_POSTGRES_YAML}" | "${KUBECTL}" delete -f -
147179

148180
# ----------- cleaning postgres related resources
@@ -160,7 +192,9 @@ delete_postgresdb_resources(){
160192
integration_tests_postgres() {
161193
setup_postgresdb_no_tls
162194
setup_provider_config_postgres_no_tls
195+
setup_observe_only_database
163196
setup_postgresdb_tests
197+
check_observe_only_database
164198
check_all_roles_privileges
165199
check_schema_privileges
166200
delete_postgresdb_resources

examples/postgresql/database.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,13 @@ spec:
1313
deletionPolicy: Orphan
1414
forProvider:
1515
allowConnections: true
16-
owner: "ownerrole"
16+
owner: "ownerrole"
17+
---
18+
apiVersion: postgresql.sql.crossplane.io/v1alpha1
19+
kind: Database
20+
metadata:
21+
name: db-observe
22+
spec:
23+
managementPolicies:
24+
- Observe
25+
forProvider: {}

0 commit comments

Comments
 (0)