test 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/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 rafthttp snap store version wal"
  16. FORMATTABLE="$TESTABLE_AND_FORMATTABLE *.go etcdctl/ integration"
  17. # user has not provided PKG override
  18. if [ -z "$PKG" ]; then
  19. TEST=$TESTABLE_AND_FORMATTABLE
  20. FMT=$FORMATTABLE
  21. # user has provided PKG override
  22. else
  23. # strip out leading dotslashes and trailing slashes from PKG=./foo/
  24. TEST=${PKG/#./}
  25. TEST=${TEST/#\//}
  26. TEST=${TEST/%\//}
  27. # only run gofmt on packages provided by user
  28. FMT="$TEST"
  29. fi
  30. # split TEST into an array and prepend REPO_PATH to each local package
  31. split=(${TEST// / })
  32. TEST=${split[@]/#/${REPO_PATH}/}
  33. echo "Running tests..."
  34. go test -timeout 3m ${COVER} $@ ${TEST} --race
  35. if [ -n "$INTEGRATION" ]; then
  36. echo "Running integration tests..."
  37. go test -timeout 3m $@ ${REPO_PATH}/integration
  38. fi
  39. echo "Checking gofmt..."
  40. fmtRes=$(gofmt -l $FMT)
  41. if [ -n "${fmtRes}" ]; then
  42. echo -e "gofmt checking failed:\n${fmtRes}"
  43. exit 255
  44. fi
  45. echo "Checking govet..."
  46. vetRes=$(go vet $TEST)
  47. if [ -n "${vetRes}" ]; then
  48. echo -e "govet checking failed:\n${vetRes}"
  49. exit 255
  50. fi
  51. if command -v go-nyet >/dev/null 2>&1; then
  52. echo "Checking go-nyet..."
  53. nyetRes=$(go-nyet -exitWith 0 $FMT)
  54. if [ -n "${nyetRes}" ]; then
  55. echo -e "go-nyet checking failed:\n${nyetRes}"
  56. exit 255
  57. fi
  58. fi
  59. echo "Success"