connectionForQuery returns the connection to use for the given query
(t *testing.T, query string, connections map[string]*pgx.Conn, primaryDns string)
| 837 | |
| 838 | // connectionForQuery returns the connection to use for the given query |
| 839 | func connectionForQuery(t *testing.T, query string, connections map[string]*pgx.Conn, primaryDns string) *pgx.Conn { |
| 840 | target, client := clientSpecFromQueryComment(query) |
| 841 | var conn *pgx.Conn |
| 842 | switch target { |
| 843 | case "primary": |
| 844 | conn = connections[client] |
| 845 | if conn == nil { |
| 846 | var err error |
| 847 | conn, err = pgx.Connect(context.Background(), primaryDns) |
| 848 | require.NoError(t, err) |
| 849 | connections[client] = conn |
| 850 | } |
| 851 | case "replica": |
| 852 | conn = connections["replica"] |
| 853 | default: |
| 854 | require.Fail(t, "Invalid target in setup script: ", target) |
| 855 | } |
| 856 | return conn |
| 857 | } |
| 858 | |
| 859 | // handlePseudoQuery handles special pseudo-queries that are used to orchestrate replication tests and returns whether |
| 860 | // one was handled. |
no test coverage detected