-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdburl_test.go
More file actions
27 lines (25 loc) · 1.07 KB
/
Copy pathdburl_test.go
File metadata and controls
27 lines (25 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package gadm
import "testing"
func TestDatabaseURL(t *testing.T) {
testcases := []struct {
url string
dsn string
}{
{url: "sqlite:path/to/sqlite.db", dsn: "path/to/sqlite.db"},
{url: "sqlite::memory:", dsn: ":memory:"},
{url: "postgres://localhost:5432/mydatabase?user=myuser&password=mypassword",
dsn: "host=localhost user=myuser password=mypassword dbname=mydatabase port=5432 sslmode=disable"},
{url: "postgres://user:password@localhost:5432/database",
dsn: "host=localhost user=user password=password dbname=database port=5432 sslmode=disable"},
{url: "mysql://user:password@localhost:3366/database?charset=utf8mb4&parseTime=True&loc=Local",
dsn: "user:password@localhost:3366/database?charset=utf8mb4&parseTime=True&loc=Local"},
{url: "mysql://localhost:3366/mydatabase?user=myuser&password=mypassword",
dsn: "myuser:mypassword@localhost:3366/mydatabase?user=myuser&password=mypassword"},
}
for _, testcase := range testcases {
du := Parse(testcase.url)
if du.DSN != testcase.dsn {
t.Errorf("expect: %s actual: %s", du.DSN, testcase.dsn)
}
}
}