From 297a4227efa8f2cdd946cff18853852c6b006f44 Mon Sep 17 00:00:00 2001 From: Matthias Kadenbach Date: Wed, 8 Feb 2017 01:49:57 -0800 Subject: [PATCH] fixing travis --- .travis.yml | 34 ++++++++++++++++++++++++++---- Makefile | 22 +++++++++++-------- database/postgres/postgres_test.go | 12 ++++++----- source/github/github_test.go | 4 ++++ testing/testing.go | 10 ++++++++- 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 22c9463..9b35e10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,38 @@ language: go sudo: required go: - - 1.5 - - 1.6 - 1.7 +env: + - MIGRATE_TEST_CONTAINER_BOOT_DELAY=15 + +# TODO: https://docs.docker.com/engine/installation/linux/ubuntu/ +# pre-provision with travis docker setup and pin down docker version in install step services: - - docker + - docker -script: make test +install: + - make deps + - (cd $GOPATH/src/github.com/docker/docker && git fetch --all --tags --prune && git checkout v1.13.0) + - sudo apt-get update && sudo apt-get install docker-engine=1.13.0* + +script: + - make test + +before_deploy: + - make build-cli + +deploy: + provider: releases + skip_cleanup: true + api_key: + secure: EFow50BI448HVb/uQ1Kk2Kq0xzmwIYq3V67YyymXIuqSCodvXEsMiBPUoLrxEknpPEIc67LEQTNdfHBgvyHk6oRINWAfie+7pr5tKrpOTF9ghyxoN1PlO8WKQCqwCvGMBCnc5ur5rvzp0bqfpV2rs5q9/nngy3kBuEvs12V7iho= + on: + repo: mattes/migrate + tags: true + file: + - cli/build/migrate.linux-amd64.tar.gz + - cli/build/migrate.darwin-amd64.tar.gz + - cli/build/migrate.windows-amd64.exe.tar.gz + - cli/build/sha256sum.txt diff --git a/Makefile b/Makefile index 02eae0e..9ef30dc 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,11 @@ DATABASE?=postgres VERSION?=$(shell git describe --tags 2>/dev/null) TEST_FLAGS?= -# define comma and space -, := , -space := -space += - build-cli: clean -mkdir ./cli/build - cd ./cli && GOOS=linux GOARCH=amd64 go build -a -o build/migrate.$(VERSION).linux-amd64 -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' . - cd ./cli && GOOS=darwin GOARCH=amd64 go build -a -o build/migrate.$(VERSION).darwin-amd64 -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' . - cd ./cli && GOOS=windows GOARCH=amd64 go build -a -o build/migrate.$(VERSION).windows-amd64.exe -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' . + cd ./cli && GOOS=linux GOARCH=amd64 go build -a -o build/migrate.linux-amd64 -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' . + cd ./cli && GOOS=darwin GOARCH=amd64 go build -a -o build/migrate.darwin-amd64 -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' . + cd ./cli && GOOS=windows GOARCH=amd64 go build -a -o build/migrate.windows-amd64.exe -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' . cd ./cli/build && find . -name 'migrate*' | xargs -I{} tar czf {}.tar.gz {} cd ./cli/build && shasum -a 256 * > sha256sum.txt cat ./cli/build/sha256sum.txt @@ -47,6 +42,15 @@ test-with-flags: # deprecated v1compat: @go test $(TEST_FLAGS) ./migrate/... +deps: + -go get -v -u ./... + -go test -v -i ./... -.PHONY: build-cli clean test-short test coverage test-with-flags +.PHONY: build-cli clean test-short test coverage test-with-flags deps +SHELL=/bin/bash + +# define comma and space +, := , +space := +space += diff --git a/database/postgres/postgres_test.go b/database/postgres/postgres_test.go index 0123282..d30fb3f 100644 --- a/database/postgres/postgres_test.go +++ b/database/postgres/postgres_test.go @@ -46,9 +46,10 @@ func Test(t *testing.T) { mt.ParallelTest(t, versions, isReady, func(t *testing.T, i mt.Instance) { p := &Postgres{} - d, err := p.Open(fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable", i.Host(), i.Port())) + addr := fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable", i.Host(), i.Port()) + d, err := p.Open(addr) if err != nil { - t.Fatalf("%#v", err) + t.Fatalf("%v", err) } dt.Test(t, d, []byte("SELECT 1")) }) @@ -58,9 +59,10 @@ func TestWithSchema(t *testing.T) { mt.ParallelTest(t, versions, isReady, func(t *testing.T, i mt.Instance) { p := &Postgres{} - d, err := p.Open(fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable", i.Host(), i.Port())) + addr := fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable", i.Host(), i.Port()) + d, err := p.Open(addr) if err != nil { - t.Fatalf("%#v", err) + t.Fatalf("%v", err) } // create foobar schema @@ -71,7 +73,7 @@ func TestWithSchema(t *testing.T) { // re-connect using that schema d2, err := p.Open(fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable&search_path=foobar", i.Host(), i.Port())) if err != nil { - t.Fatalf("%#v", err) + t.Fatalf("%v", err) } version, err := d2.Version() diff --git a/source/github/github_test.go b/source/github/github_test.go index 00c8969..83e8661 100644 --- a/source/github/github_test.go +++ b/source/github/github_test.go @@ -18,6 +18,10 @@ func init() { } func Test(t *testing.T) { + if len(GithubTestSecret) == 0 { + t.Skip("test requires .github_test_secrets") + } + g := &Github{} d, err := g.Open("github://" + GithubTestSecret + "@mattes/migrate_test_tmp/test") if err != nil { diff --git a/testing/testing.go b/testing/testing.go index cb3e7f0..550b4b0 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -1,6 +1,8 @@ package testing import ( + "os" + "strconv" "testing" "time" ) @@ -46,8 +48,14 @@ func ParallelTest(t *testing.T, versions []string, readyFn IsReadyFunc, testFn T } } + delay, err := strconv.Atoi(os.Getenv("MIGRATE_TEST_CONTAINER_BOOT_DELAY")) + if err == nil { + time.Sleep(time.Duration(int64(delay)) * time.Second) + } else { + time.Sleep(2 * time.Second) + } + // we can now run the tests - time.Sleep(2 * time.Second) // addded grace period testFn(t, container) }) }