Skip to content

Commit 284ff25

Browse files
committed
Use go test as unit test runner
Problem: Switching to using ginkgo as the test runner caused some issues with verbose output and difficulty finding test failures. This could also be exacerbated by the fact that we mix standard go test style with ginkgo framework tests. Solution: For now, switch back to using go test as the runner, since the output is cleaner and easier to find errors.
1 parent 365bd3f commit 284ff25

File tree

3 files changed

+2
-39
lines changed

3 files changed

+2
-39
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
.github/.cache/buster-for-unit-tests
9191
9292
- name: Run Tests
93-
run: make unit-test CI=true
93+
run: make unit-test
9494

9595
- name: Upload coverage reports to Codecov
9696
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0

Diff for: Makefile

+1-8
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ ifneq (,$(findstring plus,$(MAKECMDGOALS)))
5555
PLUS_ENABLED = true
5656
endif
5757

58-
ifeq ($(CI),true)
59-
GITHUB_OUTPUT := --github-output
60-
endif
61-
6258
.PHONY: help
6359
help: Makefile ## Display this help
6460
@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}'
@@ -191,11 +187,8 @@ lint: ## Run golangci-lint against code
191187

192188
.PHONY: unit-test
193189
unit-test: ## Run unit tests for the go code
194-
# 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.
195-
go test -buildvcs ./cmd/... -race -shuffle=on -coverprofile=cmd-coverage.out -covermode=atomic
196-
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
190+
go test ./... -buildvcs -race -shuffle=on -coverprofile=coverage.out -covermode=atomic
197191
go tool cover -html=coverage.out -o cover.html
198-
go tool cover -html=cmd-coverage.out -o cmd-cover.html
199192

200193
.PHONY: njs-unit-test
201194
njs-unit-test: ## Run unit tests for the njs httpmatches module

Diff for: cmd/gateway/commands_test.go

-30
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,6 @@ func testFlag(t *testing.T, cmd *cobra.Command, test flagTestCase) {
4040
}
4141
}
4242

43-
/*
44-
This test cannot be run with ginkgo. Ginkgo reports the following error:
45-
* Unexpected error:
46-
* <*errors.errorString | 0xc0004746b0>:
47-
* unknown flag: --test.v
48-
* {
49-
* s: "unknown flag: --test.v",
50-
* }
51-
* occurred
52-
*
53-
* This is because cobra sets the args of the command to the OS args when args are nil, and adds the testing flags
54-
* that ginkgo passes to the testing binary as flags on the command. This does not happen with the `go test` flags
55-
* because those only have one dash (e.g. -test) and are ignored by cobra.
56-
* See https://github.com/spf13/cobra/issues/2104.
57-
*/
5843
func TestRootCmd(t *testing.T) {
5944
t.Parallel()
6045
testCase := flagTestCase{
@@ -410,21 +395,6 @@ func TestProvisionerModeCmdFlagValidation(t *testing.T) {
410395
testFlag(t, createProvisionerModeCommand(), testCase)
411396
}
412397

413-
/*
414-
This test cannot be run with ginkgo. Ginkgo reports the following error for the "omitted flag" case:
415-
* Unexpected error:
416-
* <*errors.errorString | 0xc0004746b0>:
417-
* unknown flag: --test.v
418-
* {
419-
* s: "unknown flag: --test.v",
420-
* }
421-
* occurred
422-
*
423-
* This is because cobra sets the args of the command to the OS args when args are nil, and adds the testing flags
424-
* that ginkgo passes to the testing binary as flags on the command. This does not happen with the `go test` flags
425-
* because those only have one dash (e.g. -test) and are ignored by cobra.
426-
* See https://github.com/spf13/cobra/issues/2104.
427-
*/
428398
func TestSleepCmdFlagValidation(t *testing.T) {
429399
t.Parallel()
430400
tests := []flagTestCase{

0 commit comments

Comments
 (0)