121 lines
3.3 KiB
Bash
121 lines
3.3 KiB
Bash
#!/bin/bash
|
||
set -e
|
||
|
||
if [ "$#" -ne 1 ] || [ \! -x "$1" ] ; then
|
||
echo "Wrong arguments! Must supply path to shinyr executeable!"
|
||
exit 2
|
||
fi
|
||
|
||
SHINYR="$1"
|
||
|
||
TCUR=-1
|
||
|
||
fail_msg() {
|
||
echo "FAILED on test: $TCUR"
|
||
exit 1
|
||
}
|
||
|
||
trap fail_msg EXIT
|
||
|
||
TCUR="api2db"
|
||
res="$("$SHINYR" api2db AwnW35HP3S0ADNCM76)"
|
||
[ "$res" = "00000198-70ad-868e-8d3a-6d2726850000" ]
|
||
|
||
TCUR="db2api"
|
||
res="$("$SHINYR" db2api 00000198-70ad-868e-8d3a-6d2726850000)"
|
||
[ "$res" = "AwnW35HP3S0ADNCM76" ]
|
||
|
||
TCUR="api2db legacy id"
|
||
res="$("$SHINYR" api2db 123)"
|
||
[ "$res" = "00000000-0000-0000-0000-00000000007b" ]
|
||
|
||
TCUR="db2api legacy id"
|
||
res="$("$SHINYR" db2api 00000000-0000-0000-0000-00000000007b)"
|
||
[ "$res" = "123" ]
|
||
|
||
TCUR="db2api max value"
|
||
res="$("$SHINYR" db2api FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 2>&1)"
|
||
[ "$res" = "7n42DGM5Tflk9n8mt7Fhc7" ]
|
||
|
||
TCUR="db2api too large (just barely)"
|
||
exc=0
|
||
res="$("$SHINYR" db2api 100000000000000000000000000000000 2>&1)" || exc="$?"
|
||
[ "$exc" -eq 1 ] && echo "$res" | grep -q 'too big'
|
||
|
||
TCUR="db2api too large (a lot)"
|
||
exc=0
|
||
res="$("$SHINYR" db2api 3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 2>&1)" || exc="$?"
|
||
[ "$exc" -eq 1 ] && echo "$res" | grep -q 'too big'
|
||
|
||
TCUR="api2db max value"
|
||
res="$("$SHINYR" api2db 7n42DGM5Tflk9n8mt7Fhc7 2>&1)"
|
||
[ "$res" = "ffffffff-ffff-ffff-ffff-ffffffffffff" ]
|
||
|
||
TCUR="api2db too large (just barely)"
|
||
exc=0
|
||
res="$("$SHINYR" api2db 7n42DGM5Tflk9n8mt7Fhc8 2>&1)" || exc="$?"
|
||
[ "$exc" -eq 1 ] && echo "$res" | grep -q 'too big'
|
||
|
||
TCUR="api2db too large (a lot)"
|
||
exc=0
|
||
res="$("$SHINYR" api2db 17n42DGM5Tflk9n8mt7Fhc9 2>&1)" || exc="$?"
|
||
[ "$exc" -eq 1 ] && echo "$res" | grep -q 'too big'
|
||
|
||
# exhausitively test base62’s individual char de- and encoding
|
||
prefix_de="00000000-0000-0000-0000-0000000000"
|
||
prefix_en="2d227003d8d2af8" # = 62^11 > 2^64
|
||
exval=0
|
||
for i in {0..9} {A..Z} {a..z} ; do
|
||
TCUR="base62 decode $i -> $exval"
|
||
expected="$(printf '%s%02x' "$prefix_de" "$exval")"
|
||
res="$("$SHINYR" api2db "$i")"
|
||
[ "$res" = "$expected" ]
|
||
|
||
# need to use input ≥ 2^64 to avoid decimal legacy-id output
|
||
TCUR="base62 encode $exval -> $i"
|
||
input="$(printf '%s%02x' "$prefix_en" "$exval")"
|
||
expected="10000000000${i}"
|
||
res="$("$SHINYR" db2api "$input")"
|
||
[ "$res" = "$expected" ]
|
||
|
||
exval="$((exval + 1))"
|
||
done
|
||
TCUR="META: de/encoder test iterates everything"
|
||
[ "$exval" -eq 62 ]
|
||
|
||
# common among time (success) tests
|
||
expect="1752612828187"
|
||
|
||
TCUR="time from implicit API ID"
|
||
res="$("$SHINYR" time AwAY5w3CVlXYAv5Gu8)"
|
||
[ "$res" = "$expect" ]
|
||
|
||
TCUR="time from explicit API ID"
|
||
res="$("$SHINYR" time -f api AwAY5w3CVlXYAv5Gu8)" || echo "FAIL $? $res"
|
||
[ "$res" = "$expect" ] || echo "EXPECTED: $expect GOT $res"
|
||
|
||
TCUR="time from implicit database ID"
|
||
res="$("$SHINYR" time 00000198-0fdd-741b-30e3-35c5c83e0000)"
|
||
[ "$res" = "$expect" ]
|
||
|
||
TCUR="time from explicit database ID"
|
||
res="$("$SHINYR" time -f db 00000198-0fdd-741b-30e3-35c5c83e0000)"
|
||
[ "$res" = "$expect" ]
|
||
|
||
TCUR="time fails on invalid ID"
|
||
exc=0
|
||
res="$("$SHINYR" time SGlpaSF+Cg 2>&1)" || exc="$?"
|
||
[ "$exc" -eq 1 ] && echo "$res" | grep -q 'Invalid'
|
||
|
||
TCUR="time fails when getting API for db id"
|
||
exc=0
|
||
res="$("$SHINYR" time -f db AwAY5w3CVlXYAv5Gu8 2>&1)" || exc="$?"
|
||
[ "$exc" -eq 1 ] && echo "$res" | grep -q 'Invalid'
|
||
|
||
TCUR="time fails when getting db for API id"
|
||
exc=0
|
||
res="$("$SHINYR" time -f api 00000198-0fdd-741b-30e3-35c5c83e0000 2>&1)" || exc="$?"
|
||
[ "$exc" -eq 1 ] && echo "$res" | grep -q 'Invalid'
|
||
|
||
trap - EXIT
|
||
echo "ALL GOOD"
|