Skip to content

Commit

Permalink
Better testing (christianselig#62)
Browse files Browse the repository at this point in the history
* some tests

* more tests

* tidy up go.mod

* more tests

* add postgres

* beep

* again

* Set up schema

* fix device test
  • Loading branch information
andremedeiros authored May 7, 2022
1 parent 17019ce commit f9b9c59
Show file tree
Hide file tree
Showing 57 changed files with 674 additions and 550 deletions.
4 changes: 4 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DATABASE_URL=postgres://andremedeiros@localhost/apollo_test?sslmode=disable
DATABASE_CONNECTION_POOL_URL=postgres://andremedeiros@localhost/apollo_test?sslmode=disable
REDIS_URL=redis://127.0.0.1:6379
STATSD_URL=127.0.0.1:8125
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,35 @@ jobs:
go-version: [1.18]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
env:
DATABASE_URL: postgres://postgres:postgres@localhost/apollo_test
services:
postgres:
image: postgres
env:
POSTGRES_DB: apollo_test
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Lint
uses: golangci/golangci-lint-action@v2

- name: Setup database schema
run: psql -f docs/schema.sql $DATABASE_URL

- name: Test
run: go test ./... -v -race -timeout 5s
28 changes: 28 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
linters:
enable:
- bodyclose # checks whether HTTP response body is closed successfully
- errcheck # checks for unchecked errors in go programs
- errname # checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`
- exportloopref # checks for pointers to enclosing loop variables
- gochecknoinits # checks that no init functions are present in Go code
- ifshort # checks that your code uses short syntax for if-statements whenever possible
- importas # enforces consistent import aliases
- ineffassign # detects when assignments to existing variables are not used
- noctx # finds sending http request without context.Context
- paralleltest # detects missing usage of t.Parallel() method in go tests
- prealloc # finds slice declarations that could potentially be preallocated
- rowserrcheck # checks whether Err of rows is checked successfully
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
- tenv # detects using os.Setenv instead of t.Setenv
- testpackage # makes you use a separate _test package
- thelper # detects golang test helpers without t.Helper() call and checks consistency of test helpers
- unconvert # removes unnecessary type conversions
- unparam # removes unused function parameters
fast: true

issues:
exclude-rules:
# False positive: https://github.com/kunwardeep/paralleltest/issues/8.
- linters:
- paralleltest
text: "does not use range value in test Run"
8 changes: 0 additions & 8 deletions Brewfile

This file was deleted.

218 changes: 0 additions & 218 deletions Brewfile.lock.json

This file was deleted.

19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BREW_PREFIX ?= $(shell brew --prefix)
DATABASE_URL ?= "postgres://$(USER)@localhost/apollo_test?sslmode=disable"

test:
@DATABASE_URL=$(DATABASE_URL) go test -race -v -timeout 1s ./...

test-setup: $(BREW_PREFIX)/bin/migrate
migrate -path migrations/ -database $(DATABASE_URL) up

build:
@go build ./cmd/apollo

lint:
@golangci-lint run

$(BREW_PREFIX)/bin/migrate:
@brew install golang-migrate

.PHONY: all build deps lint test
3 changes: 0 additions & 3 deletions Procfile

This file was deleted.

4 changes: 0 additions & 4 deletions env.example

This file was deleted.

36 changes: 32 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
module github.com/christianselig/apollo-backend

// +heroku goVersion go1.16
go 1.16
go 1.18

require (
github.com/DataDog/datadog-go v4.8.3+incompatible
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/adjust/rmq/v4 v4.0.5
github.com/bugsnag/bugsnag-go/v2 v2.1.2
github.com/dustin/go-humanize v1.0.0
Expand All @@ -15,12 +13,42 @@ require (
github.com/go-redis/redismock/v8 v8.0.6
github.com/gorilla/mux v1.8.0
github.com/heroku/x v0.0.50
github.com/jackc/pgconn v1.12.0
github.com/jackc/pgx/v4 v4.16.0
github.com/joho/godotenv v1.4.0
github.com/sideshow/apns2 v0.23.0
github.com/sirupsen/logrus v1.8.1
github.com/smtp2go-oss/smtp2go-go v1.0.1 // indirect
github.com/smtp2go-oss/smtp2go-go v1.0.1
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.1
github.com/valyala/fastjson v1.6.3
)

require (
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/bugsnag/panicwrap v1.3.4 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.11.0 // indirect
github.com/jackc/puddle v1.2.1 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading

0 comments on commit f9b9c59

Please sign in to comment.