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

test: Add the unit tests to the github action #11

Merged
merged 9 commits into from Mar 15, 2024
Merged
25 changes: 25 additions & 0 deletions .github/workflows/code-health-tools.yml
Expand Up @@ -25,6 +25,31 @@ jobs:
run: |
pushd tools/cli
make build
unit-tests:
needs: build
env:
COVERAGE: coverage.out
TEST_CMD: gotestsum --junitfile unit-tests.xml --format standard-verbose --
UNIT_TAGS: unit
INTEGRATION_TAGS: integration
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Install Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'tools/cli/go.mod'
- name: Install gotest
run: go install gotest.tools/gotestsum@ec99a250836f069a524bb9d9b5de0a7a96334ea7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use this in the cli to have the test summary with failures since gotestsum can produce xunit reports
feel free to use the simpler go test command but I wonder if there's a nicer way to have a summary report of tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this https://github.com/smartystreets/goconvey may be a bit too much. xD

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I don't have a strong opinion I feel in general GH actions lack a good way to represent test summaries, I don't quite like it on the CLI currently and I haven't really found something good enough to what I would expect (a list of tests and the result)

- name: Run unit tests
run: |
pushd tools/cli
andreaangiolillo marked this conversation as resolved.
Show resolved Hide resolved
make unit-test
lint:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -13,3 +13,5 @@
# Tool generated files
*.idea
*.vscode

*.out
7 changes: 7 additions & 0 deletions tools/cli/Makefile
Expand Up @@ -11,6 +11,8 @@ LINKER_GH_SHA_FLAG=-s -w -X github.com/mongodb/openapi/tools/cli/internal/versio
LINKER_FLAGS=${LINKER_GH_SHA_FLAG} -X github.com/mongodb/openapi/tools/cli/internal/version.Version=${VERSION}

DEBUG_FLAGS=all=-N -l
TEST_CMD?=go test
COVERAGE=coverage.out

export TERM := linux-m
export GO111MODULE := on
Expand Down Expand Up @@ -58,6 +60,11 @@ fix-lint: ## Fix linting errors
list: ## List all make targets
@${MAKE} -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort

.PHONY: unit-test
unit-test: ## Run unit-tests
@echo "==> Running unit tests..."
$(TEST_CMD) -race -cover -count=1 -coverprofile $(COVERAGE) ./...
andreaangiolillo marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: gen-mocks
gen-mocks: ## Generate mocks
@echo "==> Generating mocks"
Expand Down