(t *testing.T)
| 671 | } |
| 672 | |
| 673 | func TestConnectWithFallback(t *testing.T) { |
| 674 | t.Parallel() |
| 675 | |
| 676 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 677 | defer cancel() |
| 678 | |
| 679 | config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE")) |
| 680 | require.NoError(t, err) |
| 681 | |
| 682 | // Prepend current primary config to fallbacks |
| 683 | config.Fallbacks = append([]*pgconn.FallbackConfig{ |
| 684 | { |
| 685 | Host: config.Host, |
| 686 | Port: config.Port, |
| 687 | TLSConfig: config.TLSConfig, |
| 688 | }, |
| 689 | }, config.Fallbacks...) |
| 690 | |
| 691 | // Make primary config bad |
| 692 | config.Host = "localhost" |
| 693 | config.Port = 1 // presumably nothing listening here |
| 694 | |
| 695 | // Prepend bad first fallback |
| 696 | config.Fallbacks = append([]*pgconn.FallbackConfig{ |
| 697 | { |
| 698 | Host: "localhost", |
| 699 | Port: 1, |
| 700 | TLSConfig: config.TLSConfig, |
| 701 | }, |
| 702 | }, config.Fallbacks...) |
| 703 | |
| 704 | conn, err := pgconn.ConnectConfig(ctx, config) |
| 705 | require.NoError(t, err) |
| 706 | closeConn(t, conn) |
| 707 | } |
| 708 | |
| 709 | func TestConnectFailsWithResolveFailureAndFailedConnectionAttempts(t *testing.T) { |
| 710 | t.Parallel() |
nothing calls this directly
no test coverage detected