Skip to content

Use Docker Compose for testing #697

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

Closed
wants to merge 1 commit into from
Closed
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
File renamed without changes.
5 changes: 5 additions & 0 deletions .testing/testing-server.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[mysqld]
innodb_log_file_size=256MB
innodb_buffer_pool_size=512MB
max_allowed_packet=16MB
local-infile=1
8 changes: 8 additions & 0 deletions .testing/wait_mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
while :
do
if mysql --user=gotest --password=secret --host=127.0.0.1 --port=3307 -e 'select version()' 2>&1 | grep 'version()\|ERROR 2059 (HY000):'; then
break
fi
sleep 3
done
149 changes: 57 additions & 92 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,107 +1,72 @@
sudo: false
dist: trusty
sudo: required
language: go
go:
- 1.7.x
- 1.8.x
- 1.9.x
- 1.10.x
- master

before_install:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
services:
- docker

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

matrix:
include:
- env: DB=MYSQL8
sudo: required
dist: trusty
go: 1.10.x
services:
- docker
before_install:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- docker pull mysql:8.0
- 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
mysql:8.0 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
- cp .travis/docker.cnf ~/.my.cnf
- .travis/wait_mysql.sh
before_script:
- export MYSQL_TEST_USER=gotest
- export MYSQL_TEST_PASS=secret
- export MYSQL_TEST_ADDR=127.0.0.1:3307
- export MYSQL_TEST_CONCURRENT=1
# test latest stable MySQL (currently 5.7) with 4 latest Go releases + master
- go: 1.7.x
env: MYSQL_IMAGE=mysql:5.7
- go: 1.8.x
env: MYSQL_IMAGE=mysql:5.7
- go: 1.9.x
env: MYSQL_IMAGE=mysql:5.7
- go: 1.10.x
env: MYSQL_IMAGE=mysql:5.7
- go: master
env: MYSQL_IMAGE=mysql:5.7

- env: DB=MYSQL57
sudo: required
dist: trusty
go: 1.10.x
services:
- docker
before_install:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- docker pull mysql:5.7
- 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
mysql:5.7 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
- cp .travis/docker.cnf ~/.my.cnf
- .travis/wait_mysql.sh
before_script:
- export MYSQL_TEST_USER=gotest
- export MYSQL_TEST_PASS=secret
- export MYSQL_TEST_ADDR=127.0.0.1:3307
- export MYSQL_TEST_CONCURRENT=1
# test latest stable Go (currently 1.10.x) with all other supported MySQL versions + not yet supported 8.0
# https://www.mysql.com/support/supportedplatforms/database.html
- go: 1.10.x
env: MYSQL_IMAGE=mysql:5.5
- go: 1.10.x
env: MYSQL_IMAGE=mysql:5.6
- go: 1.10.x
env: MYSQL_IMAGE=mysql:8.0

- env: DB=MARIA55
sudo: required
dist: trusty
go: 1.10.x
services:
- docker
before_install:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- docker pull mariadb:5.5
- 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
mariadb:5.5 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
- cp .travis/docker.cnf ~/.my.cnf
- .travis/wait_mysql.sh
before_script:
- export MYSQL_TEST_USER=gotest
- export MYSQL_TEST_PASS=secret
- export MYSQL_TEST_ADDR=127.0.0.1:3307
- export MYSQL_TEST_CONCURRENT=1
# test latest stable Go (currently 1.10.x) with all supported MariaDB versions + not yet supported 10.3
# https://mariadb.org/about/maintenance-policy/
- go: 1.10.x
env: MYSQL_IMAGE=mariadb:5.5
- go: 1.10.x
env: MYSQL_IMAGE=mariadb:10.0
- go: 1.10.x
env: MYSQL_IMAGE=mariadb:10.1
- go: 1.10.x
env: MYSQL_IMAGE=mariadb:10.2
- go: 1.10.x
env: MYSQL_IMAGE=mariadb:10.3

- env: DB=MARIA10_1
sudo: required
dist: trusty
go: 1.10.x
services:
- docker
before_install:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- docker pull mariadb:10.1
- 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
mariadb:10.1 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
- cp .travis/docker.cnf ~/.my.cnf
- .travis/wait_mysql.sh
before_script:
- export MYSQL_TEST_USER=gotest
- export MYSQL_TEST_PASS=secret
- export MYSQL_TEST_ADDR=127.0.0.1:3307
- export MYSQL_TEST_CONCURRENT=1
go_import_path: github.com/go-sql-driver/mysql

before_install:
- go get -u github.com/mattn/goveralls

before_script:
- sudo service mysql stop
- docker --version
- docker-compose --version
- docker-compose up -d
- .testing/wait_mysql.sh

script:
- go test -v -covermode=count -coverprofile=coverage.out
- go vet ./...
- .travis/gofmt.sh
- .testing/gofmt.sh

after_script:
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci
5 changes: 0 additions & 5 deletions .travis/docker.cnf

This file was deleted.

8 changes: 0 additions & 8 deletions .travis/wait_mysql.sh

This file was deleted.

15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# see CONTRIBUTING.md
---
version: '3'
services:
mysql:
image: ${MYSQL_IMAGE:-mysql:5.7}
environment:
- MYSQL_ROOT_PASSWORD=verysecret
- MYSQL_USER=gotest
- MYSQL_PASSWORD=secret
- MYSQL_DATABASE=gotest
ports:
- 127.0.0.1:3307:3306
volumes:
- .testing/testing-server.cnf:/etc/mysql/conf.d/testing-server.cnf
6 changes: 3 additions & 3 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func init() {
}
return defaultValue
}
user = env("MYSQL_TEST_USER", "root")
pass = env("MYSQL_TEST_PASS", "")
user = env("MYSQL_TEST_USER", "gotest")
pass = env("MYSQL_TEST_PASS", "secret")
prot = env("MYSQL_TEST_PROT", "tcp")
addr = env("MYSQL_TEST_ADDR", "localhost:3306")
addr = env("MYSQL_TEST_ADDR", "127.0.0.1:3307")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change default port to 3307

dbname = env("MYSQL_TEST_DBNAME", "gotest")
netAddr = fmt.Sprintf("%s(%s)", prot, addr)
dsn = fmt.Sprintf("%s:%s@%s/%s?timeout=30s", user, pass, netAddr, dbname)
Expand Down