Skip to content

Commit 19467df

Browse files
committed
Squashed 'tools/' changes from 2b3a1bb..b783528
b783528 Tweak test script so it can be run on a mca a3b18bf Merge pull request #65 from weaveworks/fix-integration-tests ecb5602 Fix integration tests f9dcbf6 ... without tab (clearly not my day) a6215c3 Add break I forgot 0e6832d Remove incorrectly added tab eb26c68 Merge pull request #64 from weaveworks/remove-test-package-linting f088e83 Review feedback 2c6e83e Remove test package linting git-subtree-dir: tools git-subtree-split: b783528b75f6ba52a51832bd087bd8347b26f131
1 parent c923cd3 commit 19467df

File tree

3 files changed

+44
-45
lines changed

3 files changed

+44
-45
lines changed

integration/config.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ run_on() {
8181
host=$1
8282
shift 1
8383
[ -z "$DEBUG" ] || greyly echo "Running on $host:" "$@" >&2
84-
remote "$host" "$SSH" "$host" "$@"
84+
# shellcheck disable=SC2086
85+
remote "$host" $SSH "$host" "$@"
8586
}
8687

8788
docker_on() {
@@ -117,7 +118,8 @@ start_suite() {
117118
PLUGIN_ID=$(docker_on "$host" ps -aq --filter=name=weaveplugin)
118119
PLUGIN_FILTER="cat"
119120
[ -n "$PLUGIN_ID" ] && PLUGIN_FILTER="grep -v $PLUGIN_ID"
120-
rm_containers "$host" "$(docker_on "$host" ps -aq 2>/dev/null | "$PLUGIN_FILTER")"
121+
# shellcheck disable=SC2046
122+
rm_containers "$host" $(docker_on "$host" ps -aq 2>/dev/null | $PLUGIN_FILTER)
121123
run_on "$host" "docker network ls | grep -q ' weave ' && docker network rm weave" || true
122124
weave_on "$host" reset 2>/dev/null
123125
done

lint

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
set -e
1919

2020
IGNORE_LINT_COMMENT=
21-
IGNORE_TEST_PACKAGES=
2221
IGNORE_SPELLINGS=
2322
while true; do
2423
case "$1" in
@@ -27,7 +26,7 @@ while true; do
2726
shift 1
2827
;;
2928
-notestpackage)
30-
IGNORE_TEST_PACKAGES=1
29+
# NOOP, still accepted for backwards compatibility
3130
shift 1
3231
;;
3332
-ignorespelling)
@@ -65,30 +64,6 @@ spell_check() {
6564
return $lint_result
6665
}
6766

68-
test_mismatch() {
69-
local filename="$1"
70-
local package=$(grep '^package ' "$filename" | awk '{print $2}')
71-
local lint_result=0
72-
73-
if [[ $package == "main" ]]; then
74-
return # in package main, all bets are off
75-
fi
76-
77-
if [[ $filename == *"_internal_test.go" ]]; then
78-
if [[ $package == *"_test" ]]; then
79-
lint_result=1
80-
echo "${filename}: should not be part of a _test package"
81-
fi
82-
else
83-
if [[ ! $package == *"_test" ]]; then
84-
lint_result=1
85-
echo "${filename}: should be part of a _test package"
86-
fi
87-
fi
88-
89-
return $lint_result
90-
}
91-
9267
lint_go() {
9368
local filename="$1"
9469
local lint_result=0
@@ -183,12 +158,6 @@ lint() {
183158
tf) lint_tf "${filename}" || lint_result=1 ;;
184159
esac
185160

186-
if [ -z "$IGNORE_TEST_PACKAGES" ]; then
187-
if [[ "$filename" == *"_test.go" ]]; then
188-
test_mismatch "${filename}" || lint_result=1
189-
fi
190-
fi
191-
192161
spell_check "${filename}" || lint_result=1
193162

194163
return $lint_result

test

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
set -e
44

55
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6-
GO_TEST_ARGS=(-tags netgo -cpu 4 -timeout 8m)
76
SLOW=
8-
NO_GO_GET=
7+
NO_GO_GET=true
8+
TAGS=
9+
PARALLEL=
910

1011
usage() {
11-
echo "$0 [-slow] [-in-container foo]"
12+
echo "$0 [-slow] [-in-container foo] [-netgo] [-(no-)go-get]"
1213
}
1314

1415
while [ $# -gt 0 ]; do
@@ -21,13 +22,27 @@ while [ $# -gt 0 ]; do
2122
NO_GO_GET=true
2223
shift 1
2324
;;
25+
"-go-get")
26+
NO_GO_GET=
27+
shift 1
28+
;;
29+
"-netgo")
30+
TAGS="-tags netgo"
31+
shift 1
32+
;;
33+
"-p")
34+
PARALLEL=true
35+
shift 1
36+
;;
2437
*)
2538
usage
2639
exit 2
2740
;;
2841
esac
2942
done
3043

44+
GO_TEST_ARGS=($TAGS -cpu 4 -timeout 8m)
45+
3146
if [ -n "$SLOW" ] || [ -n "$CIRCLECI" ]; then
3247
SLOW=true
3348
fi
@@ -69,33 +84,46 @@ PACKAGE_BASE=$(go list -e ./)
6984
# Speed up the tests by compiling and installing their dependencies first.
7085
go test -i "${GO_TEST_ARGS[@]}" "${TESTDIRS[@]}"
7186

72-
for dir in "${TESTDIRS[@]}"; do
87+
run_test() {
88+
local dir=$1
7389
if [ -z "$NO_GO_GET" ]; then
74-
go get -t -tags netgo "$dir"
90+
go get -t $TAGS "$dir"
7591
fi
7692

77-
GO_TEST_ARGS_RUN=("${GO_TEST_ARGS[@]}")
93+
local GO_TEST_ARGS_RUN=("${GO_TEST_ARGS[@]}")
7894
if [ -n "$SLOW" ]; then
79-
COVERPKGS=$( (
95+
local COVERPKGS=$( (
8096
go list "$dir"
8197
go list -f '{{join .Deps "\n"}}' "$dir" | grep -v "vendor" | grep "^$PACKAGE_BASE/"
8298
) | paste -s -d, -)
83-
output=$(mktemp "$coverdir/unit.XXXXXXXXXX")
84-
GO_TEST_ARGS_RUN=("${GO_TEST_ARGS[@]}" -coverprofile=$output -coverpkg=$COVERPKGS)
99+
local output=$(mktemp "$coverdir/unit.XXXXXXXXXX")
100+
local GO_TEST_ARGS_RUN=("${GO_TEST_ARGS[@]}" -coverprofile=$output -coverpkg=$COVERPKGS)
85101
fi
86102

87-
START=$(date +%s)
103+
local START=$(date +%s)
88104
if ! go test "${GO_TEST_ARGS_RUN[@]}" "$dir"; then
89105
fail=1
90106
fi
91-
RUNTIME=$(($(date +%s) - START))
107+
local RUNTIME=$(($(date +%s) - START))
92108

93109
# Report test runtime when running on circle, to help scheduler
94110
if [ -n "$CIRCLECI" ] && [ -z "$NO_SCHEDULER" ] && [ -x "$DIR/sched" ]; then
95111
"$DIR/sched" time "$dir" "$RUNTIME"
96112
fi
113+
}
114+
115+
for dir in "${TESTDIRS[@]}"; do
116+
if [ -n "$PARALLEL" ]; then
117+
run_test "$dir" &
118+
else
119+
run_test "$dir"
120+
fi
97121
done
98122

123+
if [ -n "$PARALLEL" ]; then
124+
wait
125+
fi
126+
99127
if [ -n "$SLOW" ] && [ -z "$COVERDIR" ]; then
100128
go get github.com/weaveworks/tools/cover
101129
cover "$coverdir"/* >profile.cov

0 commit comments

Comments
 (0)