diff options
author | Kevin Lyda <kevin@ie.suberic.net> | 2017-01-13 20:12:53 +0000 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2017-01-13 20:12:53 +0000 |
commit | adca4cec3bf97d73e082d4c986443ffc8fee6fe1 (patch) | |
tree | 2ff48ee7f89faf514f101688bde9b5211afdd023 | |
parent | 94ae8fd80298f207830d29dc015b503f4f1e3e90 (diff) |
Db test config (#43)
* Allow tests to specify mysql connection info.
User can set MYSQL_TEST_USER, MYSQL_TEST_PASS and MYSQL_TEST_HOST
environment variables for test environments that need that.
* Changes from testing.
Need to set both time fields as '0000-00-00' depends on a feature
deprecated in MySQL 5.7.4.
Go lint wanted snake case for my sql_config var. sqlConfig it is.
* Go go idioms.
Based on feedback from Niall, a cleaner way to do this in Go.
-rw-r--r-- | server/store/store_test.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/server/store/store_test.go b/server/store/store_test.go index 281a614..afe6c03 100644 --- a/server/store/store_test.go +++ b/server/store/store_test.go @@ -44,8 +44,9 @@ func testStore(t *testing.T, db CertStorer) { defer db.Close() r := &CertRecord{ - KeyID: "a", - Expires: time.Now().UTC().Add(1 * time.Minute), + KeyID: "a", + CreatedAt: time.Now().UTC(), + Expires: time.Now().UTC().Add(1 * time.Minute), } if err := db.SetRecord(r); err != nil { t.Error(err) @@ -92,7 +93,17 @@ func TestMySQLStore(t *testing.T) { t.Skip("No MYSQL_TEST environment variable") } u, _ := user.Current() - db, err := NewSQLStore(map[string]string{"type": "mysql", "username": u.Username}) + sqlConfig := map[string]string{ + "type": "mysql", + "password": os.Getenv("MYSQL_TEST_PASS"), + "address": os.Getenv("MYSQL_TEST_HOST"), + } + if testUser, ok := os.LookupEnv("MYSQL_TEST_USER"); ok { + sqlConfig["username"] = testUser + } else { + sqlConfig["username"] = u.Username + } + db, err := NewSQLStore(sqlConfig) if err != nil { t.Error(err) } |