tendermint/test/test.sh

70 lines
1.6 KiB
Bash
Raw Normal View History

2016-06-23 17:36:59 -07:00
#! /bin/bash
2017-01-12 18:59:02 -08:00
cd $GOPATH/src/github.com/tendermint/go-rpc
# get deps
go get -u -t ./...
# go tests
go test --race github.com/tendermint/go-rpc/...
# integration tests
cd test
2016-06-23 17:36:59 -07:00
set -e
go build -o server main.go
./server > /dev/null &
PID=$!
sleep 2
# simple request
2016-06-23 17:36:59 -07:00
R1=`curl -s 'http://localhost:8008/hello_world?name="my_world"&num=5'`
R2=`curl -s --data @data.json http://localhost:8008`
if [[ "$R1" != "$R2" ]]; then
echo "responses are not identical:"
echo "R1: $R1"
echo "R2: $R2"
2017-01-07 14:00:27 -08:00
exit 1
else
echo "Success"
fi
2016-06-23 17:36:59 -07:00
# request with 0x-prefixed hex string arg
R1=`curl -s 'http://localhost:8008/hello_world?name=0x41424344&num=123'`
R2='{"jsonrpc":"2.0","id":"","result":{"Result":"hi ABCD 123"},"error":""}'
if [[ "$R1" != "$R2" ]]; then
echo "responses are not identical:"
echo "R1: $R1"
echo "R2: $R2"
2017-01-07 14:00:27 -08:00
exit 1
else
echo "Success"
fi
2016-06-23 17:36:59 -07:00
# request with unquoted string arg
R1=`curl -s 'http://localhost:8008/hello_world?name=abcd&num=123'`
R2="{\"jsonrpc\":\"2.0\",\"id\":\"\",\"result\":null,\"error\":\"Error converting http params to args: invalid character 'a' looking for beginning of value\"}"
2016-06-23 17:36:59 -07:00
if [[ "$R1" != "$R2" ]]; then
echo "responses are not identical:"
echo "R1: $R1"
echo "R2: $R2"
2017-01-07 14:00:27 -08:00
exit 1
else
echo "Success"
2016-06-23 17:36:59 -07:00
fi
# request with string type when expecting number arg
R1=`curl -s 'http://localhost:8008/hello_world?name="abcd"&num=0xabcd'`
2017-01-12 07:22:23 -08:00
R2="{\"jsonrpc\":\"2.0\",\"id\":\"\",\"result\":null,\"error\":\"Error converting http params to args: Got a hex string arg, but expected 'int'\"}"
if [[ "$R1" != "$R2" ]]; then
echo "responses are not identical:"
echo "R1: $R1"
echo "R2: $R2"
exit 1
else
echo "Success"
fi
kill -9 $PID || exit 0