(t *testing.T, ctx context.Context, method, socketPath, path string, payload any)
| 122 | } |
| 123 | |
| 124 | func httpDo(t *testing.T, ctx context.Context, method, socketPath, path string, payload any) []byte { |
| 125 | t.Helper() |
| 126 | |
| 127 | var ( |
| 128 | body io.Reader |
| 129 | contentType string |
| 130 | ) |
| 131 | switch v := payload.(type) { |
| 132 | case nil: |
| 133 | body = http.NoBody |
| 134 | case []byte: |
| 135 | body = bytes.NewReader(v) |
| 136 | case string: |
| 137 | body = strings.NewReader(v) |
| 138 | default: |
| 139 | buf, err := json.Marshal(payload) |
| 140 | require.NoError(t, err) |
| 141 | body = bytes.NewReader(buf) |
| 142 | contentType = "application/json" |
| 143 | } |
| 144 | |
| 145 | req, err := http.NewRequestWithContext(ctx, method, "http://_"+path, body) |
| 146 | require.NoError(t, err) |
| 147 | |
| 148 | req.Header.Set("Content-Type", contentType) |
| 149 | |
| 150 | client := &http.Client{ |
| 151 | Transport: &http.Transport{ |
| 152 | DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { |
| 153 | var d net.Dialer |
| 154 | return d.DialContext(ctx, "unix", strings.TrimPrefix(socketPath, "unix://")) |
| 155 | }, |
| 156 | }, |
| 157 | } |
| 158 | resp, err := client.Do(req) |
| 159 | require.NoError(t, err) |
| 160 | defer resp.Body.Close() |
| 161 | |
| 162 | buf, err := io.ReadAll(resp.Body) |
| 163 | require.NoError(t, err) |
| 164 | |
| 165 | require.Less(t, resp.StatusCode, 400, string(buf)) |
| 166 | return buf |
| 167 | } |
| 168 | |
| 169 | func unmarshal(t *testing.T, buf []byte, v any) { |
| 170 | t.Helper() |
no test coverage detected