mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-10-30 07:40:05 -04:00
Merge pull request #25 from aclindsa/add_mysql_postgres
Testing: Add MySQL and Postgres
This commit is contained in:
commit
f9c234c2f3
14
.travis.yml
14
.travis.yml
@ -7,6 +7,20 @@ go:
|
||||
- 1.9.x
|
||||
- master
|
||||
|
||||
services:
|
||||
- mysql
|
||||
- postgresql
|
||||
|
||||
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"
|
||||
|
||||
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"
|
||||
|
||||
script:
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
- go get github.com/mattn/goveralls
|
||||
|
@ -19,7 +19,7 @@ db-type = sqlite3
|
||||
#
|
||||
# Sqlite example DSN: "file:moneygo.sqlite?cache=shared&mode=rwc"
|
||||
# MySQL documentation: https://github.com/go-sql-driver/mysql/#dsn-data-source-name
|
||||
# example DSN: "user:password@localhost/dbname&parseTime=true"
|
||||
# example DSN: "user:password@tcp(localhost)/dbname&parseTime=true"
|
||||
# (Note: MySQL DSN's *must* include the
|
||||
# "parseTime=true" parameter)
|
||||
# Postgres documentation: https://godoc.org/github.com/lib/pq
|
||||
|
@ -174,14 +174,41 @@ func RunWith(t *testing.T, d *TestData, fn TestDataFunc) {
|
||||
}
|
||||
|
||||
func RunTests(m *testing.M) int {
|
||||
dsn := db.GetDSN(config.SQLite, ":memory:")
|
||||
database, err := sql.Open("sqlite3", dsn)
|
||||
envDbType := os.Getenv("MONEYGO_TEST_DB")
|
||||
var dbType config.DbType
|
||||
var dsn string
|
||||
|
||||
switch envDbType {
|
||||
case "", "sqlite", "sqlite3":
|
||||
dbType = config.SQLite
|
||||
dsn = ":memory:"
|
||||
case "mariadb", "mysql":
|
||||
dbType = config.MySQL
|
||||
dsn = "root@127.0.0.1/moneygo_test&parseTime=true"
|
||||
case "postgres", "postgresql":
|
||||
dbType = config.Postgres
|
||||
dsn = "postgres://postgres@localhost/moneygo_test"
|
||||
default:
|
||||
log.Fatalf("Invalid value for $MONEYGO_TEST_DB: %s\n", envDbType)
|
||||
}
|
||||
|
||||
if envDSN := os.Getenv("MONEYGO_TEST_DSN"); len(envDSN) > 0 {
|
||||
dsn = envDSN
|
||||
}
|
||||
|
||||
dsn = db.GetDSN(dbType, dsn)
|
||||
database, err := sql.Open(dbType.String(), dsn)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer database.Close()
|
||||
|
||||
dbmap, err := db.GetDbMap(database, config.SQLite)
|
||||
dbmap, err := db.GetDbMap(database, dbType)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = dbmap.TruncateTables()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user