test 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. #!/usr/bin/env bash
  2. #
  3. # Run all etcd tests
  4. # ./test
  5. # ./test -v
  6. #
  7. #
  8. # Run specified test pass
  9. #
  10. # $ PASSES=unit ./test
  11. # $ PASSES=integration ./test
  12. #
  13. #
  14. # Run tests for one package
  15. # Each pass has different default timeout, if you just run tests in one package or 1 test case then you can set TIMEOUT
  16. # flag for different expectation
  17. #
  18. # $ PASSES=unit PKG=./wal TIMEOUT=1m ./test
  19. # $ PASSES=integration PKG=client/integration TIMEOUT=1m ./test
  20. #
  21. #
  22. # Run specified unit tests in one package
  23. # To run all the tests with prefix of "TestNew", set "TESTCASE=TestNew ";
  24. # to run only "TestNew", set "TESTCASE="\bTestNew\b""
  25. #
  26. # $ PASSES=unit PKG=./wal TESTCASE=TestNew TIMEOUT=1m ./test
  27. # $ PASSES=unit PKG=./wal TESTCASE="\bTestNew\b" TIMEOUT=1m ./test
  28. # $ PASSES=integration PKG=client/integration TESTCASE="\bTestV2NoRetryEOF\b" TIMEOUT=1m ./test
  29. #
  30. #
  31. # Run code coverage
  32. # COVERDIR must either be a absolute path or a relative path to the etcd root
  33. # $ COVERDIR=coverage PASSES="build_cov cov" ./test
  34. set -e
  35. source ./build
  36. # build before setting up test GOPATH
  37. if [[ "${PASSES}" == *"functional"* ]]; then
  38. ./functional/build
  39. fi
  40. # build tests with vendored dependencies
  41. etcd_setup_gopath
  42. if [ -z "$PASSES" ]; then
  43. PASSES="fmt bom dep build unit"
  44. fi
  45. USERPKG=${PKG:-}
  46. # Invoke ./tests/cover.test.bash for HTML output
  47. COVER=${COVER:-"-cover"}
  48. # Hack: gofmt ./ will recursively check the .git directory. So use *.go for gofmt.
  49. IGNORE_PKGS="(cmd/|etcdserverpb|rafttest|gopath.proto|v3lockpb|v3electionpb)"
  50. INTEGRATION_PKGS="(integration|e2e|contrib|functional)"
  51. # all github.com/coreos/etcd/whatever pkgs that are not auto-generated / tools
  52. # shellcheck disable=SC1117
  53. PKGS=$(find . -name \*.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | grep -vE "(tools/|contrib/|e2e|pb)" | sed "s|\.|${REPO_PATH}|g" | xargs echo)
  54. # pkg1,pkg2,pkg3
  55. PKGS_COMMA=${PKGS// /,}
  56. # shellcheck disable=SC1117
  57. TEST_PKGS=$(find . -name \*_test.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
  58. # shellcheck disable=SC1117
  59. FORMATTABLE=$(find . -name \*.go | while read -r a; do echo "$(dirname "$a")/*.go"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
  60. TESTABLE_AND_FORMATTABLE=$(echo "$TEST_PKGS" | grep -vE "$INTEGRATION_PKGS")
  61. # check if user provided PKG override
  62. if [ -z "${USERPKG}" ]; then
  63. TEST=$TESTABLE_AND_FORMATTABLE
  64. FMT=$FORMATTABLE
  65. else
  66. # strip out leading dotslashes and trailing slashes from PKG=./foo/
  67. TEST=${USERPKG/#./}
  68. TEST=${TEST/#\//}
  69. TEST=${TEST/%\//}
  70. # only run gofmt on packages provided by user
  71. FMT="$TEST"
  72. fi
  73. # shellcheck disable=SC2206
  74. FMT=($FMT)
  75. # prepend REPO_PATH to each local package
  76. split=$TEST
  77. TEST=""
  78. for a in $split; do TEST="$TEST ${REPO_PATH}/${a}"; done
  79. # shellcheck disable=SC2206
  80. TEST=($TEST)
  81. # TODO: 'client' pkg fails with gosimple from generated files
  82. # TODO: 'rafttest' is failing with unused
  83. STATIC_ANALYSIS_PATHS=$(find . -name \*.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | grep -v 'client')
  84. # shellcheck disable=SC2206
  85. STATIC_ANALYSIS_PATHS=($STATIC_ANALYSIS_PATHS)
  86. if [ -z "$GOARCH" ]; then
  87. GOARCH=$(go env GOARCH);
  88. fi
  89. # determine whether target supports race detection
  90. if [ "$GOARCH" == "amd64" ]; then
  91. RACE="--race"
  92. fi
  93. RUN_ARG=""
  94. if [ ! -z "${TESTCASE}" ]; then
  95. RUN_ARG="-run=${TESTCASE}"
  96. fi
  97. function unit_pass {
  98. echo "Running unit tests..."
  99. GO_TEST_FLAG=""
  100. if [ "${VERBOSE}" == "1" ]; then
  101. GO_TEST_FLAG="-v"
  102. fi
  103. if [ "${VERBOSE}" == "2" ]; then
  104. GO_TEST_FLAG="-v"
  105. export CLIENT_DEBUG=1
  106. fi
  107. if [ "${RUN_ARG}" == "" ]; then
  108. RUN_ARG="-run=Test"
  109. fi
  110. # check if user provided time out, especially useful when just run one test case
  111. # expectation could be different
  112. USERTIMEOUT=""
  113. if [ -z "${TIMEOUT}" ]; then
  114. USERTIMEOUT="3m"
  115. else
  116. USERTIMEOUT="${TIMEOUT}"
  117. fi
  118. go test ${GO_TEST_FLAG} -timeout "${USERTIMEOUT}" "${COVER}" ${RACE} -cpu 1,2,4 ${RUN_ARG} "$@" "${TEST[@]}"
  119. }
  120. function integration_pass {
  121. echo "Running integration tests..."
  122. # check if user provided time out, especially useful when just run one test case
  123. # expectation could be different
  124. USERTIMEOUT=""
  125. if [ -z "${TIMEOUT}" ]; then
  126. USERTIMEOUT="20m"
  127. else
  128. USERTIMEOUT="${TIMEOUT}"
  129. fi
  130. # if TESTCASE and PKG set, run specified test case in specified PKG
  131. # if TESTCASE set, PKG not set, run specified test case in all integration and integration_extra packages
  132. # if TESTCASE not set, PKG set, run all test cases in specified package
  133. # if TESTCASE not set, PKG not set, run all tests in all integration and integration_extra packages
  134. if [ -z "${TESTCASE}" ] && [ -z "${USERPKG}" ]; then
  135. go test -timeout "${USERTIMEOUT}" -v -cpu 1,2,4 "$@" "${REPO_PATH}/integration"
  136. integration_extra "$@"
  137. else
  138. if [ -z "${USERPKG}" ]; then
  139. INTEGTESTPKG=("${REPO_PATH}/integration"
  140. "${REPO_PATH}/client/integration"
  141. "${REPO_PATH}/clientv3/integration"
  142. "${REPO_PATH}/contrib/raftexample"
  143. "${REPO_PATH}/store")
  144. else
  145. INTEGTESTPKG=("${TEST[@]}")
  146. fi
  147. go test -timeout "${USERTIMEOUT}" -v -cpu 1,2,4 "${RUN_ARG}" "$@" "${INTEGTESTPKG[@]}"
  148. fi
  149. }
  150. function integration_extra {
  151. go test -timeout 1m -v ${RACE} -cpu 1,2,4 "$@" "${REPO_PATH}/client/integration"
  152. go test -timeout 25m -v ${RACE} -cpu 1,2,4 "$@" "${REPO_PATH}/clientv3/integration"
  153. go test -timeout 1m -v -cpu 1,2,4 "$@" "${REPO_PATH}/contrib/raftexample"
  154. go test -timeout 5m -v ${RACE} -tags v2v3 "$@" "${REPO_PATH}/etcdserver/v2store"
  155. go test -timeout 1m -v ${RACE} -cpu 1,2,4 -run=Example "$@" "${TEST[@]}"
  156. }
  157. function functional_pass {
  158. # Clean up any data and logs from previous runs
  159. rm -rf /tmp/etcd-agent-data-*
  160. for a in 1 2 3; do
  161. ./bin/etcd-agent --network tcp --address 127.0.0.1:${a}9027 &
  162. pid="$!"
  163. agent_pids="${agent_pids} $pid"
  164. done
  165. for a in 1 2 3; do
  166. echo "Waiting for 'etcd-agent' on ${a}9027..."
  167. while ! nc -z localhost ${a}9027; do
  168. sleep 1
  169. done
  170. done
  171. echo "functional test START!"
  172. ./bin/etcd-tester --config ./functional.yaml && echo "'etcd-tester' succeeded"
  173. ETCD_TESTER_EXIT_CODE=$?
  174. echo "ETCD_TESTER_EXIT_CODE:" ${ETCD_TESTER_EXIT_CODE}
  175. # shellcheck disable=SC2206
  176. agent_pids=($agent_pids)
  177. kill -s TERM "${agent_pids[@]}" || true
  178. if [[ "${ETCD_TESTER_EXIT_CODE}" -ne "0" ]]; then
  179. echo "--- FAIL: exit code" ${ETCD_TESTER_EXIT_CODE}
  180. exit ${ETCD_TESTER_EXIT_CODE}
  181. fi
  182. echo "functional test PASS!"
  183. }
  184. function cov_pass {
  185. echo "Running code coverage..."
  186. # install gocovmerge before running code coverage from github.com/wadey/gocovmerge
  187. # gocovmerge merges coverage files
  188. if ! which gocovmerge >/dev/null; then
  189. echo "gocovmerge not installed"
  190. exit 255
  191. fi
  192. if [ -z "$COVERDIR" ]; then
  193. echo "COVERDIR undeclared"
  194. exit 255
  195. fi
  196. if [ ! -f "bin/etcd_test" ]; then
  197. echo "etcd_test binary not found"
  198. exit 255
  199. fi
  200. mkdir -p "$COVERDIR"
  201. # run code coverage for unit and integration tests
  202. GOCOVFLAGS="-covermode=set -coverpkg ${PKGS_COMMA} -v -timeout 20m"
  203. # shellcheck disable=SC2206
  204. GOCOVFLAGS=($GOCOVFLAGS)
  205. failed=""
  206. for t in $(echo "${TEST_PKGS}" | grep -vE "(e2e|functional)"); do
  207. tf=$(echo "$t" | tr / _)
  208. # cache package compilation data for faster repeated builds
  209. go test "${GOCOVFLAGS[@]}" -i "${REPO_PATH}/$t" || true
  210. # uses -run=Test to skip examples because clientv3/ example tests will leak goroutines
  211. go test "${GOCOVFLAGS[@]}" -run=Test -coverprofile "$COVERDIR/${tf}.coverprofile" "${REPO_PATH}/$t" || failed="$failed $t"
  212. done
  213. # v2v3 tests
  214. go test -tags v2v3 "${GOCOVFLAGS[@]}" -coverprofile "$COVERDIR/store-v2v3.coverprofile" "${REPO_PATH}/clientv3/integration" || failed="$failed store-v2v3"
  215. # proxy tests
  216. go test -tags cluster_proxy "${GOCOVFLAGS[@]}" -coverprofile "$COVERDIR/proxy_integration.coverprofile" "${REPO_PATH}/integration" || failed="$failed proxy-integration"
  217. go test -tags cluster_proxy "${GOCOVFLAGS[@]}" -coverprofile "$COVERDIR/proxy_clientv3.coverprofile" "${REPO_PATH}/clientv3/integration" || failed="$failed proxy-clientv3/integration"
  218. # run code coverage for e2e tests
  219. # use 30m timeout because e2e coverage takes longer
  220. # due to many tests cause etcd process to wait
  221. # on leadership transfer timeout during gracefully shutdown
  222. echo Testing e2e without proxy...
  223. go test -tags cov -timeout 30m -v "${REPO_PATH}/e2e" || failed="$failed e2e"
  224. echo Testing e2e with proxy...
  225. go test -tags "cov cluster_proxy" -timeout 30m -v "${REPO_PATH}/e2e" || failed="$failed e2e-proxy"
  226. # incrementally merge to get coverage data even if some coverage files are corrupted
  227. # optimistically assume etcdserver package's coverage file is OK since gocovmerge
  228. # expects to start with a non-empty file
  229. cp "$COVERDIR"/etcdserver.coverprofile "$COVERDIR"/cover.out
  230. for f in "$COVERDIR"/*.coverprofile; do
  231. echo "merging test coverage file ${f}"
  232. gocovmerge "$f" "$COVERDIR"/cover.out >"$COVERDIR"/cover.tmp || failed="$failed $f"
  233. if [ -s "$COVERDIR"/cover.tmp ]; then
  234. mv "$COVERDIR"/cover.tmp "$COVERDIR"/cover.out
  235. fi
  236. done
  237. # strip out generated files (using GNU-style sed)
  238. sed --in-place '/generated.go/d' "$COVERDIR"/cover.out || true
  239. # held failures to generate the full coverage file, now fail
  240. if [ -n "$failed" ]; then
  241. for f in $failed; do
  242. echo "--- FAIL:" "$f"
  243. done
  244. exit 255
  245. fi
  246. }
  247. function e2e_pass {
  248. echo "Running e2e tests..."
  249. # check if user provided time out, especially useful when just run one test case
  250. # expectation could be different
  251. USERTIMEOUT=""
  252. if [ -z "${TIMEOUT}" ]; then
  253. USERTIMEOUT="20m"
  254. else
  255. USERTIMEOUT="${TIMEOUT}"
  256. fi
  257. go test -timeout "${USERTIMEOUT}" -v -cpu 1,2,4 "${RUN_ARG}" "$@" "${REPO_PATH}/e2e"
  258. }
  259. function integration_e2e_pass {
  260. echo "Running integration and e2e tests..."
  261. go test -timeout 20m -v -cpu 1,2,4 "$@" "${REPO_PATH}/e2e" &
  262. e2epid="$!"
  263. go test -timeout 20m -v -cpu 1,2,4 "$@" "${REPO_PATH}/integration" &
  264. intpid="$!"
  265. wait $e2epid
  266. wait $intpid
  267. integration_extra "$@"
  268. }
  269. function grpcproxy_pass {
  270. go test -timeout 20m -v ${RACE} -tags cluster_proxy -cpu 1,2,4 "$@" "${REPO_PATH}/integration"
  271. go test -timeout 20m -v ${RACE} -tags cluster_proxy -cpu 1,2,4 "$@" "${REPO_PATH}/clientv3/integration"
  272. go test -timeout 20m -v -tags cluster_proxy "$@" "${REPO_PATH}/e2e"
  273. }
  274. function release_pass {
  275. rm -f ./bin/etcd-last-release
  276. # to grab latest patch release; bump this up for every minor release
  277. UPGRADE_VER=$(git tag -l --sort=-version:refname "v3.3.*" | head -1)
  278. if [ -n "$MANUAL_VER" ]; then
  279. # in case, we need to test against different version
  280. UPGRADE_VER=$MANUAL_VER
  281. fi
  282. if [[ -z ${UPGRADE_VER} ]]; then
  283. UPGRADE_VER="v3.3.0"
  284. echo "fallback to" ${UPGRADE_VER}
  285. fi
  286. local file="etcd-$UPGRADE_VER-linux-$GOARCH.tar.gz"
  287. echo "Downloading $file"
  288. set +e
  289. curl --fail -L "https://github.com/coreos/etcd/releases/download/$UPGRADE_VER/$file" -o "/tmp/$file"
  290. local result=$?
  291. set -e
  292. case $result in
  293. 0) ;;
  294. *) echo "--- FAIL:" ${result}
  295. exit $result
  296. ;;
  297. esac
  298. tar xzvf "/tmp/$file" -C /tmp/ --strip-components=1
  299. mkdir -p ./bin
  300. mv /tmp/etcd ./bin/etcd-last-release
  301. }
  302. function shellcheck_pass {
  303. if which shellcheck >/dev/null; then
  304. shellcheckResult=$(shellcheck -fgcc build test scripts/*.sh 2>&1 || true)
  305. if [ -n "${shellcheckResult}" ]; then
  306. echo -e "shellcheck checking failed:\\n${shellcheckResult}"
  307. exit 255
  308. fi
  309. fi
  310. }
  311. function markdown_you_pass {
  312. # eschew you
  313. yous=$(find . -name \*.md -exec grep -E --color "[Yy]ou[r]?[ '.,;]" {} + | grep -v /v2/ || true)
  314. if [ ! -z "$yous" ]; then
  315. echo -e "found 'you' in documentation:\\n${yous}"
  316. exit 255
  317. fi
  318. }
  319. function markdown_marker_pass {
  320. # TODO: check other markdown files when marker handles headers with '[]'
  321. if which marker >/dev/null; then
  322. markerResult=$(marker --skip-http --root ./Documentation 2>&1 || true)
  323. if [ -n "${markerResult}" ]; then
  324. echo -e "marker checking failed:\\n${markerResult}"
  325. exit 255
  326. fi
  327. else
  328. echo "Skipping marker..."
  329. fi
  330. }
  331. function goword_pass {
  332. if which goword >/dev/null; then
  333. # get all go files to process
  334. gofiles=$(find "${FMT[@]}" -iname '*.go' 2>/dev/null)
  335. # shellcheck disable=SC2206
  336. gofiles_all=($gofiles)
  337. # ignore tests and protobuf files
  338. # shellcheck disable=SC1117
  339. gofiles=$(echo "${gofiles_all[@]}" | sort | uniq | sed "s/ /\n/g" | grep -vE "(\\_test.go|\\.pb\\.go)")
  340. # shellcheck disable=SC2206
  341. gofiles=($gofiles)
  342. # only check for broken exported godocs
  343. gowordRes=$(goword -use-spell=false "${gofiles[@]}" | grep godoc-export | sort)
  344. if [ ! -z "$gowordRes" ]; then
  345. echo -e "goword checking failed:\\n${gowordRes}"
  346. exit 255
  347. fi
  348. # check some spelling
  349. gowordRes=$(goword -ignore-file=.words clientv3/{*,*/*}.go 2>&1 | grep spell | sort)
  350. if [ ! -z "$gowordRes" ]; then
  351. echo -e "goword checking failed:\\n${gowordRes}"
  352. exit 255
  353. fi
  354. else
  355. echo "Skipping goword..."
  356. fi
  357. }
  358. function gofmt_pass {
  359. fmtRes=$(gofmt -l -s -d "${FMT[@]}")
  360. if [ -n "${fmtRes}" ]; then
  361. echo -e "gofmt checking failed:\\n${fmtRes}"
  362. exit 255
  363. fi
  364. }
  365. function govet_pass {
  366. vetRes=$(go vet "${TEST[@]}")
  367. if [ -n "${vetRes}" ]; then
  368. echo -e "govet checking failed:\\n${vetRes}"
  369. exit 255
  370. fi
  371. }
  372. function govet_shadow_pass {
  373. fmtpkgs=$(for a in "${FMT[@]}"; do dirname "$a"; done | sort | uniq | grep -v "\\.")
  374. # shellcheck disable=SC2206
  375. fmtpkgs=($fmtpkgs)
  376. vetRes=$(go tool vet -all -shadow "${fmtpkgs[@]}" 2>&1 | grep -v '/gw/' || true)
  377. if [ -n "${vetRes}" ]; then
  378. echo -e "govet -all -shadow checking failed:\\n${vetRes}"
  379. exit 255
  380. fi
  381. }
  382. function gosimple_pass {
  383. if which gosimple >/dev/null; then
  384. gosimpleResult=$(gosimple "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  385. if [ -n "${gosimpleResult}" ]; then
  386. echo -e "gosimple checking failed:\\n${gosimpleResult}"
  387. exit 255
  388. fi
  389. else
  390. echo "Skipping gosimple..."
  391. fi
  392. }
  393. function unused_pass {
  394. if which unused >/dev/null; then
  395. unusedResult=$(unused "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  396. if [ -n "${unusedResult}" ]; then
  397. echo -e "unused checking failed:\\n${unusedResult}"
  398. exit 255
  399. fi
  400. else
  401. echo "Skipping unused..."
  402. fi
  403. }
  404. function staticcheck_pass {
  405. if which staticcheck >/dev/null; then
  406. staticcheckResult=$(staticcheck "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  407. if [ -n "${staticcheckResult}" ]; then
  408. # TODO: resolve these after go1.8 migration
  409. # See https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
  410. STATIC_CHECK_MASK="SA(1012|1019|2002)"
  411. if echo "${staticcheckResult}" | grep -vE "$STATIC_CHECK_MASK"; then
  412. echo -e "staticcheck checking failed:\\n${staticcheckResult}"
  413. exit 255
  414. else
  415. suppressed=$(echo "${staticcheckResult}" | sed 's/ /\n/g' | grep "(SA" | sort | uniq -c)
  416. echo -e "staticcheck suppressed warnings:\\n${suppressed}"
  417. fi
  418. fi
  419. else
  420. echo "Skipping staticcheck..."
  421. fi
  422. }
  423. function ineffassign_pass {
  424. if which ineffassign >/dev/null; then
  425. ineffassignResult=$(ineffassign "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  426. if [ -n "${ineffassignResult}" ]; then
  427. echo -e "ineffassign checking failed:\\n${ineffassignResult}"
  428. exit 255
  429. fi
  430. else
  431. echo "Skipping ineffassign..."
  432. fi
  433. }
  434. function nakedret_pass {
  435. if which nakedret >/dev/null; then
  436. nakedretResult=$(nakedret "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  437. if [ -n "${nakedretResult}" ]; then
  438. echo -e "nakedret checking failed:\\n${nakedretResult}"
  439. exit 255
  440. fi
  441. else
  442. echo "Skipping nakedret..."
  443. fi
  444. }
  445. function license_header_pass {
  446. licRes=""
  447. files=$(find . -type f -iname '*.go' ! -path './cmd/*' ! -path './gopath.proto/*')
  448. for file in $files; do
  449. if ! head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" ; then
  450. licRes="${licRes}"$(echo -e " ${file}")
  451. fi
  452. done
  453. if [ -n "${licRes}" ]; then
  454. echo -e "license header checking failed:\\n${licRes}"
  455. exit 255
  456. fi
  457. }
  458. function receiver_name_pass {
  459. # shellcheck disable=SC1117
  460. recvs=$(grep 'func ([^*]' {*,*/*,*/*/*}.go | grep -Ev "(generated|pb/)" | tr ':' ' ' | \
  461. awk ' { print $2" "$3" "$4" "$1 }' | sed "s/[a-zA-Z\.]*go//g" | sort | uniq | \
  462. grep -Ev "(Descriptor|Proto|_)" | awk ' { print $3" "$4 } ' | sort | uniq -c | grep -v ' 1 ' | awk ' { print $2 } ')
  463. if [ -n "${recvs}" ]; then
  464. # shellcheck disable=SC2206
  465. recvs=($recvs)
  466. for recv in "${recvs[@]}"; do
  467. echo "Mismatched receiver for $recv..."
  468. grep "$recv" "${FMT[@]}" | grep 'func ('
  469. done
  470. exit 255
  471. fi
  472. }
  473. function commit_title_pass {
  474. git log --oneline "$(git merge-base HEAD master)"...HEAD | while read -r l; do
  475. commitMsg=$(echo "$l" | cut -f2- -d' ')
  476. if [[ "$commitMsg" == Merge* ]]; then
  477. # ignore "Merge pull" commits
  478. continue
  479. fi
  480. if [[ "$commitMsg" == Revert* ]]; then
  481. # ignore revert commits
  482. continue
  483. fi
  484. pkgPrefix=$(echo "$commitMsg" | cut -f1 -d':')
  485. spaceCommas=$(echo "$commitMsg" | sed 's/ /\n/g' | grep -c ',$' || echo 0)
  486. commaSpaces=$(echo "$commitMsg" | sed 's/,/\n/g' | grep -c '^ ' || echo 0)
  487. if [[ $(echo "$commitMsg" | grep -c ":..*") == 0 || "$commitMsg" == "$pkgPrefix" || "$spaceCommas" != "$commaSpaces" ]]; then
  488. echo "$l"...
  489. echo "Expected commit title format '<package>{\", \"<package>}: <description>'"
  490. echo "Got: $l"
  491. exit 255
  492. fi
  493. done
  494. }
  495. function fmt_pass {
  496. toggle_failpoints disable
  497. for p in shellcheck \
  498. markdown_you \
  499. markdown_marker \
  500. goword \
  501. gofmt \
  502. govet \
  503. govet_shadow \
  504. gosimple \
  505. unused \
  506. staticcheck \
  507. ineffassign \
  508. nakedret \
  509. license_header \
  510. receiver_name \
  511. commit_title \
  512. ; do
  513. echo "'$p' started at $(date)"
  514. "${p}"_pass "$@"
  515. echo "'$p' completed at $(date)"
  516. done
  517. }
  518. function bom_pass {
  519. if ! which license-bill-of-materials >/dev/null; then
  520. return
  521. fi
  522. echo "Checking bill of materials..."
  523. license-bill-of-materials \
  524. --override-file bill-of-materials.override.json \
  525. github.com/coreos/etcd github.com/coreos/etcd/etcdctl >bom-now.json || true
  526. if ! diff bill-of-materials.json bom-now.json; then
  527. echo "vendored licenses do not match given bill of materials"
  528. exit 255
  529. fi
  530. rm bom-now.json
  531. }
  532. function dep_pass {
  533. echo "Checking package dependencies..."
  534. # don't pull in etcdserver package
  535. pushd clientv3 >/dev/null
  536. badpkg="(etcdserver$|mvcc$|backend$|grpc-gateway)"
  537. deps=$(go list -f '{{ .Deps }}' | sed 's/ /\n/g' | grep -E "${badpkg}" || echo "")
  538. popd >/dev/null
  539. if [ ! -z "$deps" ]; then
  540. echo -e "clientv3 has masked dependencies:\\n${deps}"
  541. exit 255
  542. fi
  543. }
  544. function build_cov_pass {
  545. out="bin"
  546. if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
  547. go test -tags cov -c -covermode=set -coverpkg="$PKGS_COMMA" -o "${out}/etcd_test"
  548. go test -tags cov -c -covermode=set -coverpkg="$PKGS_COMMA" -o "${out}/etcdctl_test" "${REPO_PATH}/etcdctl"
  549. }
  550. # fail fast on static tests
  551. function build_pass {
  552. echo "Checking build..."
  553. GO_BUILD_FLAGS="-a -v" etcd_build
  554. GO_BUILD_FLAGS="-a -v" tools_build
  555. }
  556. for pass in $PASSES; do
  557. echo "Starting '$pass' pass at $(date)"
  558. "${pass}"_pass "$@"
  559. echo "Finished '$pass' pass at $(date)"
  560. done
  561. echo "Success"