aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/tst-cgi.sh
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-10-04 21:41:24 +0500
committerEgor Tensin <egor@tensin.name>2026-10-04 21:41:24 +0500
commit57109eace4733153d4897cce42e44520f4efffae (patch)
treea220463377c288cad059fc587078b08a1e7d7f63 /test/tst-cgi.sh
parentdebian: ditch Vagrant, switch to Docker (diff)
parentworkflows/ci: minor formatting fixes (diff)
downloadlinux-status-57109eace4733153d4897cce42e44520f4efffae.tar.gz
linux-status-57109eace4733153d4897cce42e44520f4efffae.zip
Merge tag 'v2.4.13' into debian
v2.4.13
Diffstat (limited to 'test/tst-cgi.sh')
-rw-r--r--test/tst-cgi.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/tst-cgi.sh b/test/tst-cgi.sh
new file mode 100644
index 0000000..bb2eb01
--- /dev/null
+++ b/test/tst-cgi.sh
@@ -0,0 +1,48 @@
+test_cgi_response=
+
+_test_cgi_check_status() {
+ local expected='200 OK'
+ local actual
+ actual="$( head -n 1 -- "$test_cgi_response" )"
+
+ [ "$expected" == "$actual" ] && return 0
+
+ fail "Unexpected HTTP status: $actual"
+ fail_details "Expected: $expected"
+
+ diff <( echo "$actual" ) <( echo "$expected" ) | cat -te >&2
+ return 1
+}
+
+_test_cgi() {
+ if [ "$#" -lt 1 ]; then
+ log "usage: ${FUNCNAME[0]} WHAT [KEYWORD...]"
+ return 1
+ fi
+
+ local what="$1"
+ shift
+
+ local query_string="what=$what"
+ log "Running CGI test for query string: $query_string"
+
+ QUERY_STRING="$query_string" "$script_dir/../src/app.py" > "$test_cgi_response"
+
+ _test_cgi_check_status
+ test_check_output "$test_cgi_response" "$@"
+}
+
+test_run() {
+ # Check that app.py still works as a CGI script.
+
+ test_setup
+
+ test_cgi_response="$test_root_dir/response"
+
+ # /status returns a JSON with a number of fields:
+ _test_cgi 'status' '"hostname":' '"thermal":' '"system":' '"user":'
+ # /top is `top` output:
+ _test_cgi 'top' 'load average:'
+ # /thermal is also an endpoint:
+ _test_cgi 'thermal'
+}