Skip to content

Commit

Permalink
Add BATS test for spinkube operator
Browse files Browse the repository at this point in the history
Just uses `spin kube deploy …` to deploy an existing sample app and verify
that it works. Uses traefik ingress because the port_forwarding API still
has some unresolved challenges.

Signed-off-by: Jan Dubois <[email protected]>
  • Loading branch information
jandubois committed May 10, 2024
1 parent 8c96a9d commit 0a3f6c6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bats/tests/helpers/commands.bash
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ rdshell() {
rdsudo() {
rdshell sudo "$@"
}
spin() {
"$PATH_RESOURCES/$PLATFORM/bin/spin$EXE" "$@" | no_cr
}
wsl() {
wsl.exe -d "$WSL_DISTRO" "$@"
}
62 changes: 62 additions & 0 deletions bats/tests/k8s/spinkube.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
load '../helpers/load'

local_setup() {
if using_docker; then
skip "this test only works on containerd right now"
fi
}

# Get the host name to use to reach Traefik
get_host() {
if is_windows; then
local jsonpath='jsonpath={.status.loadBalancer.ingress[0].ip}'
run --separate-stderr kubectl get service traefik --namespace kube-system --output "$jsonpath"
assert_success || return
assert_output || return
echo "$output.sslip.io"
else
echo "localhost"
fi
}

@test 'start k8s with spinkube' {
factory_reset
start_kubernetes \
--experimental.container-engine.web-assembly.enabled \
--experimental.kubernetes.options.spinkube
wait_for_kubelet
}

@test 'deploy app to kubernetes' {
spin kube deploy --from ghcr.io/deislabs/containerd-wasm-shims/examples/spin-rust-hello:v0.10.0
}

# TODO replace ingress with port-forwarding
@test 'deploy ingress' {
kubectl apply --filename - <<EOF
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: spin-rust-hello
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
rules:
- host: $(get_host)
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: spin-rust-hello
port:
number: 80
EOF
}

@test 'connect to app on localhost' {
run try curl --silent --fail --connect-timeout 5 "http://$(get_host)/hello"
assert_success
assert_output "Hello world from Spin!"
}

0 comments on commit 0a3f6c6

Please sign in to comment.