(t *testing.T)
| 605 | } |
| 606 | |
| 607 | func TestConnectCustomLookupWithPort(t *testing.T) { |
| 608 | t.Parallel() |
| 609 | |
| 610 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 611 | defer cancel() |
| 612 | |
| 613 | connString := os.Getenv("PGX_TEST_TCP_CONN_STRING") |
| 614 | if connString == "" { |
| 615 | t.Skipf("Skipping due to missing environment variable %v", "PGX_TEST_TCP_CONN_STRING") |
| 616 | } |
| 617 | |
| 618 | config, err := pgconn.ParseConfig(connString) |
| 619 | require.NoError(t, err) |
| 620 | |
| 621 | origPort := config.Port |
| 622 | // Change the config an invalid port so it will fail if used |
| 623 | config.Port = 0 |
| 624 | |
| 625 | looked := false |
| 626 | config.LookupFunc = func(ctx context.Context, host string) ([]string, error) { |
| 627 | looked = true |
| 628 | addrs, err := net.LookupHost(host) |
| 629 | if err != nil { |
| 630 | return nil, err |
| 631 | } |
| 632 | for i := range addrs { |
| 633 | addrs[i] = net.JoinHostPort(addrs[i], strconv.FormatUint(uint64(origPort), 10)) |
| 634 | } |
| 635 | return addrs, nil |
| 636 | } |
| 637 | |
| 638 | conn, err := pgconn.ConnectConfig(ctx, config) |
| 639 | require.NoError(t, err) |
| 640 | require.True(t, looked) |
| 641 | closeConn(t, conn) |
| 642 | } |
| 643 | |
| 644 | func TestConnectWithRuntimeParams(t *testing.T) { |
| 645 | t.Parallel() |
nothing calls this directly
no test coverage detected