MCPcopy
hub / github.com/elastic/go-elasticsearch / TestNew_WithAPIKey

Function TestNew_WithAPIKey

options_test.go:206–238  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

204}
205
206func 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
240func TestNew_WithTransportOptions(t *testing.T) {
241 t.Parallel()

Callers

nothing calls this directly

Calls 5

WithAPIKeyFunction · 0.85
WithTransportOptionsFunction · 0.85
NewFunction · 0.50
InfoMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected