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.

57 lines
1.5 KiB

8 years ago
  1. #! /bin/bash
  2. set -e
  3. go build -o server main.go
  4. ./server > /dev/null &
  5. PID=$!
  6. sleep 2
  7. # simple request
  8. R1=`curl -s 'http://localhost:8008/hello_world?name="my_world"&num=5'`
  9. R2=`curl -s --data @data.json http://localhost:8008`
  10. if [[ "$R1" != "$R2" ]]; then
  11. echo "responses are not identical:"
  12. echo "R1: $R1"
  13. echo "R2: $R2"
  14. exit 1
  15. else
  16. echo "Success"
  17. fi
  18. # request with 0x-prefixed hex string arg
  19. R1=`curl -s 'http://localhost:8008/hello_world?name=0x41424344&num=123'`
  20. R2='{"jsonrpc":"2.0","id":"","result":{"Result":"hi ABCD 123"},"error":""}'
  21. if [[ "$R1" != "$R2" ]]; then
  22. echo "responses are not identical:"
  23. echo "R1: $R1"
  24. echo "R2: $R2"
  25. exit 1
  26. else
  27. echo "Success"
  28. fi
  29. # request with unquoted string arg
  30. R1=`curl -s 'http://localhost:8008/hello_world?name=abcd&num=123'`
  31. R2="{\"jsonrpc\":\"2.0\",\"id\":\"\",\"result\":null,\"error\":\"Error converting http params to args: invalid character 'a' looking for beginning of value\"}"
  32. if [[ "$R1" != "$R2" ]]; then
  33. echo "responses are not identical:"
  34. echo "R1: $R1"
  35. echo "R2: $R2"
  36. exit 1
  37. else
  38. echo "Success"
  39. fi
  40. # request with string type when expecting number arg
  41. R1=`curl -s 'http://localhost:8008/hello_world?name="abcd"&num=0xabcd'`
  42. R2="{\"jsonrpc\":\"2.0\",\"id\":\"\",\"result\":null,\"error\":\"Error converting http params to args: Got a hex string arg, but expected 'int'\"}"
  43. if [[ "$R1" != "$R2" ]]; then
  44. echo "responses are not identical:"
  45. echo "R1: $R1"
  46. echo "R2: $R2"
  47. exit 1
  48. else
  49. echo "Success"
  50. fi
  51. kill -9 $PID || exit 0