(t *testing.T)
| 340 | } |
| 341 | |
| 342 | func TestEscapePostgresURLUserInfo(t *testing.T) { |
| 343 | t.Parallel() |
| 344 | |
| 345 | testcases := []struct { |
| 346 | input string |
| 347 | output string |
| 348 | err error |
| 349 | }{ |
| 350 | { |
| 351 | input: "postgres://coder:coder@localhost:5432/coder", |
| 352 | output: "postgres://coder:coder@localhost:5432/coder", |
| 353 | err: nil, |
| 354 | }, |
| 355 | { |
| 356 | input: "postgres://coder:co{der@localhost:5432/coder", |
| 357 | output: "postgres://coder:co%7Bder@localhost:5432/coder", |
| 358 | err: nil, |
| 359 | }, |
| 360 | { |
| 361 | input: "postgres://coder:co:der@localhost:5432/coder", |
| 362 | output: "postgres://coder:co:der@localhost:5432/coder", |
| 363 | err: nil, |
| 364 | }, |
| 365 | { |
| 366 | input: "postgres://coder:co der@localhost:5432/coder", |
| 367 | output: "postgres://coder:co%20der@localhost:5432/coder", |
| 368 | err: nil, |
| 369 | }, |
| 370 | { |
| 371 | input: "postgres://local host:5432/coder", |
| 372 | output: "", |
| 373 | err: xerrors.New("parse postgres url: parse \"postgres://local host:5432/coder\": invalid character \" \" in host name"), |
| 374 | }, |
| 375 | { |
| 376 | input: "postgres://coder:co?der@localhost:5432/coder", |
| 377 | output: "postgres://coder:co%3Fder@localhost:5432/coder", |
| 378 | err: nil, |
| 379 | }, |
| 380 | { |
| 381 | input: "postgres://coder:co#der@localhost:5432/coder", |
| 382 | output: "postgres://coder:co%23der@localhost:5432/coder", |
| 383 | err: nil, |
| 384 | }, |
| 385 | } |
| 386 | for _, tc := range testcases { |
| 387 | t.Run(tc.input, func(t *testing.T) { |
| 388 | t.Parallel() |
| 389 | o, err := escapePostgresURLUserInfo(tc.input) |
| 390 | assert.Equal(t, tc.output, o) |
| 391 | if tc.err != nil { |
| 392 | require.Error(t, err) |
| 393 | require.EqualValues(t, tc.err.Error(), err.Error()) |
| 394 | } else { |
| 395 | require.NoError(t, err) |
| 396 | } |
| 397 | }) |
| 398 | } |
| 399 | } |
nothing calls this directly
no test coverage detected