test 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. go test -timeout 3m ${COVER} $@ ${TEST} --race -cpu 1,2,4
  41. go test -timeout 3m ${COVER} $@ ${NO_RACE_TEST} -cpu 1,2,4
  42. if [ -n "$INTEGRATION" ]; then
  43. echo "Running integration tests..."
  44. go test -timeout 10m $@ ${REPO_PATH}/integration -v -cpu 1,2,4
  45. fi
  46. echo "Checking gofmt..."
  47. fmtRes=$(gofmt -l $FMT)
  48. if [ -n "${fmtRes}" ]; then
  49. echo -e "gofmt checking failed:\n${fmtRes}"
  50. exit 255
  51. fi
  52. echo "Checking govet..."
  53. vetRes=$(go vet $TEST)
  54. if [ -n "${vetRes}" ]; then
  55. echo -e "govet checking failed:\n${vetRes}"
  56. exit 255
  57. fi
  58. if command -v go-nyet >/dev/null 2>&1; then
  59. echo "Checking go-nyet..."
  60. nyetRes=$(go-nyet -exitWith 0 $FMT)
  61. if [ -n "${nyetRes}" ]; then
  62. echo -e "go-nyet checking failed:\n${nyetRes}"
  63. exit 255
  64. fi
  65. fi
  66. echo "Success"