You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 lines
3.0 KiB

#!/usr/bin/env bash
# No real need to use stderr here since it's just tests.
set -eE
shellcheck "$0"
# Before we build...
go fmt
go doc -all
go test
go build
strip -s rantbin
mkdir test_dir
cd test_dir
../rantbin :2222 &
PID=$!
# So, there's a bug in shellcheck where disabling SC2103 doesn't work.
# shellcheck disable=SC2103
# cd ..
cd "$(echo .. | grep .)"
cleanup() {
echo "Cleaning up."
rm -r test_dir
kill "$PID"
}
fail() {
echo "$1"
cleanup
exit 1
}
trap fail $(seq 1 64)
# Be sure we are running.
sleep 2
# Functional tests.
echo test | curl -s --show-error --fail --data-urlencode data@- "http://localhost:2222"/feedback || fail "Should be able to write.."
[ -f "test_dir/f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2" ] || fail "Output file not created."
echo -n | curl -s --show-error --fail --data-urlencode data@- "http://localhost:2222"/feedback && fail "Should error on empty input."
# This is.. approximate because it's URL encoded.
yes 2> /dev/null | head -c 4096 | curl -s --show-error --fail --data-urlencode data@- "http://localhost:2222"/feedback || fail "Should allow a 4096 byte post."
yes 2> /dev/null | head -c 4097 | curl -s --show-error --fail --data-urlencode data@- "http://localhost:2222"/feedback && fail "Should fail on anything greater than 4096 bytes."
[ "$(wc -l test_dir/309a1668b23adc98b0ec1b67d55bdca1e89e9d81c0930d5baf9b85df85d76ee0)" != "4096" ] || fail "4096 byte file wrong length or checksum???"
yes 2> /dev/null | head -c 4096 | curl -s --show-error --fail --data-urlencode data@- "http://localhost:2222"/feedback && fail "Shouldn't be able to write the same message twice."
ls -1 test_dir
# Start over for final max files test.
rm test_dir/*
for i in $(seq 1 128); do
yes 2> /dev/null | head -c "$i" | curl -s --show-error --fail --data-urlencode data@- "http://localhost:2222"/feedback || fail "Should be able to add file number $i"
done
echo test | curl -s --show-error --fail --data-urlencode data@- "http://localhost:2222"/feedback && fail "Should not be able to make more than 128 feedbacks."
[ "$(find test_dir/ -type f | wc -l)" -ne 128 ] && fail "We don't have exactly 128 files??"
# Start over for page feature test.
rm test_dir/*
echo test | curl -s --show-error --fail -d page=/index.html --data-urlencode data@- "http://localhost:2222"/feedback || fail "Should be able to write with page.."
[ -f "test_dir/35ebe6e8dab05c744864f4fcc3a21f1d16c01a79be0257169d82894ae879970b" ] || fail "Output file with page not created."
yes 2> /dev/null | tr -d '\n' | head -c 256 | curl -s --show-error --fail --data-urlencode page@- -d data=test "http://localhost:2222"/feedback || fail "Should be able to write with 256 byte page"
[ -f "test_dir/b287a5c7db0e96917aca6c9751a3f5e890d6d92ab093f826b6ed5d5c8948df41" ] || fail "Output file with longest page not created."
yes 2> /dev/null | tr -d '\n' | head -c 257 | curl -s --show-error --fail --data-urlencode page@- -d data=test "http://localhost:2222"/feedback && fail "Should NOT be able to write with 257 byte page"
cleanup
echo Success.