Skip to content

Commit 776cdf0

Browse files
committed
Use Docker Compose for testing.
1 parent d03e4c2 commit 776cdf0

File tree

8 files changed

+88
-108
lines changed

8 files changed

+88
-108
lines changed
File renamed without changes.

.testing/testing-server.cnf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[mysqld]
2+
innodb_log_file_size=256MB
3+
innodb_buffer_pool_size=512MB
4+
max_allowed_packet=16MB
5+
local-infile=1

.testing/wait_mysql.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
while :
3+
do
4+
if mysql --user=gotest --password=secret --host=127.0.0.1 --port=3307 -e 'select version()' 2>&1 | grep 'version()\|ERROR 2059 (HY000):'; then
5+
break
6+
fi
7+
sleep 3
8+
done

.travis.yml

+57-92
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,72 @@
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-
- 1.10.x
8-
- master
94

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

14-
before_script:
15-
- echo -e "[server]\ninnodb_log_file_size=256MB\ninnodb_buffer_pool_size=512MB\nmax_allowed_packet=16MB" | sudo tee -a /etc/mysql/my.cnf
16-
- sudo service mysql restart
17-
- .travis/wait_mysql.sh
18-
- 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
1917

2018
matrix:
2119
include:
22-
- env: DB=MYSQL8
23-
sudo: required
24-
dist: trusty
25-
go: 1.10.x
26-
services:
27-
- docker
28-
before_install:
29-
- go get golang.org/x/tools/cmd/cover
30-
- go get github.com/mattn/goveralls
31-
- docker pull mysql:8.0
32-
- 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
33-
mysql:8.0 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
34-
- cp .travis/docker.cnf ~/.my.cnf
35-
- .travis/wait_mysql.sh
36-
before_script:
37-
- export MYSQL_TEST_USER=gotest
38-
- export MYSQL_TEST_PASS=secret
39-
- export MYSQL_TEST_ADDR=127.0.0.1:3307
40-
- export MYSQL_TEST_CONCURRENT=1
20+
# test latest stable MySQL (currently 5.7) with 4 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: 1.10.x
28+
env: MYSQL_IMAGE=mysql:5.7
29+
- go: master
30+
env: MYSQL_IMAGE=mysql:5.7
4131

42-
- env: DB=MYSQL57
43-
sudo: required
44-
dist: trusty
45-
go: 1.10.x
46-
services:
47-
- docker
48-
before_install:
49-
- go get golang.org/x/tools/cmd/cover
50-
- go get github.com/mattn/goveralls
51-
- docker pull mysql:5.7
52-
- 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
53-
mysql:5.7 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
54-
- cp .travis/docker.cnf ~/.my.cnf
55-
- .travis/wait_mysql.sh
56-
before_script:
57-
- export MYSQL_TEST_USER=gotest
58-
- export MYSQL_TEST_PASS=secret
59-
- export MYSQL_TEST_ADDR=127.0.0.1:3307
60-
- export MYSQL_TEST_CONCURRENT=1
32+
# test latest stable Go (currently 1.10.x) with all other supported MySQL versions + not yet supported 8.0
33+
# https://www.mysql.com/support/supportedplatforms/database.html
34+
- go: 1.10.x
35+
env: MYSQL_IMAGE=mysql:5.5
36+
- go: 1.10.x
37+
env: MYSQL_IMAGE=mysql:5.6
38+
- go: 1.10.x
39+
env: MYSQL_IMAGE=mysql:8.0
6140

62-
- env: DB=MARIA55
63-
sudo: required
64-
dist: trusty
65-
go: 1.10.x
66-
services:
67-
- docker
68-
before_install:
69-
- go get golang.org/x/tools/cmd/cover
70-
- go get github.com/mattn/goveralls
71-
- docker pull mariadb:5.5
72-
- 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
73-
mariadb:5.5 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
74-
- cp .travis/docker.cnf ~/.my.cnf
75-
- .travis/wait_mysql.sh
76-
before_script:
77-
- export MYSQL_TEST_USER=gotest
78-
- export MYSQL_TEST_PASS=secret
79-
- export MYSQL_TEST_ADDR=127.0.0.1:3307
80-
- export MYSQL_TEST_CONCURRENT=1
41+
# test latest stable Go (currently 1.10.x) with all supported MariaDB versions + not yet supported 10.3
42+
# https://mariadb.org/about/maintenance-policy/
43+
- go: 1.10.x
44+
env: MYSQL_IMAGE=mariadb:5.5
45+
- go: 1.10.x
46+
env: MYSQL_IMAGE=mariadb:10.0
47+
- go: 1.10.x
48+
env: MYSQL_IMAGE=mariadb:10.1
49+
- go: 1.10.x
50+
env: MYSQL_IMAGE=mariadb:10.2
51+
- go: 1.10.x
52+
env: MYSQL_IMAGE=mariadb:10.3
8153

82-
- env: DB=MARIA10_1
83-
sudo: required
84-
dist: trusty
85-
go: 1.10.x
86-
services:
87-
- docker
88-
before_install:
89-
- go get golang.org/x/tools/cmd/cover
90-
- go get github.com/mattn/goveralls
91-
- docker pull mariadb:10.1
92-
- 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
93-
mariadb:10.1 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
94-
- cp .travis/docker.cnf ~/.my.cnf
95-
- .travis/wait_mysql.sh
96-
before_script:
97-
- export MYSQL_TEST_USER=gotest
98-
- export MYSQL_TEST_PASS=secret
99-
- export MYSQL_TEST_ADDR=127.0.0.1:3307
100-
- export MYSQL_TEST_CONCURRENT=1
54+
go_import_path: github.com/go-sql-driver/mysql
55+
56+
before_install:
57+
- go get -u github.com/mattn/goveralls
58+
59+
before_script:
60+
- sudo service mysql stop
61+
- docker --version
62+
- docker-compose --version
63+
- docker-compose up -d
64+
- .testing/wait_mysql.sh
10165

10266
script:
10367
- go test -v -covermode=count -coverprofile=coverage.out
10468
- go vet ./...
105-
- .travis/gofmt.sh
69+
- .testing/gofmt.sh
70+
10671
after_script:
10772
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci

.travis/docker.cnf

-5
This file was deleted.

.travis/wait_mysql.sh

-8
This file was deleted.

docker-compose.yml

+15
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

+3-3
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)