fathom/pkg/datastore/sqlstore/config_test.go

55 lines
1.1 KiB
Go
Raw Normal View History

2018-07-30 09:33:49 +02:00
package sqlstore
import (
"fmt"
"testing"
)
func TestConfigDSN(t *testing.T) {
c := Config{
Driver: "postgres",
user: "john",
password: "foo",
2018-07-30 09:33:49 +02:00
}
e := fmt.Sprintf("user=%s password=%s", c.user, c.password)
2018-07-30 09:33:49 +02:00
if v := c.DSN(); v != e {
t.Errorf("Invalid DSN. Expected %s, got %s", e, v)
}
c = Config{
Driver: "postgres",
user: "john",
password: "foo",
sslmode: "disable",
2018-07-30 09:33:49 +02:00
}
e = fmt.Sprintf("user=%s password=%s sslmode=%s", c.user, c.password, c.sslmode)
2018-07-30 09:33:49 +02:00
if v := c.DSN(); v != e {
t.Errorf("Invalid DSN. Expected %s, got %s", e, v)
}
}
func TestConfigDbname(t *testing.T) {
var c Config
c = Config{
url: "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full",
}
if e, v := "pqgotest", c.Dbname(); v != e {
t.Errorf("Expected %q, got %q", e, v)
}
c = Config{
url: "root@tcp(host.myhost)/mysqltest?loc=Local",
}
if e, v := "mysqltest", c.Dbname(); v != e {
t.Errorf("Expected %q, got %q", e, v)
}
c = Config{
url: "/mysqltest?loc=Local&parseTime=true",
}
if e, v := "mysqltest", c.Dbname(); v != e {
t.Errorf("Expected %q, got %q", e, v)
}
}