diff options
Diffstat (limited to 'nix/test-deployment.nix')
-rw-r--r-- | nix/test-deployment.nix | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/nix/test-deployment.nix b/nix/test-deployment.nix new file mode 100644 index 0000000..d10e5e6 --- /dev/null +++ b/nix/test-deployment.nix @@ -0,0 +1,40 @@ +{ kind, pkgs }: + +pkgs.writeScriptBin "test-deployment" '' + #! ${pkgs.runtimeShell} + set -euo pipefail + + SERVICE_URL=http://localhost:8001/api/v1/namespaces/default/services/hello:3000/proxy/ + + KUBECONFIG=$(${kind}/bin/kind get kubeconfig-path --name="kind") + PROXY_PID="" + trap cleanup EXIT + + function cleanup { + if ! [ -z $PROXY_PID ]; then + kill -9 $PROXY_PID + fi + } + + CLUSTERS=$(${kind}/bin/kind get clusters) + if ! [ "$CLUSTERS" = "kind" ]; then + echo "Error: kind cluster not running" + exit 1 + fi + + echo "- Cluster seems to be up and running ✓" + ${pkgs.kubectl}/bin/kubectl proxy >/dev/null & + + PROXY_PID=$! + sleep 3 + + RESPONSE=$(${pkgs.curl}/bin/curl --silent $SERVICE_URL) + + if ! [ "$RESPONSE" == "Hello World" ]; then + echo "Error: did not get expected response from service:" + echo $RESPONSE + exit 1 + fi + echo "- Service returns expected response ✓" +'' + |