Skip to content

Commit 6064ee5

Browse files
committed
chore: update tests for centralized logic
after rebasing, update test scripts to use centralized logic that was introduced in cloudnative-pg#53 Signed-off-by: Jeremy Schneider <[email protected]>
1 parent 5d85bad commit 6064ee5

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

test-1-setup.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if "${ROOT}/scripts/setup.sh"; then pass "Infrastructure setup finish at $(date
2424
# Test infrastructure health (MinIO API + Kubernetes API)
2525
log "Testing infrastructure health..."
2626
for region in eu us; do
27-
CTX="kind-${K8S_BASE_NAME}-${region}"
27+
CTX=$(get_cluster_context "${region}")
2828

2929
# Test Kubernetes API
3030
kubectl --context "${CTX}" get nodes && \
@@ -47,7 +47,7 @@ sleep 60
4747
# Test monitoring health (Prometheus + Grafana + node/system metrics)
4848
log "Testing monitoring stack health..."
4949
for region in eu us; do
50-
CTX="kind-${K8S_BASE_NAME}-${region}"
50+
CTX=$(get_cluster_context "${region}")
5151

5252
# Wait for Prometheus pod
5353
kubectl --context "${CTX}" wait --for=condition=Ready pod -l app.kubernetes.io/name=prometheus \
@@ -62,8 +62,9 @@ done
6262

6363
for region in eu us; do
6464
# Test Prometheus HTTP and metrics
65+
CTX=$(get_cluster_context "${region}")
6566
PORT=9090; [ "$region" = "us" ] && PORT=9091
66-
kubectl port-forward -n prometheus-operator prometheus-prometheus-0 ${PORT}:9090 --context "kind-${K8S_BASE_NAME}-${region}" &
67+
kubectl port-forward -n prometheus-operator prometheus-prometheus-0 ${PORT}:9090 --context "${CTX}" &
6768
sleep 3
6869

6970
[ "$(curl -s http://localhost:${PORT}/-/ready)" = "Prometheus Server is Ready." ] && \
@@ -80,7 +81,7 @@ for region in eu us; do
8081

8182
# Test Grafana HTTP
8283
GPORT=3000; [ "$region" = "us" ] && GPORT=3001
83-
kubectl port-forward -n grafana service/grafana-service ${GPORT}:3000 --context "kind-${K8S_BASE_NAME}-${region}" &
84+
kubectl port-forward -n grafana service/grafana-service ${GPORT}:3000 --context "${CTX}" &
8485
sleep 3
8586

8687
GSTATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:${GPORT}/login || echo "000")
@@ -96,7 +97,7 @@ if LEGACY=true "${ROOT}/demo/setup.sh"; then pass "PostgreSQL setup finish at $(
9697
# Test PostgreSQL health and metrics
9798
log "Testing PostgreSQL clusters..."
9899
for region in eu us; do
99-
CTX="kind-${K8S_BASE_NAME}-${region}"
100+
CTX=$(get_cluster_context "${region}")
100101
log "Testing region: ${region}"
101102

102103
# PostgreSQL readiness
@@ -115,8 +116,9 @@ sleep 60 # Increased from 45s to ensure both regions have time to scrape
115116
cleanup # Clean any lingering port-forwards
116117

117118
for region in eu us; do
119+
CTX=$(get_cluster_context "${region}")
118120
PORT=9090; [ "$region" = "us" ] && PORT=9091
119-
kubectl port-forward -n prometheus-operator prometheus-prometheus-0 ${PORT}:9090 --context "kind-${K8S_BASE_NAME}-${region}" &
121+
kubectl port-forward -n prometheus-operator prometheus-prometheus-0 ${PORT}:9090 --context "${CTX}" &
120122
sleep 3
121123

122124
PGMETRICS=$(curl -s "http://localhost:${PORT}/api/v1/query?query=cnpg_collector_up" | jq -r '.data.result | length' || echo "0")
@@ -132,7 +134,7 @@ log "Waiting 3.5 minutes for recording rules to evaluate (data + buffer)... sta
132134
sleep 210 # 3.5 minutes wait for sufficient time series data
133135

134136
for region in eu us; do
135-
CTX="kind-${K8S_BASE_NAME}-${region}"
137+
CTX=$(get_cluster_context "${region}")
136138
PORT=9090; [ "$region" = "us" ] && PORT=9091
137139

138140
kubectl port-forward -n prometheus-operator prometheus-prometheus-0 ${PORT}:9090 --context "${CTX}" &

test-2-teardown.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ trap cleanup EXIT
2020
# Pre-flight check: Verify database is running before teardown tests
2121
log "Pre-flight check: Verifying database is running..."
2222
for region in eu us; do
23-
kubectl --context "kind-${K8S_BASE_NAME}-${region}" wait --for=condition=Ready pod -l cnpg.io/cluster=pg-${region} --timeout=10s && \
23+
CTX=$(get_cluster_context "${region}")
24+
kubectl --context "${CTX}" wait --for=condition=Ready pod -l cnpg.io/cluster=pg-${region} --timeout=10s && \
2425
pass "${region}: PostgreSQL running" || { fail "${region}: PostgreSQL not ready. Run test-1-setup.sh first."; exit 1; }
2526
done
2627

@@ -29,7 +30,7 @@ log "Tearing down PostgreSQL clusters..."
2930
"${ROOT}/demo/teardown.sh" && pass "PostgreSQL teardown" || fail "PostgreSQL teardown"
3031

3132
for region in eu us; do
32-
CTX="kind-${K8S_BASE_NAME}-${region}"
33+
CTX=$(get_cluster_context "${region}")
3334
PGPODS=$(kubectl --context "${CTX}" get pods -l cnpg.io/cluster=pg-${region} --no-headers | wc -l || echo "0")
3435
[ "${PGPODS}" -eq 0 ] && pass "${region}: PostgreSQL removed" || fail "${region}: PostgreSQL still exists"
3536
done
@@ -38,7 +39,7 @@ log "Recreating PostgreSQL clusters..."
3839
if LEGACY=true "${ROOT}/demo/setup.sh"; then pass "PostgreSQL re-setup"; else fail "PostgreSQL re-setup"; exit 1; fi
3940

4041
for region in eu us; do
41-
CTX="kind-${K8S_BASE_NAME}-${region}"
42+
CTX=$(get_cluster_context "${region}")
4243
kubectl --context "${CTX}" wait --for=condition=Ready pod -l cnpg.io/cluster=pg-${region} --timeout=30s && \
4344
pass "${region}: PostgreSQL ready" || fail "${region}: PostgreSQL not ready"
4445
done
@@ -48,7 +49,7 @@ log "Tearing down monitoring stack..."
4849
"${ROOT}/monitoring/teardown.sh" && pass "Monitoring teardown" || fail "Monitoring teardown"
4950

5051
for region in eu us; do
51-
CTX="kind-${K8S_BASE_NAME}-${region}"
52+
CTX=$(get_cluster_context "${region}")
5253
for ns in prometheus-operator grafana; do
5354
! kubectl --context "${CTX}" get namespace "${ns}" && \
5455
pass "${region}: ${ns} removed" || fail "${region}: ${ns} still exists"
@@ -59,7 +60,7 @@ log "Recreating monitoring stack..."
5960
if "${ROOT}/monitoring/setup.sh"; then pass "Monitoring re-setup"; else fail "Monitoring re-setup"; exit 1; fi
6061

6162
for region in eu us; do
62-
CTX="kind-${K8S_BASE_NAME}-${region}"
63+
CTX=$(get_cluster_context "${region}")
6364
kubectl --context "${CTX}" wait --for=condition=Ready pod -l app.kubernetes.io/name=prometheus \
6465
-n prometheus-operator --timeout=90s && \
6566
pass "${region}: Prometheus ready" || fail "${region}: Prometheus not ready"

0 commit comments

Comments
 (0)