MCPcopy Create free account
hub / github.com/go-pg/pg / TestOptions_ToURL

Function TestOptions_ToURL

options_test.go:267–291  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

265}
266
267func TestOptions_ToURL(t *testing.T) {
268 tests := []struct {
269 name string
270 opts *Options
271 expected string
272 }{
273 {"Empty", &Options{Database: "postgres"}, "postgres://localhost:5432/postgres?sslmode=disable"},
274 {"User", &Options{Database: "postgres", User: "postgres"}, "postgres://postgres@localhost:5432/postgres?sslmode=disable"},
275 {"UserPass", &Options{Database: "postgres", User: "postgres", Password: "password"}, "postgres://postgres:password@localhost:5432/postgres?sslmode=disable"},
276 {"UserPassAddr", &Options{Database: "postgres", User: "postgres", Password: "password", Addr: "somewhere:1234"}, "postgres://postgres:password@somewhere:1234/postgres?sslmode=disable"},
277 {"UserPassAddrAppl", &Options{Database: "postgres", User: "postgres", Password: "password", Addr: "somewhere:1234", ApplicationName: "test"}, "postgres://postgres:password@somewhere:1234/postgres?application_name=test&sslmode=disable"},
278 {"UserPassAddrApplTimeout", &Options{Database: "postgres", User: "postgres", Password: "password", Addr: "somewhere:1234", ApplicationName: "test", DialTimeout: time.Second}, "postgres://postgres:password@somewhere:1234/postgres?application_name=test&connect_timeout=1&sslmode=disable"},
279 }
280 for _, tt := range tests {
281 t.Run(tt.name, func(t *testing.T) {
282 assert := assert.New(t)
283
284 actual := tt.opts.ToURL()
285 assert.Equal(tt.expected, actual)
286
287 _, err := ParseURL(actual)
288 assert.NoError(err)
289 })
290 }
291}
292
293func TestOptions_ToURL_reparsable(t *testing.T) {
294 assert := assert.New(t)

Callers

nothing calls this directly

Calls 3

ParseURLFunction · 0.85
ToURLMethod · 0.80
NewMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…