Skip to content

Support running examples tests locally #758

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

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
.PHONY: build test test-examples regen

build:
go build ./...

test:
go test ./...

test-examples:
go test --tags=examples ./...

regen: sqlc-dev
go run ./scripts/regenerate/

sqlc-dev:
go build -o ~/bin/sqlc-dev ./cmd/sqlc/

sqlc-pg-gen:
go build -o ~/bin/sqlc-pg-gen ./internal/tools/sqlc-pg-gen

regen: sqlc-dev
go run ./scripts/regenerate/
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,24 @@ go build -o ~/go/bin/sqlc-dev ./cmd/sqlc

### Running Tests

To run the tests, include the `exp` tag. Without this tag, a few tests will
fail.
```
go test ./...
```

To run the tests in the examples folder, use the `examples` tag.

```
go test --tags=examples ./...
```

These tests require locally-running database instances. Run these databases
using [Docker Compose](https://docs.docker.com/compose/).

```
go test --tags=exp ./...
docker-compose up -d
```

To run the tests in the examples folder, a running PostgreSQL instance is
required. The tests use the following environment variables to connect to the
The tests use the following environment variables to connect to the
database

#### For PostgreSQL
Expand All @@ -506,10 +515,6 @@ MYSQL_ROOT_PASSWORD mysecretpassword
MYSQL_DATABASE dinotest
```

```
go test --tags=examples,exp ./...
```

### Regenerate expected test output

If you need to update a large number of expected test output in the
Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3.8"
services:
mysql:
image: "mysql:8"
ports:
- "3306:3306"
restart: always
environment:
MYSQL_DATABASE: dinotest
MYSQL_PASSWORD: mysecretpassword
MYSQL_ROOT_PASSWORD: mysecretpassword
MYSQL_USER: root

postgresql:
image: "postgres:13"
ports:
- "5432:5432"
restart: always
environment:
POSTGRES_DB: dinotest
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_USER: postgres