test 2.2 KB

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