From 408b59d522ec39561b9b3563d905e31cd7503fe3 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 17 Nov 2017 09:18:01 -0500 Subject: [PATCH 1/7] .travis.yml: Comment, reorganize --- .travis.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39468c2..b3f6580 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,20 +13,28 @@ services: env: - MONEYGO_TEST_DB=sqlite - - MONEYGO_TEST_DB=mysql MONEYGO_TEST_DSN="root@tcp(127.0.0.1)/moneygo_test?parseTime=true" - - MONEYGO_TEST_DB=postgres MONEYGO_TEST_DSN="postgres://postgres@localhost/moneygo_test" + - MONEYGO_TEST_DB=mysql + - MONEYGO_TEST_DB=postgres +# Initialize databases, if necessary before_script: - - sh -c "if [ $MONEYGO_TEST_DB = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS moneygo_test;' -U postgres; fi" - - sh -c "if [ $MONEYGO_TEST_DB = 'postgres' ]; then psql -c 'CREATE DATABASE moneygo_test;' -U postgres; fi" - - sh -c "if [ $MONEYGO_TEST_DB = 'mysql' ]; then mysql -e 'CREATE DATABASE IF NOT EXISTS moneygo_test;'; fi" + - if [ $MONEYGO_TEST_DB = 'mysql' ]; then export MONEYGO_TEST_DSN="root@tcp(127.0.0.1)/moneygo_test?parseTime=true"; fi + - if [ $MONEYGO_TEST_DB = 'postgres' ]; then export MONEYGO_TEST_DSN="postgres://postgres@localhost/moneygo_test"; fi + - if [ $MONEYGO_TEST_DB = 'mysql' ]; then mysql -u root -e 'CREATE DATABASE IF NOT EXISTS moneygo_test;'; fi + - if [ $MONEYGO_TEST_DB = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS moneygo_test;' -U postgres; fi + - if [ $MONEYGO_TEST_DB = 'postgres' ]; then psql -c 'CREATE DATABASE moneygo_test;' -U postgres; fi script: +# Fetch/build coverage reporting tools - go get golang.org/x/tools/cmd/cover - go get github.com/mattn/goveralls - go install github.com/mattn/goveralls +# Fetch MoneyGo itself - go get -d github.com/aclindsa/moneygo +# Don't allow the test to query for a full list of all CUSIPs - touch $GOPATH/src/github.com/aclindsa/moneygo/internal/handlers/cusip_list.csv +# Build and test MoneyGo - go generate -v github.com/aclindsa/moneygo/internal/handlers - go test -v -covermode=count -coverprofile=coverage.out github.com/aclindsa/moneygo/internal/handlers +# Finally, report the test coverage - $GOPATH/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN From 955bb214b822c26f0d7eb17faf488cd56daeba18 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 17 Nov 2017 09:18:20 -0500 Subject: [PATCH 2/7] .travis.yml: Add OSX --- .travis.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b3f6580..a082dba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: go os: - linux + - osx go: - 1.9.x @@ -16,7 +17,16 @@ env: - MONEYGO_TEST_DB=mysql - MONEYGO_TEST_DB=postgres -# Initialize databases, if necessary +# Install MySQL or Postgres if on OSX +before_install: + - if [ $TRAVIS_OS_NAME = 'osx' ] && [ $MONEYGO_TEST_DB = 'mysql' ]; then brew update > /dev/null && brew install mariadb && mysql.server start; fi + - if [ $TRAVIS_OS_NAME = 'osx' ] && [ $MONEYGO_TEST_DB = 'postgres' ]; then brew update > /dev/null; fi + - if [ $TRAVIS_OS_NAME = 'osx' ] && [ $MONEYGO_TEST_DB = 'postgres' ]; then rm -rf /usr/local/var/postgres; fi + - if [ $TRAVIS_OS_NAME = 'osx' ] && [ $MONEYGO_TEST_DB = 'postgres' ]; then initdb /usr/local/var/postgres; fi + - if [ $TRAVIS_OS_NAME = 'osx' ] && [ $MONEYGO_TEST_DB = 'postgres' ]; then pg_ctl -D /usr/local/var/postgres start; fi + - if [ $TRAVIS_OS_NAME = 'osx' ] && [ $MONEYGO_TEST_DB = 'postgres' ]; then createuser -s postgres; fi + +# Initialize databases, if testing MySQL or Postgres before_script: - if [ $MONEYGO_TEST_DB = 'mysql' ]; then export MONEYGO_TEST_DSN="root@tcp(127.0.0.1)/moneygo_test?parseTime=true"; fi - if [ $MONEYGO_TEST_DB = 'postgres' ]; then export MONEYGO_TEST_DSN="postgres://postgres@localhost/moneygo_test"; fi From 8ac573796b64028479e1e9761ee8849dd4f9cdc5 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 17 Nov 2017 11:45:01 -0500 Subject: [PATCH 3/7] .travis.yml: Allow OSX tests on 'master' to finish early (and fail) --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index a082dba..ac6d07d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,13 @@ env: - MONEYGO_TEST_DB=mysql - MONEYGO_TEST_DB=postgres +# OSX builds take too long, so don't wait for all of them +matrix: + fast_finish: true + allow_failures: + - os: osx + go: master + # Install MySQL or Postgres if on OSX before_install: - if [ $TRAVIS_OS_NAME = 'osx' ] && [ $MONEYGO_TEST_DB = 'mysql' ]; then brew update > /dev/null && brew install mariadb && mysql.server start; fi From d5ca4395ac8b20d6d63d10456e87e9607c1be221 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 17 Nov 2017 19:53:56 -0500 Subject: [PATCH 4/7] Move to gorp v2 This removes the following error, caused by the MySQL Dialect using a 'varchar' for all columns over 256 characters in length, instead of 'text' for the largest: 2017/11/17 22:41:33 common_test.go:208: Error 1074: Column length too big for column 'Lua' (max = 21844); use BLOB or TEXT instead --- internal/db/db.go | 2 +- internal/handlers/handlers.go | 2 +- internal/handlers/tx.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/db/db.go b/internal/db/db.go index 8622af0..ad3ea78 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -8,7 +8,7 @@ import ( _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" - "gopkg.in/gorp.v1" + "gopkg.in/gorp.v2" "log" "strings" ) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index b330ed6..67f5672 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -1,7 +1,7 @@ package handlers import ( - "gopkg.in/gorp.v1" + "gopkg.in/gorp.v2" "log" "net/http" "path" diff --git a/internal/handlers/tx.go b/internal/handlers/tx.go index ae19a4b..716abf0 100644 --- a/internal/handlers/tx.go +++ b/internal/handlers/tx.go @@ -2,7 +2,7 @@ package handlers import ( "database/sql" - "gopkg.in/gorp.v1" + "gopkg.in/gorp.v2" "strings" ) From 04d85cd6819f144655268780a0c72b49254117e4 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 17 Nov 2017 21:01:06 -0500 Subject: [PATCH 5/7] Fix gorp to internally lowercase fields for Postgres Postgres folds all unquoted column names to lowercase, and doing this allows that to work nicely without screwing up the queries for the other database engines. --- internal/db/db.go | 6 ++++-- internal/handlers/handlers.go | 2 +- internal/handlers/tx.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/db/db.go b/internal/db/db.go index ad3ea78..68cfd6d 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -3,12 +3,12 @@ package db import ( "database/sql" "fmt" + "github.com/aclindsa/gorp" "github.com/aclindsa/moneygo/internal/config" "github.com/aclindsa/moneygo/internal/handlers" _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" - "gopkg.in/gorp.v2" "log" "strings" ) @@ -25,7 +25,9 @@ func GetDbMap(db *sql.DB, dbtype config.DbType) (*gorp.DbMap, error) { Encoding: "UTF8", } } else if dbtype == config.Postgres { - dialect = gorp.PostgresDialect{} + dialect = gorp.PostgresDialect{ + LowercaseFields: true, + } } else { return nil, fmt.Errorf("Don't know gorp dialect to go with '%s' DB type", dbtype.String()) } diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 67f5672..e42419d 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -1,7 +1,7 @@ package handlers import ( - "gopkg.in/gorp.v2" + "github.com/aclindsa/gorp" "log" "net/http" "path" diff --git a/internal/handlers/tx.go b/internal/handlers/tx.go index 716abf0..c0db452 100644 --- a/internal/handlers/tx.go +++ b/internal/handlers/tx.go @@ -2,7 +2,7 @@ package handlers import ( "database/sql" - "gopkg.in/gorp.v2" + "github.com/aclindsa/gorp" "strings" ) From e4e474caf25b642ab1a98ecbf5d9e4c59b809bcd Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 17 Nov 2017 21:02:25 -0500 Subject: [PATCH 6/7] Remove outdated comment --- internal/handlers/testdata_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/handlers/testdata_test.go b/internal/handlers/testdata_test.go index 143229e..2b3a558 100644 --- a/internal/handlers/testdata_test.go +++ b/internal/handlers/testdata_test.go @@ -65,8 +65,6 @@ func (t *TestData) initUser(user *User, userid int) error { t.clients = append(t.clients, client) - // TODO initialize everything else owned by this user in the TestData struct - return nil } From 05aea959611662cf466beb14c427d153e7b5841f Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 17 Nov 2017 21:18:10 -0500 Subject: [PATCH 7/7] .travis.yml: Disable SSL mode for Postgres This isn't enabled on OSX by default --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ac6d07d..3f02141 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ before_install: # Initialize databases, if testing MySQL or Postgres before_script: - if [ $MONEYGO_TEST_DB = 'mysql' ]; then export MONEYGO_TEST_DSN="root@tcp(127.0.0.1)/moneygo_test?parseTime=true"; fi - - if [ $MONEYGO_TEST_DB = 'postgres' ]; then export MONEYGO_TEST_DSN="postgres://postgres@localhost/moneygo_test"; fi + - if [ $MONEYGO_TEST_DB = 'postgres' ]; then export MONEYGO_TEST_DSN="postgres://postgres@localhost/moneygo_test?sslmode=disable"; fi - if [ $MONEYGO_TEST_DB = 'mysql' ]; then mysql -u root -e 'CREATE DATABASE IF NOT EXISTS moneygo_test;'; fi - if [ $MONEYGO_TEST_DB = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS moneygo_test;' -U postgres; fi - if [ $MONEYGO_TEST_DB = 'postgres' ]; then psql -c 'CREATE DATABASE moneygo_test;' -U postgres; fi