diff --git a/.travis.yml b/.travis.yml index 39468c2..3f02141 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: go os: - linux + - osx go: - 1.9.x @@ -13,20 +14,44 @@ 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 +# 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 + - 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: - - 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?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 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 diff --git a/internal/db/db.go b/internal/db/db.go index 8622af0..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.v1" "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 b330ed6..e42419d 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -1,7 +1,7 @@ package handlers import ( - "gopkg.in/gorp.v1" + "github.com/aclindsa/gorp" "log" "net/http" "path" 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 } diff --git a/internal/handlers/tx.go b/internal/handlers/tx.go index ae19a4b..c0db452 100644 --- a/internal/handlers/tx.go +++ b/internal/handlers/tx.go @@ -2,7 +2,7 @@ package handlers import ( "database/sql" - "gopkg.in/gorp.v1" + "github.com/aclindsa/gorp" "strings" )