Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use go test as unit test runner #2613

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ coverage:
informational: true
comment:
require_changes: true
ignore:
- "**/fake_*.go"
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
.github/.cache/buster-for-unit-tests

- name: Run Tests
run: make unit-test CI=true
run: make unit-test

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
Expand Down
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ ifneq (,$(findstring plus,$(MAKECMDGOALS)))
PLUS_ENABLED = true
endif

ifeq ($(CI),true)
GITHUB_OUTPUT := --github-output
endif

sjberman marked this conversation as resolved.
Show resolved Hide resolved
.PHONY: help
help: Makefile ## Display this help
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n\n make \033[36m<target>\033[0m [VARIABLE=value...]\n\nTargets:\n\n"}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down Expand Up @@ -191,11 +187,8 @@ lint: ## Run golangci-lint against code

.PHONY: unit-test
unit-test: ## Run unit tests for the go code
# We have to run the tests in the cmd package using `go test` because of a bug with the CLI library cobra. See https://github.com/spf13/cobra/issues/2104.
go test -buildvcs ./cmd/... -race -shuffle=on -coverprofile=cmd-coverage.out -covermode=atomic
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --race --keep-going --fail-on-pending --fail-fast --trace --covermode=atomic --coverprofile=coverage.out --force-newlines $(GITHUB_OUTPUT) -p -v -r internal
go test ./cmd/... ./internal/... -buildvcs -race -shuffle=on -coverprofile=coverage.out -covermode=atomic
go tool cover -html=coverage.out -o cover.html
go tool cover -html=cmd-coverage.out -o cmd-cover.html

.PHONY: njs-unit-test
njs-unit-test: ## Run unit tests for the njs httpmatches module
Expand Down
30 changes: 0 additions & 30 deletions cmd/gateway/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,6 @@ func testFlag(t *testing.T, cmd *cobra.Command, test flagTestCase) {
}
}

/*
This test cannot be run with ginkgo. Ginkgo reports the following error:
* Unexpected error:
* <*errors.errorString | 0xc0004746b0>:
* unknown flag: --test.v
* {
* s: "unknown flag: --test.v",
* }
* occurred
*
* This is because cobra sets the args of the command to the OS args when args are nil, and adds the testing flags
* that ginkgo passes to the testing binary as flags on the command. This does not happen with the `go test` flags
* because those only have one dash (e.g. -test) and are ignored by cobra.
* See https://github.com/spf13/cobra/issues/2104.
*/
func TestRootCmd(t *testing.T) {
t.Parallel()
testCase := flagTestCase{
Expand Down Expand Up @@ -410,21 +395,6 @@ func TestProvisionerModeCmdFlagValidation(t *testing.T) {
testFlag(t, createProvisionerModeCommand(), testCase)
}

/*
This test cannot be run with ginkgo. Ginkgo reports the following error for the "omitted flag" case:
* Unexpected error:
* <*errors.errorString | 0xc0004746b0>:
* unknown flag: --test.v
* {
* s: "unknown flag: --test.v",
* }
* occurred
*
* This is because cobra sets the args of the command to the OS args when args are nil, and adds the testing flags
* that ginkgo passes to the testing binary as flags on the command. This does not happen with the `go test` flags
* because those only have one dash (e.g. -test) and are ignored by cobra.
* See https://github.com/spf13/cobra/issues/2104.
*/
func TestSleepCmdFlagValidation(t *testing.T) {
t.Parallel()
tests := []flagTestCase{
Expand Down
4 changes: 4 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ ifneq ($(GINKGO_LABEL),)
override GINKGO_FLAGS += --label-filter "$(GINKGO_LABEL)"
endif

ifeq ($(CI),true)
GITHUB_OUTPUT := --github-output
endif

.PHONY: update-go-modules
update-go-modules: ## Update the gateway-api go modules to latest main version
go get -u sigs.k8s.io/gateway-api@main
Expand Down
Loading