Skip to content

Commit a1d5c35

Browse files
authored
Support running examples tests locally (#758)
Use Docker Compose to run MySQL and PostgreSQL locally
1 parent db3d581 commit a1d5c35

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
.PHONY: build test test-examples regen
2+
13
build:
24
go build ./...
35

46
test:
57
go test ./...
68

9+
test-examples:
10+
go test --tags=examples ./...
11+
12+
regen: sqlc-dev
13+
go run ./scripts/regenerate/
14+
715
sqlc-dev:
816
go build -o ~/bin/sqlc-dev ./cmd/sqlc/
917

1018
sqlc-pg-gen:
1119
go build -o ~/bin/sqlc-pg-gen ./internal/tools/sqlc-pg-gen
12-
13-
regen: sqlc-dev
14-
go run ./scripts/regenerate/

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,24 @@ go build -o ~/go/bin/sqlc-dev ./cmd/sqlc
471471

472472
### Running Tests
473473

474-
To run the tests, include the `exp` tag. Without this tag, a few tests will
475-
fail.
474+
```
475+
go test ./...
476+
```
477+
478+
To run the tests in the examples folder, use the `examples` tag.
479+
480+
```
481+
go test --tags=examples ./...
482+
```
483+
484+
These tests require locally-running database instances. Run these databases
485+
using [Docker Compose](https://docs.docker.com/compose/).
476486

477487
```
478-
go test --tags=exp ./...
488+
docker-compose up -d
479489
```
480490

481-
To run the tests in the examples folder, a running PostgreSQL instance is
482-
required. The tests use the following environment variables to connect to the
491+
The tests use the following environment variables to connect to the
483492
database
484493

485494
#### For PostgreSQL
@@ -506,10 +515,6 @@ MYSQL_ROOT_PASSWORD mysecretpassword
506515
MYSQL_DATABASE dinotest
507516
```
508517

509-
```
510-
go test --tags=examples,exp ./...
511-
```
512-
513518
### Regenerate expected test output
514519

515520
If you need to update a large number of expected test output in the

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: "3.8"
2+
services:
3+
mysql:
4+
image: "mysql:8"
5+
ports:
6+
- "3306:3306"
7+
restart: always
8+
environment:
9+
MYSQL_DATABASE: dinotest
10+
MYSQL_PASSWORD: mysecretpassword
11+
MYSQL_ROOT_PASSWORD: mysecretpassword
12+
MYSQL_USER: root
13+
14+
postgresql:
15+
image: "postgres:13"
16+
ports:
17+
- "5432:5432"
18+
restart: always
19+
environment:
20+
POSTGRES_DB: dinotest
21+
POSTGRES_PASSWORD: mysecretpassword
22+
POSTGRES_USER: postgres

0 commit comments

Comments
 (0)