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

Function TestConnectWithAfterConnect

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

Source from the content-addressed store, hash-verified

840}
841
842func TestConnectWithAfterConnect(t *testing.T) {
843 t.Parallel()
844
845 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
846 defer cancel()
847
848 config, err := pgconn.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
849 require.NoError(t, err)
850
851 config.AfterConnect = func(ctx context.Context, conn *pgconn.PgConn) error {
852 _, err := conn.Exec(ctx, "set search_path to foobar;").ReadAll()
853 return err
854 }
855
856 conn, err := pgconn.ConnectConfig(ctx, config)
857 require.NoError(t, err)
858
859 results, err := conn.Exec(ctx, "show search_path;").ReadAll()
860 require.NoError(t, err)
861 defer closeConn(t, conn)
862
863 assert.Equal(t, []byte("foobar"), results[0].Rows[0][0])
864}
865
866func TestConnectConfigRequiresConfigFromParseConfig(t *testing.T) {
867 t.Parallel()

Callers

nothing calls this directly

Calls 5

ParseConfigFunction · 0.92
ConnectConfigFunction · 0.92
ReadAllMethod · 0.80
closeConnFunction · 0.70
ExecMethod · 0.65

Tested by

no test coverage detected