2015-07-21 02:32:42 +03:00
|
|
|
#!/usr/bin/env bash
|
2014-09-09 10:06:03 +04:00
|
|
|
#
|
|
|
|
# Run all etcd tests
|
|
|
|
# ./test
|
|
|
|
# ./test -v
|
|
|
|
#
|
|
|
|
# Run tests for one package
|
|
|
|
#
|
|
|
|
# PKG=./wal ./test
|
|
|
|
# PKG=snap ./test
|
2016-12-28 02:15:57 +03:00
|
|
|
#
|
2017-02-24 01:39:34 +03:00
|
|
|
# Run code coverage
|
2017-01-31 03:05:21 +03:00
|
|
|
# COVERDIR must either be a absolute path or a relative path to the etcd root
|
|
|
|
# COVERDIR=coverage PASSES="build_cov cov" ./test
|
2015-07-21 02:32:42 +03:00
|
|
|
set -e
|
2014-09-09 10:06:03 +04:00
|
|
|
|
2016-06-21 22:12:50 +03:00
|
|
|
source ./build
|
|
|
|
|
2017-06-20 01:51:21 +03:00
|
|
|
# build before setting up test GOPATH
|
|
|
|
if [[ "${PASSES}" == *"functional"* ]]; then
|
|
|
|
./tools/functional-tester/build
|
|
|
|
fi
|
|
|
|
|
2016-08-16 23:46:07 +03:00
|
|
|
# build tests with vendored dependencies
|
|
|
|
etcd_setup_gopath
|
|
|
|
|
2016-07-15 04:13:07 +03:00
|
|
|
if [ -z "$PASSES" ]; then
|
2017-04-25 02:10:32 +03:00
|
|
|
PASSES="fmt bom dep compile build unit"
|
2016-07-15 04:13:07 +03:00
|
|
|
fi
|
|
|
|
|
2017-06-03 21:02:08 +03:00
|
|
|
USERPKG=${PKG:-}
|
|
|
|
|
2014-09-09 10:06:03 +04:00
|
|
|
# Invoke ./cover for HTML output
|
|
|
|
COVER=${COVER:-"-cover"}
|
|
|
|
|
2014-09-23 04:11:20 +04:00
|
|
|
# Hack: gofmt ./ will recursively check the .git directory. So use *.go for gofmt.
|
2017-04-13 00:13:30 +03:00
|
|
|
IGNORE_PKGS="(cmd/|etcdserverpb|rafttest|gopath.proto|v3lockpb|v3electionpb)"
|
2016-06-17 21:17:17 +03:00
|
|
|
INTEGRATION_PKGS="(integration|e2e|contrib|functional-tester)"
|
2017-03-14 09:58:29 +03:00
|
|
|
|
|
|
|
# all github.com/coreos/etcd/whatever pkgs that are not auto-generated / tools
|
2017-09-08 04:37:33 +03:00
|
|
|
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)
|
2017-03-14 09:58:29 +03:00
|
|
|
# pkg1,pkg2,pkg3
|
2017-06-03 21:02:08 +03:00
|
|
|
PKGS_COMMA=${PKGS// /,}
|
2017-03-14 09:58:29 +03:00
|
|
|
|
2017-09-08 04:37:33 +03:00
|
|
|
TEST_PKGS=$(find . -name \*_test.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
|
|
|
|
FORMATTABLE=$(find . -name \*.go | while read -r a; do echo "$(dirname "$a")/*.go"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
|
|
|
|
TESTABLE_AND_FORMATTABLE=$(echo "$TEST_PKGS" | grep -vE "$INTEGRATION_PKGS")
|
2014-09-09 10:06:03 +04:00
|
|
|
|
2017-06-03 21:02:08 +03:00
|
|
|
# check if user provided PKG override
|
|
|
|
if [ -z "${USERPKG}" ]; then
|
2014-10-30 02:14:31 +03:00
|
|
|
TEST=$TESTABLE_AND_FORMATTABLE
|
2014-09-09 10:06:03 +04:00
|
|
|
FMT=$FORMATTABLE
|
|
|
|
else
|
|
|
|
# strip out leading dotslashes and trailing slashes from PKG=./foo/
|
2017-06-03 21:02:08 +03:00
|
|
|
TEST=${USERPKG/#./}
|
2014-09-09 10:06:03 +04:00
|
|
|
TEST=${TEST/#\//}
|
|
|
|
TEST=${TEST/%\//}
|
|
|
|
# only run gofmt on packages provided by user
|
|
|
|
FMT="$TEST"
|
|
|
|
fi
|
2017-09-06 20:38:08 +03:00
|
|
|
FMT=($FMT)
|
2014-09-09 10:06:03 +04:00
|
|
|
|
2017-06-07 01:20:39 +03:00
|
|
|
# prepend REPO_PATH to each local package
|
|
|
|
split=$TEST
|
|
|
|
TEST=""
|
|
|
|
for a in $split; do TEST="$TEST ${REPO_PATH}/${a}"; done
|
2017-09-06 20:38:08 +03:00
|
|
|
TEST=($TEST)
|
2017-06-03 21:02:08 +03:00
|
|
|
|
|
|
|
# TODO: 'client' pkg fails with gosimple from generated files
|
|
|
|
# TODO: 'rafttest' is failing with unused
|
2017-09-08 04:37:33 +03:00
|
|
|
STATIC_ANALYSIS_PATHS=$(find . -name \*.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | grep -v 'client')
|
2017-09-06 20:38:08 +03:00
|
|
|
STATIC_ANALYSIS_PATHS=($STATIC_ANALYSIS_PATHS)
|
2017-06-03 21:02:08 +03:00
|
|
|
|
|
|
|
if [ -z "$GOARCH" ]; then
|
|
|
|
GOARCH=$(go env GOARCH);
|
|
|
|
fi
|
|
|
|
|
2016-07-15 04:13:07 +03:00
|
|
|
# determine whether target supports race detection
|
2016-10-04 23:42:53 +03:00
|
|
|
if [ "$GOARCH" == "amd64" ]; then
|
2016-03-27 12:07:32 +03:00
|
|
|
RACE="--race"
|
|
|
|
fi
|
2014-09-09 10:06:03 +04:00
|
|
|
|
2016-07-15 04:13:07 +03:00
|
|
|
function unit_pass {
|
|
|
|
echo "Running unit tests..."
|
2017-10-23 23:12:43 +03:00
|
|
|
GO_TEST_FLAG=""
|
|
|
|
if [ "${VERBOSE}" == "1" ]; then
|
|
|
|
GO_TEST_FLAG="-v"
|
|
|
|
fi
|
|
|
|
if [ "${VERBOSE}" == "2" ]; then
|
|
|
|
GO_TEST_FLAG="-v"
|
|
|
|
export CLIENT_DEBUG=1
|
|
|
|
fi
|
2016-04-15 10:18:24 +03:00
|
|
|
# only -run=Test so examples can run in integration tests
|
2017-10-23 23:12:43 +03:00
|
|
|
go test ${GO_TEST_FLAG} -timeout 3m "${COVER}" ${RACE} -cpu 1,2,4 -run=Test "$@" "${TEST[@]}"
|
2016-01-18 11:07:09 +03:00
|
|
|
}
|
2014-09-09 10:06:03 +04:00
|
|
|
|
2016-07-15 04:13:07 +03:00
|
|
|
function integration_pass {
|
|
|
|
echo "Running integration tests..."
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/integration"
|
|
|
|
integration_extra "$@"
|
2017-08-25 08:55:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function integration_extra {
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -timeout 1m -v ${RACE} -cpu 1,2,4 "$@" "${REPO_PATH}/client/integration"
|
|
|
|
go test -timeout 15m -v ${RACE} -cpu 1,2,4 "$@" "${REPO_PATH}/clientv3/integration"
|
|
|
|
go test -timeout 1m -v -cpu 1,2,4 "$@" "${REPO_PATH}/contrib/raftexample"
|
|
|
|
go test -timeout 5m -v ${RACE} -tags v2v3 "$@" "${REPO_PATH}/store"
|
|
|
|
go test -timeout 1m -v ${RACE} -cpu 1,2,4 -run=Example "$@" "${TEST[@]}"
|
2016-10-06 01:35:14 +03:00
|
|
|
}
|
|
|
|
|
2017-06-20 01:51:21 +03:00
|
|
|
function functional_pass {
|
2017-11-14 23:17:15 +03:00
|
|
|
# Clean up any data and logs from previous runs
|
|
|
|
rm -rf ./agent-*
|
|
|
|
|
2017-06-20 01:51:21 +03:00
|
|
|
for a in 1 2 3; do
|
|
|
|
mkdir -p ./agent-$a
|
|
|
|
./bin/etcd-agent -etcd-path ./bin/etcd -etcd-log-dir "./agent-$a" -port ":${a}9027" -use-root=false &
|
|
|
|
pid="$!"
|
|
|
|
agent_pids="${agent_pids} $pid"
|
|
|
|
done
|
|
|
|
|
2017-07-13 00:46:43 +03:00
|
|
|
for a in 1 2 3; do
|
|
|
|
echo "Waiting for 'etcd-agent' on ${a}9027..."
|
|
|
|
while ! nc -z localhost ${a}9027; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Starting 'etcd-tester'"
|
2017-06-20 01:51:21 +03:00
|
|
|
./bin/etcd-tester \
|
|
|
|
-agent-endpoints "127.0.0.1:19027,127.0.0.1:29027,127.0.0.1:39027" \
|
|
|
|
-client-ports 12379,22379,32379 \
|
|
|
|
-peer-ports 12380,22380,32380 \
|
|
|
|
-limit 1 \
|
|
|
|
-schedule-cases "0 1 2 3 4 5" \
|
2017-07-13 00:46:43 +03:00
|
|
|
-exit-on-failure && echo "'etcd-tester' succeeded"
|
2017-06-20 01:51:21 +03:00
|
|
|
ETCD_TESTER_EXIT_CODE=$?
|
|
|
|
echo "ETCD_TESTER_EXIT_CODE:" ${ETCD_TESTER_EXIT_CODE}
|
|
|
|
|
|
|
|
echo "Waiting for processes to exit"
|
2017-09-06 20:38:08 +03:00
|
|
|
agent_pids=($agent_pids)
|
|
|
|
kill -s TERM "${agent_pids[@]}"
|
|
|
|
for a in "${agent_pids[@]}"; do wait "$a" || true; done
|
2017-06-20 01:51:21 +03:00
|
|
|
|
|
|
|
if [[ "${ETCD_TESTER_EXIT_CODE}" -ne "0" ]]; then
|
2017-11-03 08:39:34 +03:00
|
|
|
echo "--- FAIL: exit code" ${ETCD_TESTER_EXIT_CODE}
|
2017-06-20 01:51:21 +03:00
|
|
|
exit ${ETCD_TESTER_EXIT_CODE}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-12-28 02:15:57 +03:00
|
|
|
function cov_pass {
|
|
|
|
echo "Running code coverage..."
|
|
|
|
# install gocovmerge before running code coverage from github.com/wadey/gocovmerge
|
2017-02-24 01:39:34 +03:00
|
|
|
# gocovmerge merges coverage files
|
2016-12-28 02:15:57 +03:00
|
|
|
if ! which gocovmerge >/dev/null; then
|
|
|
|
echo "gocovmerge not installed"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$COVERDIR" ]; then
|
|
|
|
echo "COVERDIR undeclared"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2017-01-31 03:05:21 +03:00
|
|
|
if [ ! -f "bin/etcd_test" ]; then
|
|
|
|
echo "etcd_test binary not found"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2016-12-28 02:15:57 +03:00
|
|
|
mkdir -p "$COVERDIR"
|
|
|
|
|
2017-01-31 03:05:21 +03:00
|
|
|
# run code coverage for unit and integration tests
|
2017-09-06 20:38:08 +03:00
|
|
|
GOCOVFLAGS="-covermode=set -coverpkg ${PKGS_COMMA} -v -timeout 15m"
|
2017-09-17 10:33:56 +03:00
|
|
|
GOCOVFLAGS=($GOCOVFLAGS)
|
2017-04-04 20:44:29 +03:00
|
|
|
failed=""
|
2017-09-08 04:37:33 +03:00
|
|
|
for t in $(echo "${TEST_PKGS}" | grep -vE "(e2e|functional-tester)"); do
|
2017-09-06 20:38:08 +03:00
|
|
|
tf=$(echo "$t" | tr / _)
|
2017-03-09 09:24:16 +03:00
|
|
|
# cache package compilation data for faster repeated builds
|
2017-09-06 20:38:08 +03:00
|
|
|
go test "${GOCOVFLAGS[@]}" -i "${REPO_PATH}/$t" || true
|
2017-01-31 03:05:21 +03:00
|
|
|
# uses -run=Test to skip examples because clientv3/ example tests will leak goroutines
|
2017-09-06 20:38:08 +03:00
|
|
|
go test "${GOCOVFLAGS[@]}" -run=Test -coverprofile "$COVERDIR/${tf}.coverprofile" "${REPO_PATH}/$t" || failed="$failed $t"
|
2016-12-28 02:15:57 +03:00
|
|
|
done
|
|
|
|
|
2017-08-25 08:55:41 +03:00
|
|
|
# v2v3 tests
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -tags v2v3 "${GOCOVFLAGS[@]}" -coverprofile "$COVERDIR/store-v2v3.coverprofile" "${REPO_PATH}/clientv3/integration" || failed="$failed store-v2v3"
|
2017-08-25 08:55:41 +03:00
|
|
|
|
2017-03-24 04:27:09 +03:00
|
|
|
# proxy tests
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -tags cluster_proxy "${GOCOVFLAGS[@]}" -coverprofile "$COVERDIR/proxy_integration.coverprofile" "${REPO_PATH}/integration" || failed="$failed proxy-integration"
|
|
|
|
go test -tags cluster_proxy "${GOCOVFLAGS[@]}" -coverprofile "$COVERDIR/proxy_clientv3.coverprofile" "${REPO_PATH}/clientv3/integration" || failed="$failed proxy-clientv3/integration"
|
2017-03-24 04:27:09 +03:00
|
|
|
|
2017-01-31 03:05:21 +03:00
|
|
|
# run code coverage for e2e tests
|
2017-02-24 01:39:34 +03:00
|
|
|
# use 30m timeout because e2e coverage takes longer
|
2017-01-31 03:05:21 +03:00
|
|
|
# due to many tests cause etcd process to wait
|
|
|
|
# on leadership transfer timeout during gracefully shutdown
|
2017-07-19 01:12:07 +03:00
|
|
|
echo Testing e2e without proxy...
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -tags cov -timeout 30m -v "${REPO_PATH}/e2e" || failed="$failed e2e"
|
2017-07-19 01:12:07 +03:00
|
|
|
echo Testing e2e with proxy...
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -tags "cov cluster_proxy" -timeout 30m -v "${REPO_PATH}/e2e" || failed="$failed e2e-proxy"
|
2017-01-31 03:05:21 +03:00
|
|
|
|
2017-05-31 23:50:09 +03:00
|
|
|
# incrementally merge to get coverage data even if some coverage files are corrupted
|
|
|
|
# optimistically assume etcdserver package's coverage file is OK since gocovmerge
|
|
|
|
# expects to start with a non-empty file
|
|
|
|
cp "$COVERDIR"/etcdserver.coverprofile "$COVERDIR"/cover.out
|
|
|
|
for f in "$COVERDIR"/*.coverprofile; do
|
2017-09-06 20:38:08 +03:00
|
|
|
gocovmerge "$f" "$COVERDIR"/cover.out >"$COVERDIR"/cover.tmp || failed="$failed $f"
|
2017-05-31 23:50:09 +03:00
|
|
|
if [ -s "$COVERDIR"/cover.tmp ]; then
|
|
|
|
mv "$COVERDIR"/cover.tmp "$COVERDIR"/cover.out
|
|
|
|
fi
|
|
|
|
done
|
2017-04-10 22:32:13 +03:00
|
|
|
# strip out generated files (using GNU-style sed)
|
|
|
|
sed --in-place '/generated.go/d' "$COVERDIR"/cover.out || true
|
2017-04-04 20:44:29 +03:00
|
|
|
|
|
|
|
# held failures to generate the full coverage file, now fail
|
|
|
|
if [ -n "$failed" ]; then
|
|
|
|
for f in $failed; do
|
2017-11-03 08:39:34 +03:00
|
|
|
echo "--- FAIL:" "$f"
|
2017-04-04 20:44:29 +03:00
|
|
|
done
|
|
|
|
exit 255
|
|
|
|
fi
|
2016-12-28 02:15:57 +03:00
|
|
|
}
|
|
|
|
|
2016-10-06 01:35:14 +03:00
|
|
|
function e2e_pass {
|
|
|
|
echo "Running e2e tests..."
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/e2e"
|
2016-10-06 01:35:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function integration_e2e_pass {
|
|
|
|
echo "Running integration and e2e tests..."
|
2016-07-11 20:43:42 +03:00
|
|
|
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/e2e" &
|
2016-04-28 20:02:36 +03:00
|
|
|
e2epid="$!"
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/integration" &
|
2016-05-16 16:32:38 +03:00
|
|
|
intpid="$!"
|
2016-04-28 20:02:36 +03:00
|
|
|
wait $e2epid
|
|
|
|
wait $intpid
|
2017-09-06 20:38:08 +03:00
|
|
|
integration_extra "$@"
|
2016-01-18 11:07:09 +03:00
|
|
|
}
|
2014-09-09 10:06:03 +04:00
|
|
|
|
2016-07-06 19:27:02 +03:00
|
|
|
function grpcproxy_pass {
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -timeout 20m -v ${RACE} -tags cluster_proxy -cpu 1,2,4 "$@" "${REPO_PATH}/integration"
|
|
|
|
go test -timeout 20m -v ${RACE} -tags cluster_proxy -cpu 1,2,4 "$@" "${REPO_PATH}/clientv3/integration"
|
|
|
|
go test -timeout 15m -v -tags cluster_proxy "$@" "${REPO_PATH}/e2e"
|
2016-07-06 19:27:02 +03:00
|
|
|
}
|
|
|
|
|
2016-07-15 04:13:07 +03:00
|
|
|
function release_pass {
|
2016-10-04 23:42:53 +03:00
|
|
|
rm -f ./bin/etcd-last-release
|
2016-08-31 06:54:07 +03:00
|
|
|
# to grab latest patch release; bump this up for every minor release
|
2017-05-25 00:31:30 +03:00
|
|
|
UPGRADE_VER=$(git tag -l --sort=-version:refname "v3.2.*" | head -1)
|
2016-07-15 04:13:07 +03:00
|
|
|
if [ -n "$MANUAL_VER" ]; then
|
|
|
|
# in case, we need to test against different version
|
|
|
|
UPGRADE_VER=$MANUAL_VER
|
|
|
|
fi
|
2017-06-19 18:30:42 +03:00
|
|
|
if [[ -z ${UPGRADE_VER} ]]; then
|
|
|
|
UPGRADE_VER="v3.2.0"
|
|
|
|
echo "fallback to" ${UPGRADE_VER}
|
|
|
|
fi
|
2016-10-04 23:42:53 +03:00
|
|
|
|
|
|
|
local file="etcd-$UPGRADE_VER-linux-$GOARCH.tar.gz"
|
|
|
|
echo "Downloading $file"
|
|
|
|
|
|
|
|
set +e
|
2017-09-06 20:38:08 +03:00
|
|
|
curl --fail -L "https://github.com/coreos/etcd/releases/download/$UPGRADE_VER/$file" -o "/tmp/$file"
|
2016-10-04 23:42:53 +03:00
|
|
|
local result=$?
|
|
|
|
set -e
|
|
|
|
case $result in
|
|
|
|
0) ;;
|
2017-11-03 08:39:34 +03:00
|
|
|
*) echo "--- FAIL:" ${result}
|
2017-06-19 18:30:42 +03:00
|
|
|
exit $result
|
2016-10-04 23:42:53 +03:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2017-09-06 20:38:08 +03:00
|
|
|
tar xzvf "/tmp/$file" -C /tmp/ --strip-components=1
|
2016-10-04 23:42:53 +03:00
|
|
|
mkdir -p ./bin
|
2016-07-15 04:13:07 +03:00
|
|
|
mv /tmp/etcd ./bin/etcd-last-release
|
|
|
|
}
|
|
|
|
|
|
|
|
function fmt_pass {
|
|
|
|
toggle_failpoints disable
|
|
|
|
|
2016-01-18 11:07:09 +03:00
|
|
|
echo "Checking gofmt..."
|
2017-09-06 20:38:08 +03:00
|
|
|
fmtRes=$(gofmt -l -s -d "${FMT[@]}")
|
2016-01-18 11:07:09 +03:00
|
|
|
if [ -n "${fmtRes}" ]; then
|
|
|
|
echo -e "gofmt checking failed:\n${fmtRes}"
|
|
|
|
exit 255
|
|
|
|
fi
|
2014-10-21 11:17:36 +04:00
|
|
|
|
2016-01-18 11:07:09 +03:00
|
|
|
echo "Checking govet..."
|
2017-09-06 20:38:08 +03:00
|
|
|
vetRes=$(go vet "${TEST[@]}")
|
2015-08-27 23:23:33 +03:00
|
|
|
if [ -n "${vetRes}" ]; then
|
2016-01-18 11:07:09 +03:00
|
|
|
echo -e "govet checking failed:\n${vetRes}"
|
2015-08-27 23:23:33 +03:00
|
|
|
exit 255
|
|
|
|
fi
|
2015-02-18 00:15:48 +03:00
|
|
|
|
2017-06-04 05:28:01 +03:00
|
|
|
echo "Checking 'go tool vet -all -shadow'..."
|
2017-09-06 20:38:08 +03:00
|
|
|
fmtpkgs=$(for a in "${FMT[@]}"; do dirname "$a"; done | sort | uniq | grep -v "\\.")
|
|
|
|
fmtpkgs=($fmtpkgs)
|
|
|
|
vetRes=$(go tool vet -all -shadow "${fmtpkgs[@]}" 2>&1 | grep -v '/gw/' || true)
|
2017-06-04 05:28:01 +03:00
|
|
|
if [ -n "${vetRes}" ]; then
|
|
|
|
echo -e "govet -all -shadow checking failed:\n${vetRes}"
|
|
|
|
exit 255
|
|
|
|
fi
|
2016-01-18 11:07:09 +03:00
|
|
|
|
2017-06-03 20:47:28 +03:00
|
|
|
if which shellcheck >/dev/null; then
|
|
|
|
echo "Checking shellcheck..."
|
|
|
|
shellcheckResult=$(shellcheck -fgcc build test scripts/* 2>&1 || true)
|
|
|
|
if [ -n "${shellcheckResult}" ]; then
|
2017-09-06 20:38:08 +03:00
|
|
|
echo -e "shellcheck checking failed:\n${shellcheckResult}"
|
|
|
|
exit 255
|
2017-06-03 20:47:28 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-03-03 22:22:51 +03:00
|
|
|
echo "Checking documentation style..."
|
|
|
|
# eschew you
|
2017-09-08 05:59:51 +03:00
|
|
|
yous=$(find . -name \*.md -exec grep -E --color "[Yy]ou[r]?[ '.,;]" {} + | grep -v /v2/ || true)
|
2017-03-03 22:22:51 +03:00
|
|
|
if [ ! -z "$yous" ]; then
|
|
|
|
echo -e "found 'you' in documentation:\n${yous}"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2017-05-03 19:16:57 +03:00
|
|
|
# TODO: check other markdown files when marker handles headers with '[]'
|
|
|
|
if which marker >/dev/null; then
|
|
|
|
echo "Checking marker to find broken links..."
|
2017-09-06 20:38:08 +03:00
|
|
|
markerResult=$(marker --skip-http --root ./Documentation 2>&1 || true)
|
2017-05-03 19:16:57 +03:00
|
|
|
if [ -n "${markerResult}" ]; then
|
|
|
|
echo -e "marker checking failed:\n${markerResult}"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Skipping marker..."
|
|
|
|
fi
|
|
|
|
|
2016-04-08 08:09:04 +03:00
|
|
|
if which goword >/dev/null; then
|
2016-05-11 09:05:58 +03:00
|
|
|
echo "Checking goword..."
|
2016-04-08 08:09:04 +03:00
|
|
|
# get all go files to process
|
2017-09-06 20:38:08 +03:00
|
|
|
gofiles=$(find "${FMT[@]}" -iname '*.go' 2>/dev/null)
|
|
|
|
gofiles_all=($gofiles)
|
2016-04-08 08:09:04 +03:00
|
|
|
# ignore tests and protobuf files
|
2017-09-08 04:37:33 +03:00
|
|
|
gofiles=$(echo "${gofiles_all[@]}" | sort | uniq | sed "s/ /\n/g" | grep -vE "(\\_test.go|\\.pb\\.go)")
|
2017-09-06 20:38:08 +03:00
|
|
|
gofiles=($gofiles)
|
2016-04-08 08:09:04 +03:00
|
|
|
# only check for broken exported godocs
|
2017-09-06 20:38:08 +03:00
|
|
|
gowordRes=$(goword -use-spell=false "${gofiles[@]}" | grep godoc-export | sort)
|
2016-04-08 08:09:04 +03:00
|
|
|
if [ ! -z "$gowordRes" ]; then
|
|
|
|
echo -e "goword checking failed:\n${gowordRes}"
|
|
|
|
exit 255
|
|
|
|
fi
|
2017-09-04 13:09:32 +03:00
|
|
|
# check some spelling
|
|
|
|
gowordRes=$(goword -ignore-file=.words clientv3/{*,*/*}.go 2>&1 | grep spell | sort)
|
|
|
|
if [ ! -z "$gowordRes" ]; then
|
|
|
|
echo -e "goword checking failed:\n${gowordRes}"
|
|
|
|
exit 255
|
|
|
|
fi
|
2016-04-08 08:09:04 +03:00
|
|
|
else
|
2016-05-11 09:05:58 +03:00
|
|
|
echo "Skipping goword..."
|
2016-04-08 08:09:04 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if which gosimple >/dev/null; then
|
2016-05-11 09:05:58 +03:00
|
|
|
echo "Checking gosimple..."
|
2017-09-06 20:38:08 +03:00
|
|
|
gosimpleResult=$(gosimple "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
|
2017-04-07 07:24:39 +03:00
|
|
|
if [ -n "${gosimpleResult}" ]; then
|
2017-09-08 05:59:51 +03:00
|
|
|
echo -e "gosimple checking failed:\n${gosimpleResult}"
|
|
|
|
exit 255
|
2017-03-02 08:38:39 +03:00
|
|
|
fi
|
2016-04-08 08:09:04 +03:00
|
|
|
else
|
2016-05-11 09:05:58 +03:00
|
|
|
echo "Skipping gosimple..."
|
2016-04-08 08:09:04 +03:00
|
|
|
fi
|
2016-12-09 22:16:03 +03:00
|
|
|
|
2016-04-08 08:09:04 +03:00
|
|
|
if which unused >/dev/null; then
|
2016-05-11 09:05:58 +03:00
|
|
|
echo "Checking unused..."
|
2017-09-06 20:38:08 +03:00
|
|
|
unusedResult=$(unused "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
|
2017-03-02 08:38:39 +03:00
|
|
|
if [ -n "${unusedResult}" ]; then
|
|
|
|
echo -e "unused checking failed:\n${unusedResult}"
|
|
|
|
exit 255
|
|
|
|
fi
|
2016-04-08 08:09:04 +03:00
|
|
|
else
|
2016-05-11 09:05:58 +03:00
|
|
|
echo "Skipping unused..."
|
2016-02-21 14:52:15 +03:00
|
|
|
fi
|
|
|
|
|
2017-03-09 03:21:52 +03:00
|
|
|
if which staticcheck >/dev/null; then
|
2017-03-07 00:38:02 +03:00
|
|
|
echo "Checking staticcheck..."
|
2017-09-06 20:38:08 +03:00
|
|
|
staticcheckResult=$(staticcheck "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
|
2017-04-07 07:24:39 +03:00
|
|
|
if [ -n "${staticcheckResult}" ]; then
|
|
|
|
# TODO: resolve these after go1.8 migration
|
|
|
|
# See https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
|
2017-09-07 03:25:26 +03:00
|
|
|
STATIC_CHECK_MASK="SA(1012|1019|2002)"
|
2017-09-08 04:37:33 +03:00
|
|
|
if echo "${staticcheckResult}" | grep -vE "$STATIC_CHECK_MASK"; then
|
2017-06-03 21:02:08 +03:00
|
|
|
echo -e "staticcheck checking failed:\n${staticcheckResult}"
|
2017-04-07 07:24:39 +03:00
|
|
|
exit 255
|
|
|
|
else
|
2017-09-06 20:38:08 +03:00
|
|
|
suppressed=$(echo "${staticcheckResult}" | sed 's/ /\n/g' | grep "(SA" | sort | uniq -c)
|
2017-04-07 07:24:39 +03:00
|
|
|
echo -e "staticcheck suppressed warnings:\n${suppressed}"
|
|
|
|
fi
|
2017-03-07 00:38:02 +03:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Skipping staticcheck..."
|
|
|
|
fi
|
|
|
|
|
2017-10-03 12:14:02 +03:00
|
|
|
if which ineffassign >/dev/null; then
|
|
|
|
echo "Checking ineffassign..."
|
|
|
|
ineffassignResult=$(ineffassign "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
|
|
|
|
if [ -n "${ineffassignResult}" ]; then
|
|
|
|
echo -e "ineffassign checking failed:\n${ineffassignResult}"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Skipping ineffassign..."
|
|
|
|
fi
|
|
|
|
|
2017-11-11 04:55:55 +03:00
|
|
|
if which nakedret >/dev/null; then
|
|
|
|
echo "Checking nakedret..."
|
|
|
|
nakedretResult=$(nakedret "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
|
|
|
|
if [ -n "${nakedretResult}" ]; then
|
|
|
|
echo -e "nakedret checking failed:\n${nakedretResult}"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Skipping nakedret..."
|
|
|
|
fi
|
|
|
|
|
2016-01-18 11:07:09 +03:00
|
|
|
echo "Checking for license header..."
|
2017-06-03 21:02:08 +03:00
|
|
|
licRes=""
|
|
|
|
files=$(find . -type f -iname '*.go' ! -path './cmd/*' ! -path './gopath.proto/*')
|
|
|
|
for file in $files; do
|
|
|
|
if ! head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" ; then
|
|
|
|
licRes="${licRes}"$(echo -e " ${file}")
|
|
|
|
fi
|
|
|
|
done
|
2016-01-18 11:07:09 +03:00
|
|
|
if [ -n "${licRes}" ]; then
|
|
|
|
echo -e "license header checking failed:\n${licRes}"
|
|
|
|
exit 255
|
|
|
|
fi
|
2016-06-22 23:08:30 +03:00
|
|
|
|
2017-09-12 13:41:10 +03:00
|
|
|
echo "Checking receiver names..."
|
|
|
|
recvs=$(grep 'func ([^*]' {*,*/*,*/*/*}.go | grep -Ev "(generated|pb/)" | tr ':' ' ' | \
|
|
|
|
awk ' { print $2" "$3" "$4" "$1 }' | sed "s/[a-zA-Z\.]*go//g" | sort | uniq | \
|
|
|
|
grep -Ev "(Descriptor|Proto|_)" | awk ' { print $3" "$4 } ' | sort | uniq -c | grep -v ' 1 ' | awk ' { print $2 } ')
|
|
|
|
if [ -n "${recvs}" ]; then
|
|
|
|
recvs=($recvs)
|
|
|
|
for recv in "${recvs[@]}"; do
|
|
|
|
echo "Mismatched receiver for $recv..."
|
|
|
|
grep "$recv" "${FMT[@]}" | grep 'func ('
|
|
|
|
done
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2016-06-22 23:08:30 +03:00
|
|
|
echo "Checking commit titles..."
|
2017-09-06 20:38:08 +03:00
|
|
|
git log --oneline "$(git merge-base HEAD master)"...HEAD | while read -r l; do
|
|
|
|
commitMsg=$(echo "$l" | cut -f2- -d' ')
|
2016-06-26 15:54:02 +03:00
|
|
|
if [[ "$commitMsg" == Merge* ]]; then
|
2016-06-22 23:08:30 +03:00
|
|
|
# ignore "Merge pull" commits
|
|
|
|
continue
|
|
|
|
fi
|
2016-06-26 15:54:02 +03:00
|
|
|
if [[ "$commitMsg" == Revert* ]]; then
|
2016-06-22 23:08:30 +03:00
|
|
|
# ignore revert commits
|
|
|
|
continue
|
|
|
|
fi
|
2016-06-26 15:54:02 +03:00
|
|
|
|
2017-09-06 20:38:08 +03:00
|
|
|
pkgPrefix=$(echo "$commitMsg" | cut -f1 -d':')
|
|
|
|
spaceCommas=$(echo "$commitMsg" | sed 's/ /\n/g' | grep -c ',$' || echo 0)
|
|
|
|
commaSpaces=$(echo "$commitMsg" | sed 's/,/\n/g' | grep -c '^ ' || echo 0)
|
|
|
|
if [[ $(echo "$commitMsg" | grep -c ":..*") == 0 || "$commitMsg" == "$pkgPrefix" || "$spaceCommas" != "$commaSpaces" ]]; then
|
2016-06-26 15:54:02 +03:00
|
|
|
echo "$l"...
|
|
|
|
echo "Expected commit title format '<package>{\", \"<package>}: <description>'"
|
2016-06-22 23:08:30 +03:00
|
|
|
echo "Got: $l"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
done
|
2016-01-18 11:07:09 +03:00
|
|
|
}
|
2015-09-15 23:54:20 +03:00
|
|
|
|
2017-04-25 02:10:32 +03:00
|
|
|
function bom_pass {
|
|
|
|
if ! which license-bill-of-materials >/dev/null; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo "Checking bill of materials..."
|
|
|
|
license-bill-of-materials \
|
|
|
|
--override-file bill-of-materials.override.json \
|
|
|
|
github.com/coreos/etcd github.com/coreos/etcd/etcdctl >bom-now.json || true
|
|
|
|
if ! diff bill-of-materials.json bom-now.json; then
|
2017-06-03 21:02:08 +03:00
|
|
|
echo "vendored licenses do not match given bill of materials"
|
2017-04-25 02:10:32 +03:00
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
rm bom-now.json
|
|
|
|
}
|
|
|
|
|
2016-07-15 04:13:07 +03:00
|
|
|
function dep_pass {
|
2016-03-17 20:18:35 +03:00
|
|
|
echo "Checking package dependencies..."
|
|
|
|
# don't pull in etcdserver package
|
|
|
|
pushd clientv3 >/dev/null
|
2017-04-19 22:54:10 +03:00
|
|
|
badpkg="(etcdserver$|mvcc$|backend$|grpc-gateway)"
|
2017-09-08 05:59:51 +03:00
|
|
|
deps=$(go list -f '{{ .Deps }}' | sed 's/ /\n/g' | grep -E "${badpkg}" || echo "")
|
2016-03-17 20:18:35 +03:00
|
|
|
popd >/dev/null
|
|
|
|
if [ ! -z "$deps" ]; then
|
|
|
|
echo -e "clientv3 has masked dependencies:\n${deps}"
|
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-01-31 03:05:21 +03:00
|
|
|
function build_cov_pass {
|
|
|
|
out="bin"
|
|
|
|
if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
|
2017-09-06 20:38:08 +03:00
|
|
|
go test -tags cov -c -covermode=set -coverpkg="$PKGS_COMMA" -o "${out}/etcd_test"
|
|
|
|
go test -tags cov -c -covermode=set -coverpkg="$PKGS_COMMA" -o "${out}/etcdctl_test" "${REPO_PATH}/etcdctl"
|
2017-01-31 03:05:21 +03:00
|
|
|
}
|
|
|
|
|
2016-07-15 04:13:07 +03:00
|
|
|
function compile_pass {
|
2016-06-29 01:03:19 +03:00
|
|
|
echo "Checking build..."
|
|
|
|
go build -v ./tools/...
|
|
|
|
}
|
|
|
|
|
2016-07-15 04:13:07 +03:00
|
|
|
# fail fast on static tests
|
|
|
|
function build_pass {
|
|
|
|
GO_BUILD_FLAGS="-a -v" etcd_build
|
|
|
|
}
|
|
|
|
|
|
|
|
for pass in $PASSES; do
|
2017-07-06 22:51:24 +03:00
|
|
|
echo "Starting '$pass' pass at $(date)"
|
2017-09-06 20:38:08 +03:00
|
|
|
"${pass}"_pass "$@"
|
2017-07-06 22:51:24 +03:00
|
|
|
echo "Finished '$pass' pass at $(date)"
|
2016-07-15 04:13:07 +03:00
|
|
|
done
|
2016-06-21 22:44:11 +03:00
|
|
|
|
2014-09-09 10:06:03 +04:00
|
|
|
echo "Success"
|