connectionForQuery returns the connection to use for the given query
(t *testing.T, query string, connections map[string]*pgx.Conn, primaryDns string)
| 677 | |
| 678 | // connectionForQuery returns the connection to use for the given query |
| 679 | func connectionForQuery(t *testing.T, query string, connections map[string]*pgx.Conn, primaryDns string) *pgx.Conn { |
| 680 | target, client := clientSpecFromQueryComment(query) |
| 681 | var conn *pgx.Conn |
| 682 | switch target { |
| 683 | case "primary": |
| 684 | conn = connections[client] |
| 685 | if conn == nil { |
| 686 | var err error |
| 687 | conn, err = pgx.Connect(context.Background(), primaryDns) |
| 688 | require.NoError(t, err) |
| 689 | connections[client] = conn |
| 690 | } |
| 691 | case "replica": |
| 692 | conn = connections["replica"] |
| 693 | default: |
| 694 | require.Fail(t, "Invalid target in setup script: ", target) |
| 695 | } |
| 696 | return conn |
| 697 | } |
| 698 | |
| 699 | // handlePseudoQuery handles special pseudo-queries that are used to orchestrate replication tests and returns whether |
| 700 | // one was handled. |
no test coverage detected