Skip to content

Commit 7d6fbe5

Browse files
committed
make test: fix hack/test-go.sh
At least for macOS 11.3, bash 5.1.8, go 1.16.3 the packages were being passed in as one big string, e.g. "foo\nbar". Instead, store the `go list` results in an array, then expand the array to separate args for `go test` Write coverage files to ARTIFACTS or tmp/, and .gitignore tmp/ Other nice to have changes: - move go test flags to an array for legibility - don't depend on git for REPO_ROOT
1 parent 0609953 commit 7d6fbe5

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ Session.vim
2424

2525
# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
2626
.idea/
27+
28+
# hack/test-go.sh writes files here if ARTIFACTS is unset
29+
tmp/

hack/test-go.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
set -euo pipefail
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
1822

1923
# Default timeout is 1800s
20-
TEST_TIMEOUT=1800
24+
TEST_TIMEOUT=${TIMEOUT:-1800}
25+
26+
# Write go test artifacts here
27+
ARTIFACTS=${ARTIFACTS:-"${REPO_ROOT}/tmp"}
2128

2229
for arg in "$@"
2330
do
@@ -33,9 +40,20 @@ do
3340
esac
3441
done
3542

36-
REPO_ROOT=$(git rev-parse --show-toplevel)
3743
cd "${REPO_ROOT}"
3844

39-
GO111MODULE=on go test -v -timeout="${TEST_TIMEOUT}s" -count=1 -cover -coverprofile coverage.out "$(go list ./... | grep -v k8s.io/enhancements/cmd)"
45+
mkdir -p "${ARTIFACTS}"
46+
47+
go_test_flags=(
48+
-v
49+
-count=1
50+
-timeout="${TEST_TIMEOUT}s"
51+
-cover -coverprofile "${ARTIFACTS}/coverage.out"
52+
)
53+
54+
packages=()
55+
mapfile -t packages < <(go list ./... | grep -v k8s.io/enhancements/cmd)
56+
57+
GO111MODULE=on go test "${go_test_flags[@]}" "${packages[@]}"
4058

41-
go tool cover -html coverage.out -o coverage.html
59+
go tool cover -html "${ARTIFACTS}/coverage.out" -o "${ARTIFACTS}/coverage.html"

0 commit comments

Comments
 (0)