test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. GO_BUILD_FLAGS=-a
  15. source ./build
  16. # Hack: gofmt ./ will recursively check the .git directory. So use *.go for gofmt.
  17. 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"
  18. # TODO: add it to race testing when the issue is resolved
  19. # https://github.com/golang/go/issues/9946
  20. NO_RACE_TESTABLE="rafthttp"
  21. FORMATTABLE="$TESTABLE_AND_FORMATTABLE $NO_RACE_TESTABLE *.go etcdctl/ integration clientv3/integration e2e"
  22. # user has not provided PKG override
  23. if [ -z "$PKG" ]; then
  24. TEST=$TESTABLE_AND_FORMATTABLE
  25. NO_RACE_TEST=$NO_RACE_TESTABLE
  26. FMT=$FORMATTABLE
  27. # user has provided PKG override
  28. else
  29. # strip out leading dotslashes and trailing slashes from PKG=./foo/
  30. TEST=${PKG/#./}
  31. TEST=${TEST/#\//}
  32. TEST=${TEST/%\//}
  33. # only run gofmt on packages provided by user
  34. FMT="$TEST"
  35. fi
  36. # split TEST into an array and prepend REPO_PATH to each local package
  37. split=(${TEST// / })
  38. TEST=${split[@]/#/${REPO_PATH}/}
  39. split=(${NO_RACE_TEST// / })
  40. NO_RACE_TEST=${split[@]/#/${REPO_PATH}/}
  41. function unit_tests {
  42. echo "Running tests..."
  43. MACHINE_TYPE=$(uname -m)
  44. if [ $MACHINE_TYPE != "armv7l" ]; then
  45. RACE="--race"
  46. fi
  47. go test -timeout 3m ${COVER} ${RACE} -cpu 1,2,4 $@ ${TEST}
  48. go test -timeout 3m ${COVER} -cpu 1,2,4 $@ ${NO_RACE_TEST}
  49. }
  50. function integration_tests {
  51. echo "Running integration tests..."
  52. go test -timeout 10m -v -cpu 1,2,4 $@ ${REPO_PATH}/e2e
  53. go test -timeout 15m -v -cpu 1,2,4 $@ ${REPO_PATH}/integration
  54. go test -timeout 10m -v -cpu 1,2,4 $@ ${REPO_PATH}/clientv3/integration
  55. go test -timeout 1m -v -cpu 1,2,4 $@ ${REPO_PATH}/contrib/raftexample
  56. }
  57. function fmt_tests {
  58. echo "Checking gofmt..."
  59. fmtRes=$(gofmt -l -s -d $FMT)
  60. if [ -n "${fmtRes}" ]; then
  61. echo -e "gofmt checking failed:\n${fmtRes}"
  62. exit 255
  63. fi
  64. # echo "Checking govet..."
  65. # vetRes=$(go vet $TEST)
  66. # if [ -n "${vetRes}" ]; then
  67. # echo -e "govet checking failed:\n${vetRes}"
  68. # exit 255
  69. # fi
  70. # echo "Checking govet -shadow..."
  71. # for path in $FMT; do
  72. # vetRes=$(go tool vet -shadow ${path})
  73. # if [ -n "${vetRes}" ]; then
  74. # echo -e "govet checking ${path} failed:\n${vetRes}"
  75. # exit 255
  76. # fi
  77. # done
  78. echo "Checking for license header..."
  79. licRes=$(for file in $(find . -type f -iname '*.go' ! -path './Godeps/*'); do
  80. head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" || echo -e " ${file}"
  81. done;)
  82. if [ -n "${licRes}" ]; then
  83. echo -e "license header checking failed:\n${licRes}"
  84. exit 255
  85. fi
  86. }
  87. function dep_tests {
  88. echo "Checking package dependencies..."
  89. # don't pull in etcdserver package
  90. pushd clientv3 >/dev/null
  91. badpkg="(etcdserver|storage)"
  92. deps=`go list -f '{{ .Deps }}' | sed 's/ /\n/g' | egrep "${badpkg}" | egrep -v "${badpkg}/" || echo ""`
  93. popd >/dev/null
  94. if [ ! -z "$deps" ]; then
  95. echo -e "clientv3 has masked dependencies:\n${deps}"
  96. exit 255
  97. fi
  98. }
  99. # fail fast on static tests
  100. fmt_tests
  101. dep_tests
  102. unit_tests
  103. if [ -n "$INTEGRATION" ]; then
  104. integration_tests
  105. fi
  106. echo "Success"