Skip to content

Commit

Permalink
Uses Dockerfile instead of init to leverage caching. #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Gappa committed Sep 23, 2018
1 parent dfc94f9 commit 2fa4a74
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM golang:1.11

RUN apt-get update && apt-get install -y --no-install-recommends mysql-client && rm -rf /var/lib/apt/lists/*

ENTRYPOINT [ "go", "test", "-v", "." ]
8 changes: 4 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import (

func TestSQL(t *testing.T) {
var err error
for i := 1; i <= 5; i++ { // Try up to 10 times, because MySQL takes a while to become online
for i := 1; i <= 30; i++ { // Try up to 30 times, because MySQL takes a while to become online
var c = exec.Command("mysql", "-h", "test-mysql", "-u", "root", "-e", "SELECT * FROM db1.table1")
if err = c.Run(); err == nil {
break
}
log.Printf("Retrying (%v/10) in 1 sec because MySQL is not yet ready", i)
log.Printf("Retrying (%v/30) in 1 sec because MySQL is not yet ready", i)
time.Sleep(1 * time.Second)
}
for err != nil {
t.Errorf("bailing because couldn't connect to MySQL after 10 tries: %v", err)
t.Errorf("bailing because couldn't connect to MySQL after 30 tries: %v", err)
t.FailNow()
}

Expand All @@ -39,7 +39,7 @@ func TestSQL(t *testing.T) {
expected []string
}{
{
name: "happy case",
name: "reads ",
targetDBs: []string{"db1", "db2", "db3"},
query: "SELECT id FROM table1",
expected: []string{
Expand Down
3 changes: 1 addition & 2 deletions test-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
version: '3'
services:
test:
image: golang:1.11
build: .
volumes:
- "$PWD:/go/src/sql"
working_dir: /go/src/sql
depends_on:
- test-mysql
entrypoint: ./test.sh
test-mysql:
image: mysql:5
volumes:
Expand Down
3 changes: 0 additions & 3 deletions test.sh

This file was deleted.

0 comments on commit 2fa4a74

Please sign in to comment.