test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 clientv3 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 storage storage/backend 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 clientv3/integration e2e"
  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. function unit_tests {
  41. echo "Running tests..."
  42. MACHINE_TYPE=$(uname -m)
  43. if [ $MACHINE_TYPE != "armv7l" ]; then
  44. RACE="--race"
  45. fi
  46. go test -timeout 3m ${COVER} ${RACE} -cpu 1,2,4 $@ ${TEST}
  47. go test -timeout 3m ${COVER} -cpu 1,2,4 $@ ${NO_RACE_TEST}
  48. }
  49. function integration_tests {
  50. echo "Running integration tests..."
  51. go test -timeout 10m -v -cpu 1,2,4 $@ ${REPO_PATH}/e2e
  52. go test -timeout 15m -v -cpu 1,2,4 $@ ${REPO_PATH}/integration
  53. go test -timeout 10m -v -cpu 1,2,4 $@ ${REPO_PATH}/clientv3/integration
  54. go test -timeout 1m -v -cpu 1,2,4 $@ ${REPO_PATH}/contrib/raftexample
  55. }
  56. function fmt_tests {
  57. echo "Checking gofmt..."
  58. fmtRes=$(gofmt -l -s -d $FMT)
  59. if [ -n "${fmtRes}" ]; then
  60. echo -e "gofmt checking failed:\n${fmtRes}"
  61. exit 255
  62. fi
  63. echo "Checking govet..."
  64. vetRes=$(go vet $TEST)
  65. if [ -n "${vetRes}" ]; then
  66. echo -e "govet checking failed:\n${vetRes}"
  67. exit 255
  68. fi
  69. echo "Checking govet -shadow..."
  70. for path in $FMT; do
  71. vetRes=$(go tool vet -shadow ${path})
  72. if [ -n "${vetRes}" ]; then
  73. echo -e "govet checking ${path} failed:\n${vetRes}"
  74. exit 255
  75. fi
  76. done
  77. echo "Checking for license header..."
  78. licRes=$(for file in $(find . -type f -iname '*.go' ! -path './Godeps/*'); do
  79. head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" || echo -e " ${file}"
  80. done;)
  81. if [ -n "${licRes}" ]; then
  82. echo -e "license header checking failed:\n${licRes}"
  83. exit 255
  84. fi
  85. }
  86. # fail fast on formatting tests
  87. fmt_tests
  88. unit_tests
  89. if [ -n "$INTEGRATION" ]; then
  90. integration_tests
  91. fi
  92. echo "Success"