Skip to content

Commit

Permalink
test(rust): fix "basic web-app" bats tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbenavides committed Apr 8, 2024
1 parent 8a755f5 commit 7f78b0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

export PG_PORT=5432
if [[ -z $PG_PORT ]]; then
export PG_PORT=5432
fi

function skip_if_docs_tests_not_enabled() {
# shellcheck disable=SC2031
Expand All @@ -10,11 +12,11 @@ function skip_if_docs_tests_not_enabled() {
}

start_python_server() {
if [[ "$BATS_TEST_DESCRIPTION" != *"basic-web-app"* ]]; then
if [[ "$BATS_TEST_DESCRIPTION" != *"basic web-app"* ]]; then
return
fi

pushd $OCKAM_HOME_BASE
pushd $OCKAM_HOME_BASE/.tmp

cat >main.py <<-EOM
import os
Expand Down Expand Up @@ -47,11 +49,11 @@ EOM
}

kill_flask_server() {
if [[ "$BATS_TEST_DESCRIPTION" != *"basic-web-app"* ]]; then
if [[ "$BATS_TEST_DESCRIPTION" != *"basic web-app"* ]]; then
return
fi

pid=$(cat "${OCKAM_HOME_BASE}/flask.pid")
pid=$(cat "${OCKAM_HOME_BASE}/.tmp/flask.pid")
kill -9 "$pid" || true
wait "$pid" 2>/dev/null || true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,10 @@ EOF
# https://docs.ockam.io/guides/examples/basic-web-app
# Please update the docs repository if this bats test is updated
@test "use-case - basic web-app, single machine" {
MACHINE_A="$OCKAM_HOME"
export OCKAM_PG_PORT=$(random_port)
relay_name=$(random_str)
export OCKAM_PG_PORT=$(random_port)
run_success $OCKAM tcp-outlet create --to "$PG_HOST:$PG_PORT"
run_success $OCKAM relay create "$relay_name"

run_success $OCKAM tcp-inlet create --from $OCKAM_PG_PORT --via "$relay_name"

# Kickstart webserver
Expand All @@ -214,21 +212,21 @@ EOF
run_success start_python_server

# Visit website
run_success curl -sf -m 5 "http://127.0.0.1:$FLASK_PORT"
run_success curl -f -m 5 "http://127.0.0.1:$FLASK_PORT"
assert_output --partial "I've been visited 1 times"

# Visit website second time
run_success curl -sf -m 5 "http://127.0.0.1:$FLASK_PORT"
run_success curl -f -m 5 "http://127.0.0.1:$FLASK_PORT"
assert_output --partial "I've been visited 2 times"

run_success kill_flask_server
}

@test "use-case - basic-web-app, multiple machines" {
MACHINE_A="$OCKAM_HOME"
@test "use-case - basic web-app, multiple machines" {
relay_name=$(random_str)

# On machine A
MACHINE_A="$OCKAM_HOME"
run_success bash -c "$OCKAM project ticket --usage-count 10 --attribute component=db --relay ${relay_name} > ${MACHINE_A}/db.ticket"
run_success bash -c "$OCKAM project ticket --usage-count 10 --attribute component=web > ${MACHINE_A}/webapp.ticket"

Expand All @@ -253,9 +251,9 @@ EOF
run_success start_python_server

# Visit website
run_success curl -sf -m 5 "http://127.0.0.1:$FLASK_PORT"
run_success curl -f -m 5 "http://127.0.0.1:$FLASK_PORT"
assert_output --partial "I've been visited 3 times"
# Visit website second time
run_success curl -sf -m 5 "http://127.0.0.1:$FLASK_PORT"
run_success curl -f -m 5 "http://127.0.0.1:$FLASK_PORT"
assert_output --partial "I've been visited 4 times"
}

0 comments on commit 7f78b0e

Please sign in to comment.