Skip to content

Commit

Permalink
Use go test as unit test runner
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjberman committed Sep 26, 2024
1 parent 365bd3f commit 284ff25
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 39 deletions.
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

.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 ./... -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

0 comments on commit 284ff25

Please sign in to comment.