diff options
| author | Egor Tensin <egor@tensin.name> | 2026-09-30 11:45:02 +0500 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-09-30 12:00:50 +0500 |
| commit | ff590ddb9ade2de0f21fe5a6d4880752fa143e87 (patch) | |
| tree | 7020de8df559265b88be647ca03e73590bde1f34 /test/tst-cgi.sh | |
| parent | Makefile: fix Debian builds (diff) | |
| download | linux-status-ff590ddb9ade2de0f21fe5a6d4880752fa143e87.tar.gz linux-status-ff590ddb9ade2de0f21fe5a6d4880752fa143e87.zip | |
test: rework using the approach from my other projects
The tests are now run using a framework common to my other projects,
like config-links, tag-release & vk-scripts.
Diffstat (limited to 'test/tst-cgi.sh')
| -rw-r--r-- | test/tst-cgi.sh | 48 |
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' +} |
