aboutsummaryrefslogtreecommitdiffstats
path: root/test_status.sh
blob: ae28199593a4c61097a511549521dffb54882d7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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"