mirror of
https://github.com/cozystack/cozystack.git
synced 2026-10-28 07:37:49 +09:00
Sweep across `hack/*.bats` and `hack/*.sh` replacing fragile `sleep N` / `timeout N until …; do sleep …; done` patterns with `kubectl wait --for=condition=…` plus a small existence backstop: until kubectl get <resource> >/dev/null 2>&1; do sleep 2; done kubectl wait <resource> --for=condition=Ready --timeout=… Existence backstop added to 33 `kubectl wait` sites across 12 bats files (redis, kafka, openbao, harbor, mongodb, qdrant, vminstance, clickhouse, mariadb, postgres, bucket, install). Without it, `kubectl wait` against a not-yet-created resource sits silently for the full timeout; with it, the test fails fast with a clear "resource never appeared" error. OpenAPI tests' fixed `sleep 5` after starting `kubectl proxy` is now a port-readiness wait. The 3 remaining genuine sleeps (LINSTOR node membership propagation, MetalLB end-to-end HTTP path, HR-count emission heuristic) are annotated with TODO + rationale so a future reader knows they are intentional. Same green-path semantics; failures now surface in seconds instead of after a 5-minute timeout. Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com> Assisted-By: Claude <noreply@anthropic.com>
59 lines
2.2 KiB
Bash
59 lines
2.2 KiB
Bash
#!/usr/bin/env bats
|
|
# -----------------------------------------------------------------------------
|
|
# Test OpenAPI endpoints in a Kubernetes cluster
|
|
# -----------------------------------------------------------------------------
|
|
|
|
@test "Test OpenAPI v2 endpoint" {
|
|
kubectl get -v7 --raw '/openapi/v2?timeout=32s' > /dev/null
|
|
}
|
|
|
|
@test "Test OpenAPI v3 endpoint" {
|
|
kubectl get -v7 --raw '/openapi/v3/apis/apps.cozystack.io/v1alpha1' > /dev/null
|
|
kubectl get -v7 --raw '/openapi/v3/apis/core.cozystack.io/v1alpha1' > /dev/null
|
|
}
|
|
|
|
@test "Test OpenAPI v2 endpoint (protobuf)" {
|
|
(
|
|
kubectl proxy --port=21234 &
|
|
proxy_pid=$!
|
|
trap "kill $proxy_pid" EXIT
|
|
# Wait for the proxy to actually be listening rather than guessing with
|
|
# a fixed sleep. nc -z is non-destructive and exits 0 the moment the
|
|
# listener accepts a connection.
|
|
timeout 10 sh -ec 'until nc -z localhost 21234; do sleep 0.1; done'
|
|
curl -sS --fail 'http://localhost:21234/openapi/v2?timeout=32s' -H 'Accept: application/com.github.proto-openapi.spec.v2@v1.0+protobuf' > /dev/null
|
|
)
|
|
}
|
|
|
|
@test "Test kinds" {
|
|
val=$(kubectl get --raw /apis/apps.cozystack.io/v1alpha1/tenants | jq -r '.kind')
|
|
if [ "$val" != "TenantList" ]; then
|
|
echo "Expected kind to be TenantList, got $val"
|
|
exit 1
|
|
fi
|
|
val=$(kubectl get --raw /apis/apps.cozystack.io/v1alpha1/tenants | jq -r '.items[0].kind')
|
|
if [ "$val" != "Tenant" ]; then
|
|
echo "Expected kind to be Tenant, got $val"
|
|
exit 1
|
|
fi
|
|
val=$(kubectl get --raw /apis/apps.cozystack.io/v1alpha1/ingresses | jq -r '.kind')
|
|
if [ "$val" != "IngressList" ]; then
|
|
echo "Expected kind to be IngressList, got $val"
|
|
exit 1
|
|
fi
|
|
val=$(kubectl get --raw /apis/apps.cozystack.io/v1alpha1/ingresses | jq -r '.items[0].kind')
|
|
if [ "$val" != "Ingress" ]; then
|
|
echo "Expected kind to be Ingress, got $val"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
@test "Create and delete namespace" {
|
|
kubectl create ns cozy-test-create-and-delete-namespace --dry-run=client -o yaml | kubectl apply -f -
|
|
if ! kubectl delete ns cozy-test-create-and-delete-namespace; then
|
|
echo "Failed to delete namespace"
|
|
kubectl describe ns cozy-test-create-and-delete-namespace
|
|
exit 1
|
|
fi
|
|
}
|