Run tests

This commit is contained in:
Juan C. Müller 2023-02-19 10:18:04 -05:00
parent ee5f061d24
commit 28cb63336c
No known key found for this signature in database
GPG key ID: A76E55A7FBA1E283
2 changed files with 81 additions and 3 deletions

39
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,39 @@
name: test
on: [push]
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
jobs:
test:
name: test
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14-alpine
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
container: golang:1.20
steps:
- uses: actions/checkout@v3
- name: test
run: make mod test coverage
env:
PGHOST: postgres
PGPORT: 5432
- name: upload results
uses: actions/upload-artifact@v3
with:
name: Upload test coverage
path: tmp/coverage
- name: function coverage
run: make func-coverage

View file

@ -1,4 +1,4 @@
SHELL = /bin/bash
SHELL := /bin/bash
GOLANGCI_LINT_VERSION ?= v1.51.1
all: fmt vet mod
@ -17,21 +17,60 @@ fmt:
vet:
@go vet ./...
.PHONY: test
test: install-gotestsum
@mkdir -p tmp/output tmp/coverage
@gotestsum \
--junitfile tmp/output/gotestsum-report.xml \
-- \
-count=5 \
-race \
-cover \
-coverprofile=tmp/coverage/coverage.out \
./...
.PHONY: coverage
coverage:
@go tool cover -html=tmp/coverage/coverage.out -o tmp/coverage/coverage.html
.PHONY: func-coverage
func-coverage:
@go tool cover -func=tmp/coverage/coverage.out
.PHONY: update-dependencies
update-dependencies:
@go get -u -v ./...
$(MAKE) mod
.PHONY: test-watch
test-watch:
@gotestsum \
--watch \
--junitfile tmp/output/gotestsum-report.xml \
--post-run-command "make coverage" \
-- \
-race \
-cover \
-coverprofile=tmp/coverage/coverage.out \
./...
.PHONY: lint
lint:
@clear
@golangci-lint run .
.PHONY: lint-watch
lint-watch:
lint-watch: install-reflex
@reflex -s -r '\.go$$' -R '^vendor/' -- make lint
.PHONY: install-dev-tools
install-dev-tools:
install-dev-tools: install-gotestsum install-reflex
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_LINT_VERSION)
.PHONY: install-gotestsum
install-gotestsum:
@go install gotest.tools/gotestsum@latest
.PHONY: install-reflex
install-reflex:
@go install github.com/cespare/reflex@latest