add tests for ParseDSN

pull/76/head
deoxxa 2015-04-08 14:55:15 +10:00
parent 7e2886c576
commit 36d1a58b42
1 changed files with 49 additions and 0 deletions

View File

@ -255,6 +255,55 @@ func TestParseURI(t *testing.T) {
}
}
func TestParseDSN(t *testing.T) {
t.Parallel()
tests := []struct {
url string
connParams pgx.ConnConfig
}{
{
url: "user=jack password=secret host=localhost port=5432 dbname=mydb",
connParams: pgx.ConnConfig{
User: "jack",
Password: "secret",
Host: "localhost",
Port: 5432,
Database: "mydb",
},
},
{
url: "user=jack host=localhost port=5432 dbname=mydb",
connParams: pgx.ConnConfig{
User: "jack",
Host: "localhost",
Port: 5432,
Database: "mydb",
},
},
{
url: "user=jack host=localhost dbname=mydb",
connParams: pgx.ConnConfig{
User: "jack",
Host: "localhost",
Database: "mydb",
},
},
}
for i, tt := range tests {
connParams, err := pgx.ParseDSN(tt.url)
if err != nil {
t.Errorf("%d. Unexpected error from pgx.ParseDSN(%q) => %v", i, tt.url, err)
continue
}
if connParams != tt.connParams {
t.Errorf("%d. expected %#v got %#v", i, tt.connParams, connParams)
}
}
}
func TestExec(t *testing.T) {
t.Parallel()