Skip to content

Commit 4163dc2

Browse files
committed
Use Docker Compose for testing.
1 parent bc14601 commit 4163dc2

File tree

8 files changed

+89
-95
lines changed

8 files changed

+89
-95
lines changed

.testing/testing-server.cnf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[server]
2+
innodb_log_file_size=256MB
3+
innodb_buffer_pool_size=512MB
4+
max_allowed_packet=16MB

.testing/wait_mysql.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
while :
3+
do
4+
sleep 1
5+
if mysql --user=gotest --password=secret --host=127.0.0.1 --port=3307 -e 'SELECT version()'; then
6+
break
7+
fi
8+
done

.travis.yml

Lines changed: 56 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,70 @@
1-
sudo: false
1+
dist: trusty
2+
sudo: required
23
language: go
3-
go:
4-
- 1.7.x
5-
- 1.8.x
6-
- 1.9.x
7-
- master
84

9-
before_install:
10-
- go get golang.org/x/tools/cmd/cover
11-
- go get github.com/mattn/goveralls
5+
services:
6+
- docker
127

13-
before_script:
14-
- echo -e "[server]\ninnodb_log_file_size=256MB\ninnodb_buffer_pool_size=512MB\nmax_allowed_packet=16MB" | sudo tee -a /etc/mysql/my.cnf
15-
- sudo service mysql restart
16-
- .travis/wait_mysql.sh
17-
- mysql -e 'create database gotest;'
8+
env:
9+
global:
10+
# See https://github.com/go-sql-driver/mysql/wiki/Testing
11+
- MYSQL_TEST_USER=gotest
12+
- MYSQL_TEST_PASS=secret
13+
- MYSQL_TEST_PROT=tcp
14+
- MYSQL_TEST_ADDR=127.0.0.1:3307
15+
- MYSQL_TEST_DBNAME=gotest
16+
- MYSQL_TEST_CONCURRENT=1
1817

1918
matrix:
2019
include:
21-
- env: DB=MYSQL57
22-
sudo: required
23-
dist: trusty
24-
go: 1.9.x
25-
services:
26-
- docker
27-
before_install:
28-
- go get golang.org/x/tools/cmd/cover
29-
- go get github.com/mattn/goveralls
30-
- docker pull mysql:5.7
31-
- docker run -d -p 127.0.0.1:3307:3306 --name mysqld -e MYSQL_DATABASE=gotest -e MYSQL_USER=gotest -e MYSQL_PASSWORD=secret -e MYSQL_ROOT_PASSWORD=verysecret
32-
mysql:5.7 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB
33-
- sleep 30
34-
- cp .travis/docker.cnf ~/.my.cnf
35-
- mysql --print-defaults
36-
- .travis/wait_mysql.sh
37-
before_script:
38-
- export MYSQL_TEST_USER=gotest
39-
- export MYSQL_TEST_PASS=secret
40-
- export MYSQL_TEST_ADDR=127.0.0.1:3307
41-
- export MYSQL_TEST_CONCURRENT=1
20+
# test latest stable MySQL (currently 5.7) with 3 latest Go releases + master
21+
- go: 1.7.x
22+
env: MYSQL_IMAGE=mysql:5.7
23+
- go: 1.8.x
24+
env: MYSQL_IMAGE=mysql:5.7
25+
- go: 1.9.x
26+
env: MYSQL_IMAGE=mysql:5.7
27+
- go: master
28+
env: MYSQL_IMAGE=mysql:5.7
29+
30+
# test latest stable Go (currently 1.9.x) with all other supported MySQL versions + not yet supported 8.0
31+
# https://www.mysql.com/support/supportedplatforms/database.html
32+
- go: 1.9.x
33+
env: MYSQL_IMAGE=mysql:5.5
34+
- go: 1.9.x
35+
env: MYSQL_IMAGE=mysql:5.6
36+
- go: 1.9.x
37+
env: MYSQL_IMAGE=mysql:8.0
38+
39+
# test latest stable Go (currently 1.9.x) with all supported MariaDB versions + not yet supported 10.3
40+
# https://mariadb.org/about/maintenance-policy/
41+
- go: 1.9.x
42+
env: MYSQL_IMAGE=mariadb:5.5
43+
- go: 1.9.x
44+
env: MYSQL_IMAGE=mariadb:10.0
45+
- go: 1.9.x
46+
env: MYSQL_IMAGE=mariadb:10.1
47+
- go: 1.9.x
48+
env: MYSQL_IMAGE=mariadb:10.2
49+
- go: 1.9.x
50+
env: MYSQL_IMAGE=mariadb:10.3
4251

43-
- env: DB=MARIA55
44-
sudo: required
45-
dist: trusty
46-
go: 1.9.x
47-
services:
48-
- docker
49-
before_install:
50-
- go get golang.org/x/tools/cmd/cover
51-
- go get github.com/mattn/goveralls
52-
- docker pull mariadb:5.5
53-
- docker run -d -p 127.0.0.1:3307:3306 --name mysqld -e MYSQL_DATABASE=gotest -e MYSQL_USER=gotest -e MYSQL_PASSWORD=secret -e MYSQL_ROOT_PASSWORD=verysecret
54-
mariadb:5.5 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB
55-
- sleep 30
56-
- cp .travis/docker.cnf ~/.my.cnf
57-
- mysql --print-defaults
58-
- .travis/wait_mysql.sh
59-
before_script:
60-
- export MYSQL_TEST_USER=gotest
61-
- export MYSQL_TEST_PASS=secret
62-
- export MYSQL_TEST_ADDR=127.0.0.1:3307
63-
- export MYSQL_TEST_CONCURRENT=1
52+
go_import_path: github.com/go-sql-driver/mysql
6453

65-
- env: DB=MARIA10_1
66-
sudo: required
67-
dist: trusty
68-
go: 1.9.x
69-
services:
70-
- docker
71-
before_install:
72-
- go get golang.org/x/tools/cmd/cover
73-
- go get github.com/mattn/goveralls
74-
- docker pull mariadb:10.1
75-
- docker run -d -p 127.0.0.1:3307:3306 --name mysqld -e MYSQL_DATABASE=gotest -e MYSQL_USER=gotest -e MYSQL_PASSWORD=secret -e MYSQL_ROOT_PASSWORD=verysecret
76-
mariadb:10.1 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB
77-
- sleep 30
78-
- cp .travis/docker.cnf ~/.my.cnf
79-
- mysql --print-defaults
80-
- .travis/wait_mysql.sh
81-
before_script:
82-
- export MYSQL_TEST_USER=gotest
83-
- export MYSQL_TEST_PASS=secret
84-
- export MYSQL_TEST_ADDR=127.0.0.1:3307
85-
- export MYSQL_TEST_CONCURRENT=1
54+
before_install:
55+
- go get -u github.com/mattn/goveralls
56+
57+
before_script:
58+
- sudo service mysql stop
59+
- docker --version
60+
- docker-compose --version
61+
- docker-compose up -d
62+
- .testing/wait_mysql.sh
8663

8764
script:
8865
- go test -v -covermode=count -coverprofile=coverage.out
8966
- go vet ./...
9067
- test -z "$(gofmt -d -s . | tee /dev/stderr)"
68+
9169
after_script:
92-
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci
70+
- goveralls -coverprofile=coverage.out -service=travis-ci

.travis/docker.cnf

Lines changed: 0 additions & 5 deletions
This file was deleted.

.travis/wait_mysql.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

AUTHORS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
Aaron Hopkins <go-sql-driver at die.net>
1515
Achille Roussel <achille.roussel at gmail.com>
16+
Alexey Palazhchenko <alexey.palazhchenko at gmail.com>
1617
Arne Hormann <arnehormann at gmail.com>
1718
Asta Xie <xiemengjun at gmail.com>
1819
Bulat Gaifullin <gaifullinbf at gmail.com>
@@ -61,8 +62,8 @@ Paul Bonser <misterpib at gmail.com>
6162
Peter Schultz <peter.schultz at classmarkets.com>
6263
Rebecca Chin <rchin at pivotal.io>
6364
Reed Allman <rdallman10 at gmail.com>
64-
Runrioter Wung <runrioter at gmail.com>
6565
Robert Russell <robert at rrbrussell.com>
66+
Runrioter Wung <runrioter at gmail.com>
6667
Shuode Li <elemount at qq.com>
6768
Soroush Pour <me at soroushjp.com>
6869
Stan Putrya <root.vagner at gmail.com>
@@ -79,5 +80,6 @@ Counting Ltd.
7980
Google Inc.
8081
InfoSum Ltd.
8182
Keybase Inc.
83+
Percona LLC
8284
Pivotal Inc.
8385
Stripe Inc.

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# see CONTRIBUTING.md
2+
---
3+
version: '3'
4+
services:
5+
mysql:
6+
image: ${MYSQL_IMAGE:-mysql:5.7}
7+
environment:
8+
- MYSQL_ROOT_PASSWORD=verysecret
9+
- MYSQL_USER=gotest
10+
- MYSQL_PASSWORD=secret
11+
- MYSQL_DATABASE=gotest
12+
ports:
13+
- 127.0.0.1:3307:3306
14+
volumes:
15+
- .testing/testing-server.cnf:/etc/mysql/conf.d/testing-server.cnf

driver_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ func init() {
6363
}
6464
return defaultValue
6565
}
66-
user = env("MYSQL_TEST_USER", "root")
67-
pass = env("MYSQL_TEST_PASS", "")
66+
user = env("MYSQL_TEST_USER", "gotest")
67+
pass = env("MYSQL_TEST_PASS", "secret")
6868
prot = env("MYSQL_TEST_PROT", "tcp")
69-
addr = env("MYSQL_TEST_ADDR", "localhost:3306")
69+
addr = env("MYSQL_TEST_ADDR", "127.0.0.1:3307")
7070
dbname = env("MYSQL_TEST_DBNAME", "gotest")
7171
netAddr = fmt.Sprintf("%s(%s)", prot, addr)
7272
dsn = fmt.Sprintf("%s:%s@%s/%s?timeout=30s", user, pass, netAddr, dbname)

0 commit comments

Comments
 (0)