Skip to content

Commit 1d2b39b

Browse files
committed
Add docker-compose to run tests locally
1 parent 90498de commit 1d2b39b

File tree

5 files changed

+66
-32
lines changed

5 files changed

+66
-32
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
gorm
2+
go.sum
3+
.*
4+
*.db

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,31 @@ GORM PlayGround can be used to play GORM and reports issues
66

77
### Usage
88

9-
Modify [https://github.com/go-gorm/playground/edit/master/main_test.go](https://github.com/go-gorm/playground/edit/master/main_test.go) and create pull report, your code will runs with sqlite, mysql, postgres and sqlserver with the help of Github Action
9+
Modify [https://github.com/go-gorm/playground/edit/master/main_test.go](https://github.com/go-gorm/playground/edit/master/main_test.go) and create pull report, your code will run with SQLite, MySQL, Postgres and SQL server with the help of Github Action
1010

1111
If you encounter a bug in GORM, please report it at [https://github.com/go-gorm/gorm/issues](https://github.com/go-gorm/gorm/issues) with the PlayGround Pull Request's link
1212

13-
We are using following configuration run your code (GORM's latest master branch, database drivers: sqlite, mysql, postgres, sqlserver), you could change it in the above [link](https://github.com/go-gorm/playground/edit/master/main_test.go)
13+
We are using the following configuration run your code (GORM's latest master branch, database drivers: sqlite, mysql, postgres, sqlserver), you could change it in the above [link](https://github.com/go-gorm/playground/edit/master/main_test.go)
1414

1515
```go
1616
// GORM_REPO: https://github.com/go-gorm/gorm.git
1717
// GORM_BRANCH: master
1818
// TEST_DRIVERS: sqlite, mysql, postgres, sqlserver
1919
```
2020

21-
BTW, we have prepared some structs with relationships in [https://github.com/go-gorm/playground/blob/master/models.go](https://github.com/go-gorm/playground/blob/master/models.go) that you may interested to use
21+
BTW, we have prepared some structs with relationships in [https://github.com/go-gorm/playground/blob/master/models.go](https://github.com/go-gorm/playground/blob/master/models.go) that you may be interested to use
2222

23-
Don't forgot to close your PR after finish play! ;)
23+
### Run Locally
24+
25+
```go
26+
// Setup Databases
27+
docker-compose up
28+
29+
// Run tests with cached GORM and latest drivers
30+
GORM_ENABLE_CACHE=true ./test.sh
31+
32+
// Run tests with latest GORM specified with GORM_REPO, GORM_BRANCH and latest drivers
33+
./test.sh
34+
```
2435

2536
## Happy Hacking!

docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3'
2+
3+
services:
4+
mysql:
5+
image: 'mysql:latest'
6+
ports:
7+
- 9910:3306
8+
environment:
9+
- MYSQL_DATABASE=gorm
10+
- MYSQL_USER=gorm
11+
- MYSQL_PASSWORD=gorm
12+
- MYSQL_RANDOM_ROOT_PASSWORD="yes"
13+
postgres:
14+
image: 'postgres:latest'
15+
ports:
16+
- 9920:5432
17+
environment:
18+
- TZ=Asia/Shanghai
19+
- POSTGRES_DB=gorm
20+
- POSTGRES_USER=gorm
21+
- POSTGRES_PASSWORD=gorm
22+
mssql:
23+
image: 'mcmoe/mssqldocker:latest'
24+
ports:
25+
- 9930:1433
26+
environment:
27+
- ACCEPT_EULA=Y
28+
- SA_PASSWORD=LoremIpsum86
29+
- MSSQL_DB=gorm
30+
- MSSQL_USER=gorm
31+
- MSSQL_PASSWORD=LoremIpsum86
32+

go.mod

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ module gorm.io/playground
33
go 1.14
44

55
require (
6-
github.com/google/uuid v1.1.1
76
github.com/jinzhu/now v1.1.1
8-
github.com/lib/pq v1.6.0
9-
gorm.io/driver/mysql v0.2.3
10-
gorm.io/driver/postgres v0.2.3
11-
gorm.io/driver/sqlite v1.0.7
12-
gorm.io/driver/sqlserver v0.2.2
13-
gorm.io/gorm v0.2.15
7+
gorm.io/driver/mysql v0.2.9
8+
gorm.io/driver/postgres v0.2.5
9+
gorm.io/driver/sqlite v1.0.8
10+
gorm.io/driver/sqlserver v0.2.4
11+
gorm.io/gorm v0.2.20
1412
)
1513

1614
replace gorm.io/gorm => ./gorm
17-

test.sh

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,20 @@ fi
99

1010
[ -d gorm ] || (echo "git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}')"; git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}'))
1111

12-
if [[ $(grep TEST_DRIVER main_test.go) =~ "$GORM_DIALECT" ]]
13-
then
14-
if [ -d tests ]
15-
then
16-
cd tests
17-
cp go.mod go.mod.bak
18-
sed '/$[[:space:]]*gorm.io\/driver/d' go.mod.bak > go.mod
19-
cd ..
20-
fi
12+
cp go.mod go.mod.bak
13+
sed '/gorm.io\/driver/d' go.mod.bak > go.mod
2114

22-
for dialect in "${dialects[@]}" ; do
23-
if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ]
15+
for dialect in "${dialects[@]}" ; do
16+
if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ]
17+
then
18+
if [[ $(grep TEST_DRIVER main_test.go) =~ "${dialect}" ]]
2419
then
2520
echo "testing ${dialect}..."
2621
GORM_DIALECT=${dialect} go test -race -count=1 -v ./...
22+
else
23+
echo "skip ${dialect}..."
2724
fi
28-
done
29-
30-
if [ -d tests ]
31-
then
32-
cd tests
33-
mv go.mod.bak go.mod
3425
fi
35-
else
36-
echo "skip $GORM_DIALECT..."
37-
fi
26+
done
27+
28+
mv go.mod.bak go.mod

0 commit comments

Comments
 (0)