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: "******", Password: "******", Host: "localhost", Port: 5432, Database: "mydb", }, }, { url: "user=jack host=localhost port=5432 dbname=mydb", connParams: pgx.ConnConfig{ User: "******", Host: "localhost", Port: 5432, Database: "mydb", }, }, { url: "user=jack host=localhost dbname=mydb", connParams: pgx.ConnConfig{ User: "******", 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 !reflect.DeepEqual(connParams, tt.connParams) { t.Errorf("%d. expected %#v got %#v", i, tt.connParams, connParams) } } }
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 sslmode=disable", connParams: pgx.ConnConfig{ User: "******", Password: "******", Host: "localhost", Port: 5432, Database: "mydb", RuntimeParams: map[string]string{}, }, }, { url: "user=jack password=secret host=localhost port=5432 dbname=mydb sslmode=prefer", connParams: pgx.ConnConfig{ User: "******", Password: "******", Host: "localhost", Port: 5432, Database: "mydb", TLSConfig: &tls.Config{ InsecureSkipVerify: true, }, UseFallbackTLS: true, FallbackTLSConfig: nil, RuntimeParams: map[string]string{}, }, }, { url: "user=jack password=secret host=localhost port=5432 dbname=mydb", connParams: pgx.ConnConfig{ User: "******", Password: "******", Host: "localhost", Port: 5432, Database: "mydb", TLSConfig: &tls.Config{ InsecureSkipVerify: true, }, UseFallbackTLS: true, FallbackTLSConfig: nil, RuntimeParams: map[string]string{}, }, }, { url: "user=jack host=localhost port=5432 dbname=mydb", connParams: pgx.ConnConfig{ User: "******", Host: "localhost", Port: 5432, Database: "mydb", TLSConfig: &tls.Config{ InsecureSkipVerify: true, }, UseFallbackTLS: true, FallbackTLSConfig: nil, RuntimeParams: map[string]string{}, }, }, { url: "user=jack host=localhost dbname=mydb", connParams: pgx.ConnConfig{ User: "******", Host: "localhost", Database: "mydb", TLSConfig: &tls.Config{ InsecureSkipVerify: true, }, UseFallbackTLS: true, FallbackTLSConfig: nil, RuntimeParams: map[string]string{}, }, }, { url: "user=jack host=localhost dbname=mydb application_name=pgxtest search_path=myschema", connParams: pgx.ConnConfig{ User: "******", Host: "localhost", Database: "mydb", TLSConfig: &tls.Config{ InsecureSkipVerify: true, }, UseFallbackTLS: true, FallbackTLSConfig: nil, RuntimeParams: map[string]string{ "application_name": "pgxtest", "search_path": "myschema", }, }, }, } 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 !reflect.DeepEqual(connParams, tt.connParams) { t.Errorf("%d. expected %#v got %#v", i, tt.connParams, connParams) } } }