From 2fa4a74daab083ff352e761519e6ab9bc7136e3d Mon Sep 17 00:00:00 2001 From: Mariano Gappa Date: Sun, 23 Sep 2018 16:56:09 +1200 Subject: [PATCH] Uses Dockerfile instead of init to leverage caching. #16 --- Dockerfile | 5 +++++ main_test.go | 8 ++++---- test-docker-compose.yml | 3 +-- test.sh | 3 --- 4 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 Dockerfile delete mode 100755 test.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e3e33d1 --- /dev/null +++ b/Dockerfile @@ -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", "." ] diff --git a/main_test.go b/main_test.go index a705d73..afd27fb 100644 --- a/main_test.go +++ b/main_test.go @@ -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() } @@ -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{ diff --git a/test-docker-compose.yml b/test-docker-compose.yml index 5e28466..1677829 100644 --- a/test-docker-compose.yml +++ b/test-docker-compose.yml @@ -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: diff --git a/test.sh b/test.sh deleted file mode 100755 index fbd4469..0000000 --- a/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -# Intended to be run by docker-compose -apt-get update && apt-get install -y --no-install-recommends mysql-client && rm -rf /var/lib/apt/lists/* && go test -v .