-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Make rules and bash for Go tests
- Loading branch information
Showing
9 changed files
with
1,486 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.16.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright 2021 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
################################################################################ | ||
# ========================== Capture Environment =============================== | ||
# get the repo root and output path | ||
REPO_ROOT:=${CURDIR} | ||
OUT_DIR=$(REPO_ROOT)/out | ||
################################################################################ | ||
# ========================= Setup Go =========================================== | ||
# go1.9+ can autodetect GOROOT, but if some other tool sets it ... | ||
GOROOT:= | ||
# enable modules | ||
GO111MODULE=on | ||
export GOROOT GO111MODULE | ||
################################################################################ | ||
# ================================= Testing ==================================== | ||
# unit tests (hermetic) | ||
unit: | ||
hack/make-rules/go-test/unit.sh | ||
# integration tests | ||
integration: | ||
hack/make-rules/go-test/integration.sh | ||
# all tests | ||
test: | ||
hack/make-rules/go-test/all.sh | ||
################################################################################ | ||
# ================================= Cleanup ==================================== | ||
# standard cleanup target | ||
clean: | ||
rm -rf "$(OUT_DIR)/" | ||
################################################################################ | ||
# ============================== Auto-Update =================================== | ||
# update generated code, gofmt, etc. | ||
update: | ||
hack/make-rules/update/all.sh | ||
# update generated code | ||
generate: | ||
hack/make-rules/update/generated.sh | ||
# gofmt | ||
gofmt: | ||
hack/make-rules/update/gofmt.sh | ||
################################################################################ | ||
# ================================== Linting =================================== | ||
# run linters, ensure generated code, etc. | ||
verify: | ||
hack/make-rules/verify/all.sh | ||
# code linters | ||
lint: | ||
hack/make-rules/verify/lint.sh | ||
# shell linter | ||
shellcheck: | ||
hack/make-rules/verify/shellcheck.sh | ||
################################################################################# | ||
.PHONY: unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2021 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -o pipefail | ||
|
||
# cd to the repo root and setup go | ||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" | ||
cd "${REPO_ROOT}" | ||
|
||
# read go-version file unless GO_VERSION is set | ||
GO_VERSION="${GO_VERSION:-"$(cat .go-version)"}" | ||
|
||
# only setup go if we haven't set FORCE_HOST_GO, or `go version` doesn't match | ||
# go version output looks like: | ||
# go version go1.14.5 darwin/amd64 | ||
if ! ([ -n "${FORCE_HOST_GO:-}" ] || | ||
(command -v go >/dev/null && [ "$(go version | cut -d' ' -f3)" = "go${GO_VERSION}" ])); then | ||
|
||
if ! (command -v gvm >/dev/null); then | ||
bash -c "$(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)" | ||
source /root/.gvm/scripts/gvm | ||
fi | ||
|
||
gvm install go${GO_VERSION} | ||
gvm use go${GO_VERSION} | ||
fi | ||
|
||
# force go modules | ||
export GO111MODULE=on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2021 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -o pipefail | ||
|
||
CUR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" | ||
cd "${CUR_DIR}" | ||
|
||
./unit.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2021 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -o pipefail | ||
|
||
# cd to the repo root and setup go | ||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)" | ||
cd "${REPO_ROOT}" | ||
source hack/build/setup-go.sh | ||
|
||
# build gotestsum | ||
cd 'hack/tools' | ||
go build -o "${REPO_ROOT}/_bin/gotestsum" gotest.tools/gotestsum | ||
cd "${REPO_ROOT}" | ||
|
||
# run unit tests with junit output | ||
( | ||
set -x; | ||
mkdir -p "${REPO_ROOT}/_output" | ||
"${REPO_ROOT}/_bin/gotestsum" --junitfile="${REPO_ROOT}/_output/unit-junit.xml" \ | ||
-- './...' | ||
) | ||
|
||
# if we are in CI, copy to the artifact upload location | ||
if [[ -n "${ARTIFACTS:-}" ]]; then | ||
cp "_output/unit-junit.xml" "${ARTIFACTS:?}/unit-junit.xml" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module k8s.io/test-infra/hack/tools | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/golangci/golangci-lint v1.42.1 | ||
gotest.tools/gotestsum v1.7.0 | ||
k8s.io/code-generator v0.22.2 | ||
) |
Oops, something went wrong.