-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Improve tests reliability (#32)
With this change we are doing several things in order to improve the reliability of the tests - We are exporting the db schema and verifying that is the same as the migrations would generate. - Use generated schema from pg_dump to initialise testcontainer, this simplifies a lot the setup of the tests. - Bring back our testcontainer util, waiting for the log is ok but is not reliable at all. We are now doing a sql check. - Merged all CI files into one for simplicity
- Loading branch information
1 parent
1608dca
commit be1b108
Showing
19 changed files
with
463 additions
and
252 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
name: ci | ||
permissions: { } # no need any permissions | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
schedule: | ||
- cron: '0 10 * * 1' # run "At 10:00 on Monday" | ||
workflow_call: | ||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
go: [ '1.20', '1.21' ] | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
- name: Install Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
check-latest: true | ||
- run: go version | ||
- name: Go Format | ||
run: gofmt -s -w . && git diff --exit-code | ||
- name: Go Tidy | ||
run: go mod tidy && git diff --exit-code | ||
- name: Go Vet | ||
run: go vet ./... | ||
- name: Go Download | ||
run: go mod download | ||
- name: Go Mod Verify | ||
run: go mod verify | ||
- uses: sqlc-dev/setup-sqlc@v3 | ||
with: | ||
sqlc-version: '1.20.0' | ||
- name: Install deps | ||
run: | | ||
go install goa.design/goa/v3/cmd/goa@v3 | ||
go install github.com/rjeczalik/interfaces/cmd/interfacer@latest | ||
go install go.uber.org/mock/mockgen@latest | ||
go install github.com/onsi/ginkgo/v2/ginkgo@latest | ||
- name: Generate | ||
run: | | ||
make generate | ||
go mod tidy # Running go mod tidy because goa's dependency will generate undesired changes | ||
git diff --exit-code | ||
- name: Go Build | ||
run: make build | ||
- name: Go Test | ||
run: make test | ||
- name: Upload Coverage | ||
uses: codecov/codecov-action@v3 | ||
continue-on-error: true | ||
with: | ||
token: ${{secrets.CODECOV_TOKEN}} | ||
file: ./cover.profile | ||
fail_ci_if_error: false | ||
- name: Test Summary | ||
uses: test-summary/action@v2 | ||
with: | ||
paths: | | ||
report.xml | ||
if: always() | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 'stable' | ||
check-latest: true | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Lint | ||
uses: golangci/[email protected] | ||
with: | ||
version: latest | ||
args: --timeout 5m | ||
db: | ||
name: Sqlc | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: "postgres:14" | ||
env: | ||
POSTGRES_USER: rotabot | ||
POSTGRES_PASSWORD: '' | ||
POSTGRES_DB: rotabot | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
ports: | ||
- 5432:5432 | ||
# needed because the postgres container does not provide a healthcheck | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
timeout-minutes: 5 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: setup-sqlc | ||
uses: sqlc-dev/setup-sqlc@v3 | ||
with: | ||
sqlc-version: '1.20.0' | ||
- name: Run db migrations | ||
run: | | ||
make migrations/up DB_DSN=rotabot:postgres@localhost:5432/rotabot?sslmode=disable | ||
- run: sqlc diff | ||
- run: sqlc vet | ||
migrations: | ||
name: Migrations | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: "postgres:14" | ||
env: | ||
POSTGRES_USER: rotabot | ||
POSTGRES_PASSWORD: '' | ||
POSTGRES_DB: rotabot | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
ports: | ||
- 5432:5432 | ||
# needed because the postgres container does not provide a healthcheck | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
timeout-minutes: 5 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: DB Schema Diff | ||
run: make migrations/test && git diff --exit-code | ||
vuln: | ||
name: Vuln | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 'stable' | ||
check-latest: true | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Install govulncheck | ||
run: go install golang.org/x/vuln/cmd/govulncheck@latest | ||
- name: Run govulncheck | ||
run: govulncheck -test ./... |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ import ( | |
) | ||
|
||
//go:embed "migrations" | ||
var EmbeddedFiles embed.FS | ||
var Migrations embed.FS |
Oops, something went wrong.