MCPcopy
hub / github.com/jackc/pgx / TestConnectCustomLookupWithPort

Function TestConnectCustomLookupWithPort

pgconn/pgconn_test.go:607–642  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

605}
606
607func 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
644func TestConnectWithRuntimeParams(t *testing.T) {
645 t.Parallel()

Callers

nothing calls this directly

Calls 3

ParseConfigFunction · 0.92
ConnectConfigFunction · 0.92
closeConnFunction · 0.70

Tested by

no test coverage detected