image: lyda/golang:1.7

variables:
  MYSQL_ROOT_PASSWORD: "password"
  MYSQL_ALLOW_EMPTY_PASSWORD: "1"
  MYSQL_TEST: "true"
  MYSQL_TEST_USER: "root"
  MYSQL_TEST_PASS: "password"
  MYSQL_TEST_HOST: "mysql"

services:
  - mysql

test:
  type: test
  script:
    - id
    - mkdir -p /go/src/github.com/nsheridan
    - ln -s $PWD /go/src/github.com/nsheridan/cashier
    - cd /go/src/github.com/nsheridan/cashier
    - go get ./cmd/cashier ./cmd/cashierd
    - for i in 1 2 3; do mysql -u$MYSQL_TEST_USER -p$MYSQL_ROOT_PASSWORD -h$MYSQL_TEST_HOST < db/seed.sql && break || true; sleep 3; done
    - go list ./... |grep -v vendor/ |xargs go test
    - gofmt -d $(find -type f -name '*.go' -not -path './vendor/*')
    - go list ./... |grep -v vendor/ |xargs go vet
    - go list ./... |grep -v vendor/ |xargs -L1 golint -set_exit_status
  after_script:
    - mysqldump -u$MYSQL_TEST_USER -p$MYSQL_ROOT_PASSWORD -h$MYSQL_TEST_HOST certs
