aboutsummaryrefslogtreecommitdiffstats
path: root/test_status.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test_status.sh')
-rwxr-xr-xtest_status.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/test_status.sh b/test_status.sh
new file mode 100755
index 0000000..ae28199
--- /dev/null
+++ b/test_status.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# Check the task-response parser against the four shapes the API returns.
+# Run: ./test_status.sh
+set -euo pipefail
+cd "$(dirname "$0")"
+
+# shellcheck disable=SC1091
+status() { sed -n '/^status()/,/^}/p' pput | sed '1d;$d' | bash -s; }
+
+check() {
+ got=$(printf '%s' "$2" | bash -c "$(sed -n '/^status()/,/^}/p' pput); status")
+ [ "$got" = "$(printf '%b' "$3")" ] \
+ && echo "ok $1" \
+ || { echo "FAIL $1: got [$got] want [$(printf '%b' "$3")]" >&2; exit 1; }
+}
+
+check "empty results" '{"results":[]}' 'pending\t'
+check "pending" '{"results":[{"status":"pending","result_data":null}]}' 'pending\t'
+check "success" '{"results":[{"status":"success","result_data":{"document_id":46}}]}' 'success\tdoc 46'
+check "duplicate" '{"results":[{"status":"failure","result_data":{"duplicate_of":45,"duplicate_in_trash":false}}]}' 'failure\tduplicate of doc 45'
+check "dup in trash" '{"results":[{"status":"failure","result_data":{"duplicate_of":9,"duplicate_in_trash":true}}]}' 'failure\tduplicate of doc 9 (in trash)'
+check "other error" '{"results":[{"status":"failure","result_data":{"error":"bad mime"}}]}' 'failure\tbad mime'
+echo "all passed"