(t *testing.T)
| 204 | } |
| 205 | |
| 206 | func TestNew_WithAPIKey(t *testing.T) { |
| 207 | t.Parallel() |
| 208 | |
| 209 | var capturedReq *http.Request |
| 210 | c, err := New( |
| 211 | WithAPIKey("dGVzdGtleQ=="), |
| 212 | WithTransportOptions( |
| 213 | elastictransport.WithTransport(&mockTransp{ |
| 214 | RoundTripFunc: func(req *http.Request) (*http.Response, error) { |
| 215 | capturedReq = req |
| 216 | return &http.Response{ |
| 217 | StatusCode: http.StatusOK, |
| 218 | Header: http.Header{"X-Elastic-Product": []string{"Elasticsearch"}}, |
| 219 | Body: io.NopCloser(strings.NewReader("{}")), |
| 220 | }, nil |
| 221 | }, |
| 222 | }), |
| 223 | ), |
| 224 | ) |
| 225 | if err != nil { |
| 226 | t.Fatalf("Unexpected error: %s", err) |
| 227 | } |
| 228 | |
| 229 | _, err = c.Info() |
| 230 | if err != nil { |
| 231 | t.Fatalf("Unexpected error: %s", err) |
| 232 | } |
| 233 | |
| 234 | auth := capturedReq.Header.Get("Authorization") |
| 235 | if !strings.HasPrefix(auth, "APIKey ") { |
| 236 | t.Errorf("Expected ApiKey authorization, got: %s", auth) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | func TestNew_WithTransportOptions(t *testing.T) { |
| 241 | t.Parallel() |
nothing calls this directly
no test coverage detected