From 098259eef939818d5404680a53d840cc0e7b67e4 Mon Sep 17 00:00:00 2001 From: Mike Seese Date: Thu, 4 Apr 2024 21:32:15 -0700 Subject: [PATCH] Add tests for port forwarding API endpoint Signed-off-by: Mike Seese --- bats/tests/k8s/wasm.bats | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bats/tests/k8s/wasm.bats b/bats/tests/k8s/wasm.bats index ab5d8896ac7..346b56fad0c 100644 --- a/bats/tests/k8s/wasm.bats +++ b/bats/tests/k8s/wasm.bats @@ -141,3 +141,21 @@ EOF assert_success assert_output "Hello world from Spin!" } + +@test 'fail to connect to the service on localhost without port forwarding' { + run try curl --silent --fail "http://localhost:8080/hello" + assert_failure +} + +@test 'connect to the service on localhost with port forwarding' { + rdctl api -X POST -b '{ "namespace": "default", "service": "hello-spin", "k8sPort": 80, "hostPort": 8080 }' port_forwarding + run try curl --silent --fail "http://localhost:8080/hello" + assert_success + assert_output "Hello world from Spin!" +} + +@test 'fail to connect to the service on localhost after removing port forwarding' { + rdctl api -X DELETE "port_forwarding?namespace=default&service=hello-spin&k8sPort=80" + run try curl --silent --fail "http://localhost:8080/hello" + assert_failure +} \ No newline at end of file