Skip to content

Commit

Permalink
Add CI tests using Github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
skateinmars committed Jun 21, 2021
1 parent f8ebb8d commit 28c5c3f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions sqalx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 28c5c3f

Please sign in to comment.