test 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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 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 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}/store")
  143. else
  144. INTEGTESTPKG=("${TEST[@]}")
  145. fi
  146. go test -timeout "${USERTIMEOUT}" -v -cpu 4 "${RUN_ARG}" "$@" "${INTEGTESTPKG[@]}"
  147. fi
  148. }
  149. function integration_extra {
  150. go test -timeout 1m -v ${RACE} -cpu 4 "$@" "${REPO_PATH}/client/integration"
  151. go test -timeout 25m -v ${RACE} -cpu 4 "$@" "${REPO_PATH}/clientv3/integration"
  152. }
  153. function functional_pass {
  154. # Clean up any data and logs from previous runs
  155. rm -rf /tmp/etcd-functional-* /tmp/etcd-functional-*.backup
  156. for a in 1 2 3; do
  157. ./bin/etcd-agent --network tcp --address 127.0.0.1:${a}9027 &
  158. pid="$!"
  159. agent_pids="${agent_pids} $pid"
  160. done
  161. for a in 1 2 3; do
  162. echo "Waiting for 'etcd-agent' on ${a}9027..."
  163. while ! nc -z localhost ${a}9027; do
  164. sleep 1
  165. done
  166. done
  167. echo "functional test START!"
  168. ./bin/etcd-tester --config ./functional.yaml && echo "'etcd-tester' succeeded"
  169. ETCD_TESTER_EXIT_CODE=$?
  170. echo "ETCD_TESTER_EXIT_CODE:" ${ETCD_TESTER_EXIT_CODE}
  171. # shellcheck disable=SC2206
  172. agent_pids=($agent_pids)
  173. kill -s TERM "${agent_pids[@]}" || true
  174. if [[ "${ETCD_TESTER_EXIT_CODE}" -ne "0" ]]; then
  175. echo "--- FAIL: exit code" ${ETCD_TESTER_EXIT_CODE}
  176. exit ${ETCD_TESTER_EXIT_CODE}
  177. fi
  178. echo "functional test PASS!"
  179. }
  180. function cov_pass {
  181. echo "Running code coverage..."
  182. # install gocovmerge before running code coverage from github.com/wadey/gocovmerge
  183. # gocovmerge merges coverage files
  184. if ! which gocovmerge >/dev/null; then
  185. echo "gocovmerge not installed"
  186. exit 255
  187. fi
  188. if [ -z "$COVERDIR" ]; then
  189. echo "COVERDIR undeclared"
  190. exit 255
  191. fi
  192. if [ ! -f "bin/etcd_test" ]; then
  193. echo "etcd_test binary not found"
  194. exit 255
  195. fi
  196. mkdir -p "$COVERDIR"
  197. # run code coverage for unit and integration tests
  198. GOCOVFLAGS="-covermode=set -coverpkg ${PKGS_COMMA} -v -timeout 20m"
  199. # shellcheck disable=SC2206
  200. GOCOVFLAGS=($GOCOVFLAGS)
  201. failed=""
  202. for t in $(echo "${TEST_PKGS}" | grep -vE "(e2e|functional)"); do
  203. tf=$(echo "$t" | tr / _)
  204. # cache package compilation data for faster repeated builds
  205. go test "${GOCOVFLAGS[@]}" -i "${REPO_PATH}/$t" || true
  206. # uses -run=Test to skip examples because clientv3/ example tests will leak goroutines
  207. go test "${GOCOVFLAGS[@]}" -run=Test -coverprofile "$COVERDIR/${tf}.coverprofile" "${REPO_PATH}/$t" || failed="$failed $t"
  208. done
  209. # v2v3 tests
  210. go test -tags v2v3 "${GOCOVFLAGS[@]}" -coverprofile "$COVERDIR/store-v2v3.coverprofile" "${REPO_PATH}/clientv3/integration" || failed="$failed store-v2v3"
  211. # proxy tests
  212. go test -tags cluster_proxy "${GOCOVFLAGS[@]}" -coverprofile "$COVERDIR/proxy_integration.coverprofile" "${REPO_PATH}/integration" || failed="$failed proxy-integration"
  213. go test -tags cluster_proxy "${GOCOVFLAGS[@]}" -coverprofile "$COVERDIR/proxy_clientv3.coverprofile" "${REPO_PATH}/clientv3/integration" || failed="$failed proxy-clientv3/integration"
  214. # run code coverage for e2e tests
  215. # use 30m timeout because e2e coverage takes longer
  216. # due to many tests cause etcd process to wait
  217. # on leadership transfer timeout during gracefully shutdown
  218. echo Testing e2e without proxy...
  219. go test -tags cov -timeout 30m -v "${REPO_PATH}/e2e" || failed="$failed e2e"
  220. echo Testing e2e with proxy...
  221. go test -tags "cov cluster_proxy" -timeout 30m -v "${REPO_PATH}/e2e" || failed="$failed e2e-proxy"
  222. # incrementally merge to get coverage data even if some coverage files are corrupted
  223. # optimistically assume etcdserver package's coverage file is OK since gocovmerge
  224. # expects to start with a non-empty file
  225. cp "$COVERDIR"/etcdserver.coverprofile "$COVERDIR"/cover.out
  226. for f in "$COVERDIR"/*.coverprofile; do
  227. echo "merging test coverage file ${f}"
  228. gocovmerge "$f" "$COVERDIR"/cover.out >"$COVERDIR"/cover.tmp || failed="$failed $f"
  229. if [ -s "$COVERDIR"/cover.tmp ]; then
  230. mv "$COVERDIR"/cover.tmp "$COVERDIR"/cover.out
  231. fi
  232. done
  233. # strip out generated files (using GNU-style sed)
  234. sed --in-place '/generated.go/d' "$COVERDIR"/cover.out || true
  235. # held failures to generate the full coverage file, now fail
  236. if [ -n "$failed" ]; then
  237. for f in $failed; do
  238. echo "--- FAIL:" "$f"
  239. done
  240. exit 255
  241. fi
  242. }
  243. function e2e_pass {
  244. echo "Running e2e tests..."
  245. # check if user provided time out, especially useful when just run one test case
  246. # expectation could be different
  247. USERTIMEOUT=""
  248. if [ -z "${TIMEOUT}" ]; then
  249. USERTIMEOUT="20m"
  250. else
  251. USERTIMEOUT="${TIMEOUT}"
  252. fi
  253. go test -timeout "${USERTIMEOUT}" -v -cpu 4 "${RUN_ARG}" "$@" "${REPO_PATH}/e2e"
  254. }
  255. function integration_e2e_pass {
  256. echo "Running integration and e2e tests..."
  257. go test -timeout 20m -v -cpu 4 "$@" "${REPO_PATH}/e2e" &
  258. e2epid="$!"
  259. go test -timeout 20m -v -cpu 4 "$@" "${REPO_PATH}/integration" &
  260. intpid="$!"
  261. wait $e2epid
  262. wait $intpid
  263. integration_extra "$@"
  264. }
  265. function grpcproxy_pass {
  266. go test -timeout 20m -v ${RACE} -tags cluster_proxy -cpu 4 "$@" "${REPO_PATH}/integration"
  267. go test -timeout 20m -v ${RACE} -tags cluster_proxy -cpu 4 "$@" "${REPO_PATH}/clientv3/integration"
  268. go test -timeout 20m -v -tags cluster_proxy "$@" "${REPO_PATH}/e2e"
  269. }
  270. function release_pass {
  271. rm -f ./bin/etcd-last-release
  272. # to grab latest patch release; bump this up for every minor release
  273. UPGRADE_VER=$(git tag -l --sort=-version:refname "v3.2.*" | head -1)
  274. if [ -n "$MANUAL_VER" ]; then
  275. # in case, we need to test against different version
  276. UPGRADE_VER=$MANUAL_VER
  277. fi
  278. if [[ -z ${UPGRADE_VER} ]]; then
  279. UPGRADE_VER="v3.2.0"
  280. echo "fallback to" ${UPGRADE_VER}
  281. fi
  282. local file="etcd-$UPGRADE_VER-linux-$GOARCH.tar.gz"
  283. echo "Downloading $file"
  284. set +e
  285. curl --fail -L "https://github.com/coreos/etcd/releases/download/$UPGRADE_VER/$file" -o "/tmp/$file"
  286. local result=$?
  287. set -e
  288. case $result in
  289. 0) ;;
  290. *) echo "--- FAIL:" ${result}
  291. exit $result
  292. ;;
  293. esac
  294. tar xzvf "/tmp/$file" -C /tmp/ --strip-components=1
  295. mkdir -p ./bin
  296. mv /tmp/etcd ./bin/etcd-last-release
  297. }
  298. function shellcheck_pass {
  299. if which shellcheck >/dev/null; then
  300. shellcheckResult=$(shellcheck -fgcc build test scripts/*.sh 2>&1 || true)
  301. if [ -n "${shellcheckResult}" ]; then
  302. echo -e "shellcheck checking failed:\\n${shellcheckResult}"
  303. exit 255
  304. fi
  305. fi
  306. }
  307. function markdown_you_pass {
  308. # eschew you
  309. yous=$(find . -name \*.md -exec grep -E --color "[Yy]ou[r]?[ '.,;]" {} + | grep -v /v2/ || true)
  310. if [ ! -z "$yous" ]; then
  311. echo -e "found 'you' in documentation:\\n${yous}"
  312. exit 255
  313. fi
  314. }
  315. function markdown_marker_pass {
  316. # TODO: check other markdown files when marker handles headers with '[]'
  317. if which marker >/dev/null; then
  318. markerResult=$(marker --skip-http --root ./Documentation 2>&1 || true)
  319. if [ -n "${markerResult}" ]; then
  320. echo -e "marker checking failed:\\n${markerResult}"
  321. exit 255
  322. fi
  323. else
  324. echo "Skipping marker..."
  325. fi
  326. }
  327. function goword_pass {
  328. if which goword >/dev/null; then
  329. # get all go files to process
  330. gofiles=$(find "${FMT[@]}" -iname '*.go' 2>/dev/null)
  331. # shellcheck disable=SC2206
  332. gofiles_all=($gofiles)
  333. # ignore tests and protobuf files
  334. # shellcheck disable=SC1117
  335. gofiles=$(echo "${gofiles_all[@]}" | sort | uniq | sed "s/ /\n/g" | grep -vE "(\\_test.go|\\.pb\\.go)")
  336. # shellcheck disable=SC2206
  337. gofiles=($gofiles)
  338. # only check for broken exported godocs
  339. gowordRes=$(goword -use-spell=false "${gofiles[@]}" | grep godoc-export | sort)
  340. if [ ! -z "$gowordRes" ]; then
  341. echo -e "goword checking failed:\\n${gowordRes}"
  342. exit 255
  343. fi
  344. # check some spelling
  345. gowordRes=$(goword -ignore-file=.words clientv3/{*,*/*}.go 2>&1 | grep spell | sort)
  346. if [ ! -z "$gowordRes" ]; then
  347. echo -e "goword checking failed:\\n${gowordRes}"
  348. exit 255
  349. fi
  350. else
  351. echo "Skipping goword..."
  352. fi
  353. }
  354. function gofmt_pass {
  355. fmtRes=$(gofmt -l -s -d "${FMT[@]}")
  356. if [ -n "${fmtRes}" ]; then
  357. echo -e "gofmt checking failed:\\n${fmtRes}"
  358. exit 255
  359. fi
  360. }
  361. function govet_pass {
  362. vetRes=$(go vet "${TEST[@]}")
  363. if [ -n "${vetRes}" ]; then
  364. echo -e "govet checking failed:\\n${vetRes}"
  365. exit 255
  366. fi
  367. }
  368. function govet_shadow_pass {
  369. fmtpkgs=$(for a in "${FMT[@]}"; do dirname "$a"; done | sort | uniq | grep -v "\\.")
  370. # shellcheck disable=SC2206
  371. fmtpkgs=($fmtpkgs)
  372. vetRes=$(go tool vet -all -shadow "${fmtpkgs[@]}" 2>&1 | grep -v '/gw/' || true)
  373. if [ -n "${vetRes}" ]; then
  374. echo -e "govet -all -shadow checking failed:\\n${vetRes}"
  375. exit 255
  376. fi
  377. }
  378. function gosimple_pass {
  379. if which gosimple >/dev/null; then
  380. gosimpleResult=$(gosimple "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  381. if [ -n "${gosimpleResult}" ]; then
  382. echo -e "gosimple checking failed:\\n${gosimpleResult}"
  383. exit 255
  384. fi
  385. else
  386. echo "Skipping gosimple..."
  387. fi
  388. }
  389. function unused_pass {
  390. if which unused >/dev/null; then
  391. unusedResult=$(unused "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  392. if [ -n "${unusedResult}" ]; then
  393. echo -e "unused checking failed:\\n${unusedResult}"
  394. exit 255
  395. fi
  396. else
  397. echo "Skipping unused..."
  398. fi
  399. }
  400. function staticcheck_pass {
  401. if which staticcheck >/dev/null; then
  402. staticcheckResult=$(staticcheck "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  403. if [ -n "${staticcheckResult}" ]; then
  404. # TODO: resolve these after go1.8 migration
  405. # See https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
  406. STATIC_CHECK_MASK="SA(1012|1019|2002)"
  407. if echo "${staticcheckResult}" | grep -vE "$STATIC_CHECK_MASK"; then
  408. echo -e "staticcheck checking failed:\\n${staticcheckResult}"
  409. exit 255
  410. else
  411. suppressed=$(echo "${staticcheckResult}" | sed 's/ /\n/g' | grep "(SA" | sort | uniq -c)
  412. echo -e "staticcheck suppressed warnings:\\n${suppressed}"
  413. fi
  414. fi
  415. else
  416. echo "Skipping staticcheck..."
  417. fi
  418. }
  419. function ineffassign_pass {
  420. if which ineffassign >/dev/null; then
  421. ineffassignResult=$(ineffassign "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  422. if [ -n "${ineffassignResult}" ]; then
  423. echo -e "ineffassign checking failed:\\n${ineffassignResult}"
  424. exit 255
  425. fi
  426. else
  427. echo "Skipping ineffassign..."
  428. fi
  429. }
  430. function nakedret_pass {
  431. if which nakedret >/dev/null; then
  432. nakedretResult=$(nakedret "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
  433. if [ -n "${nakedretResult}" ]; then
  434. echo -e "nakedret checking failed:\\n${nakedretResult}"
  435. exit 255
  436. fi
  437. else
  438. echo "Skipping nakedret..."
  439. fi
  440. }
  441. function license_header_pass {
  442. licRes=""
  443. files=$(find . -type f -iname '*.go' ! -path './cmd/*' ! -path './gopath.proto/*')
  444. for file in $files; do
  445. if ! head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" ; then
  446. licRes="${licRes}"$(echo -e " ${file}")
  447. fi
  448. done
  449. if [ -n "${licRes}" ]; then
  450. echo -e "license header checking failed:\\n${licRes}"
  451. exit 255
  452. fi
  453. }
  454. function receiver_name_pass {
  455. # shellcheck disable=SC1117
  456. recvs=$(grep 'func ([^*]' {*,*/*,*/*/*}.go | grep -Ev "(generated|pb/)" | tr ':' ' ' | \
  457. awk ' { print $2" "$3" "$4" "$1 }' | sed "s/[a-zA-Z\.]*go//g" | sort | uniq | \
  458. grep -Ev "(Descriptor|Proto|_)" | awk ' { print $3" "$4 } ' | sort | uniq -c | grep -v ' 1 ' | awk ' { print $2 } ')
  459. if [ -n "${recvs}" ]; then
  460. # shellcheck disable=SC2206
  461. recvs=($recvs)
  462. for recv in "${recvs[@]}"; do
  463. echo "Mismatched receiver for $recv..."
  464. grep "$recv" "${FMT[@]}" | grep 'func ('
  465. done
  466. exit 255
  467. fi
  468. }
  469. function commit_title_pass {
  470. git log --oneline "$(git merge-base HEAD master)"...HEAD | while read -r l; do
  471. commitMsg=$(echo "$l" | cut -f2- -d' ')
  472. if [[ "$commitMsg" == Merge* ]]; then
  473. # ignore "Merge pull" commits
  474. continue
  475. fi
  476. if [[ "$commitMsg" == Revert* ]]; then
  477. # ignore revert commits
  478. continue
  479. fi
  480. pkgPrefix=$(echo "$commitMsg" | cut -f1 -d':')
  481. spaceCommas=$(echo "$commitMsg" | sed 's/ /\n/g' | grep -c ',$' || echo 0)
  482. commaSpaces=$(echo "$commitMsg" | sed 's/,/\n/g' | grep -c '^ ' || echo 0)
  483. if [[ $(echo "$commitMsg" | grep -c ":..*") == 0 || "$commitMsg" == "$pkgPrefix" || "$spaceCommas" != "$commaSpaces" ]]; then
  484. echo "$l"...
  485. echo "Expected commit title format '<package>{\", \"<package>}: <description>'"
  486. echo "Got: $l"
  487. exit 255
  488. fi
  489. done
  490. }
  491. function fmt_pass {
  492. toggle_failpoints disable
  493. for p in shellcheck \
  494. markdown_you \
  495. markdown_marker \
  496. goword \
  497. gofmt \
  498. govet \
  499. govet_shadow \
  500. gosimple \
  501. unused \
  502. staticcheck \
  503. ineffassign \
  504. nakedret \
  505. license_header \
  506. receiver_name \
  507. commit_title \
  508. ; do
  509. echo "'$p' started at $(date)"
  510. "${p}"_pass "$@"
  511. echo "'$p' completed at $(date)"
  512. done
  513. }
  514. function bom_pass {
  515. if ! which license-bill-of-materials >/dev/null; then
  516. return
  517. fi
  518. echo "Checking bill of materials..."
  519. license-bill-of-materials \
  520. --override-file bill-of-materials.override.json \
  521. github.com/coreos/etcd github.com/coreos/etcd/etcdctl >bom-now.json || true
  522. if ! diff bill-of-materials.json bom-now.json; then
  523. echo "vendored licenses do not match given bill of materials"
  524. exit 255
  525. fi
  526. rm bom-now.json
  527. }
  528. function dep_pass {
  529. echo "Checking package dependencies..."
  530. # don't pull in etcdserver package
  531. pushd clientv3 >/dev/null
  532. badpkg="(etcdserver$|mvcc$|backend$|grpc-gateway)"
  533. deps=$(go list -f '{{ .Deps }}' | sed 's/ /\n/g' | grep -E "${badpkg}" || echo "")
  534. popd >/dev/null
  535. if [ ! -z "$deps" ]; then
  536. echo -e "clientv3 has masked dependencies:\\n${deps}"
  537. exit 255
  538. fi
  539. }
  540. function build_cov_pass {
  541. out="bin"
  542. if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
  543. go test -tags cov -c -covermode=set -coverpkg="$PKGS_COMMA" -o "${out}/etcd_test"
  544. go test -tags cov -c -covermode=set -coverpkg="$PKGS_COMMA" -o "${out}/etcdctl_test" "${REPO_PATH}/etcdctl"
  545. }
  546. # fail fast on static tests
  547. function build_pass {
  548. echo "Checking build..."
  549. GO_BUILD_FLAGS="-v" etcd_build
  550. }
  551. for pass in $PASSES; do
  552. echo "Starting '$pass' pass at $(date)"
  553. "${pass}"_pass "$@"
  554. echo "Finished '$pass' pass at $(date)"
  555. done
  556. echo "Success"