test 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash -e
  2. #
  3. # Run all etcd tests
  4. # ./test
  5. # ./test -v
  6. #
  7. # Run tests for one package
  8. #
  9. # PKG=./wal ./test
  10. # PKG=snap ./test
  11. # Invoke ./cover for HTML output
  12. COVER=${COVER:-"-cover"}
  13. source ./build
  14. # Hack: gofmt ./ will recursively check the .git directory. So use *.go for gofmt.
  15. TESTABLE_AND_FORMATTABLE="client discovery error etcdctl/command etcdmain etcdserver etcdserver/auth etcdserver/etcdhttp etcdserver/etcdhttp/httptypes migrate pkg/fileutil pkg/flags pkg/idutil pkg/ioutil pkg/netutil pkg/osutil pkg/pbutil pkg/types pkg/transport pkg/wait proxy raft snap store version wal"
  16. # TODO: add it to race testing when the issue is resolved
  17. # https://github.com/golang/go/issues/9946
  18. NO_RACE_TESTABLE="rafthttp"
  19. FORMATTABLE="$TESTABLE_AND_FORMATTABLE $NO_RACE_TESTABLE *.go etcdctl/ integration"
  20. # user has not provided PKG override
  21. if [ -z "$PKG" ]; then
  22. TEST=$TESTABLE_AND_FORMATTABLE
  23. NO_RACE_TEST=$NO_RACE_TESTABLE
  24. FMT=$FORMATTABLE
  25. # user has provided PKG override
  26. else
  27. # strip out leading dotslashes and trailing slashes from PKG=./foo/
  28. TEST=${PKG/#./}
  29. TEST=${TEST/#\//}
  30. TEST=${TEST/%\//}
  31. # only run gofmt on packages provided by user
  32. FMT="$TEST"
  33. fi
  34. # split TEST into an array and prepend REPO_PATH to each local package
  35. split=(${TEST// / })
  36. TEST=${split[@]/#/${REPO_PATH}/}
  37. split=(${NO_RACE_TEST// / })
  38. NO_RACE_TEST=${split[@]/#/${REPO_PATH}/}
  39. echo "Running tests..."
  40. MACHINE_TYPE=$(uname -m)
  41. if [ $MACHINE_TYPE != "armv7l" ]; then
  42. RACE="--race"
  43. fi
  44. go test -timeout 3m ${COVER} $@ ${TEST} ${RACE} -cpu 1,2,4
  45. go test -timeout 3m ${COVER} $@ ${NO_RACE_TEST} -cpu 1,2,4
  46. if [ -n "$INTEGRATION" ]; then
  47. echo "Running integration tests..."
  48. go test -timeout 10m $@ ${REPO_PATH}/integration -v -cpu 1,2,4
  49. fi
  50. echo "Checking gofmt..."
  51. fmtRes=$(gofmt -l $FMT)
  52. if [ -n "${fmtRes}" ]; then
  53. echo -e "gofmt checking failed:\n${fmtRes}"
  54. exit 255
  55. fi
  56. echo "Checking govet..."
  57. vetRes=$(go vet $TEST)
  58. if [ -n "${vetRes}" ]; then
  59. echo -e "govet checking failed:\n${vetRes}"
  60. exit 255
  61. fi
  62. if command -v go-nyet >/dev/null 2>&1; then
  63. echo "Checking go-nyet..."
  64. nyetRes=$(go-nyet -exitWith 0 $FMT)
  65. if [ -n "${nyetRes}" ]; then
  66. echo -e "go-nyet checking failed:\n${nyetRes}"
  67. exit 255
  68. fi
  69. fi
  70. echo "Success"