mirror of
https://github.com/status-im/fathom.git
synced 2025-03-01 11:30:28 +00:00
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package sqlstore
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestConfigDSN(t *testing.T) {
|
|
c := Config{
|
|
Driver: "postgres",
|
|
user: "john",
|
|
password: "foo",
|
|
}
|
|
e := fmt.Sprintf("user=%s password=%s", c.user, c.password)
|
|
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",
|
|
}
|
|
e = fmt.Sprintf("user=%s password=%s sslmode=%s", c.user, c.password, c.sslmode)
|
|
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)
|
|
}
|
|
}
|