From 28c5c3f0facd13177095fde3c15b54dd1e8b527c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Moal Date: Mon, 21 Jun 2021 13:09:21 +0200 Subject: [PATCH] Add CI tests using Github actions --- .github/workflows/test.yml | 36 ++++++++++++++++++++++++++++++++++++ Makefile | 9 +++++++++ sqalx_test.go | 2 ++ 3 files changed, 47 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 Makefile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a92b23f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +on: [push, pull_request] +name: Test +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [1.15.x, 1.16.x] + + services: + postgres: + image: postgres:13-alpine + ports: + - 5432:5432 + env: + POSTGRES_USER: sqalx + POSTGRES_PASSWORD: sqalx + mysql: + image: mysql:8.0 + ports: + - 3306:3306 + env: + MYSQL_ROOT_PASSWORD: sqalx + MYSQL_USER: sqalx + MYSQL_PASSWORD: sqalx + MYSQL_DATABASE: sqalx + + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Test + run: make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..76bd8ed --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +POSTGRESQL_DATASOURCE ?= postgresql://sqalx:sqalx@localhost:5432/sqalx?sslmode=disable +MYSQL_DATASOURCE ?= sqalx:sqalx@tcp(localhost:3306)/sqalx + +.PHONY: test + +test: + POSTGRESQL_DATASOURCE="$(POSTGRESQL_DATASOURCE)" \ + MYSQL_DATASOURCE="$(MYSQL_DATASOURCE)" \ + go test -v -cover -race -timeout=1m ./... && echo OK || (echo FAIL && exit 1) diff --git a/sqalx_test.go b/sqalx_test.go index 89a3963..6874b9d 100644 --- a/sqalx_test.go +++ b/sqalx_test.go @@ -24,6 +24,7 @@ func prepareDB(t *testing.T, driverName string) (*sqlx.DB, sqlmock.Sqlmock, func func TestSqalxConnectPostgreSQL(t *testing.T) { dataSource := os.Getenv("POSTGRESQL_DATASOURCE") if dataSource == "" { + t.Log("skipping due to blank POSTGRESQL_DATASOURCE") t.Skip() return } @@ -35,6 +36,7 @@ func TestSqalxConnectPostgreSQL(t *testing.T) { func TestSqalxConnectMySQL(t *testing.T) { dataSource := os.Getenv("MYSQL_DATASOURCE") if dataSource == "" { + t.Log("skipping due to blank MYSQL_DATASOURCE") t.Skip() return }