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

Function TestNew_WithCompatibilityMode

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

Source from the content-addressed store, hash-verified

257}
258
259func TestNew_WithCompatibilityMode(t *testing.T) {
260 t.Parallel()
261
262 var capturedReq *http.Request
263 c, err := New(
264 WithCompatibilityMode(),
265 WithTransportOptions(
266 elastictransport.WithTransport(&mockTransp{
267 RoundTripFunc: func(req *http.Request) (*http.Response, error) {
268 capturedReq = req
269 return &http.Response{
270 StatusCode: http.StatusOK,
271 Header: http.Header{"X-Elastic-Product": []string{"Elasticsearch"}},
272 Body: io.NopCloser(strings.NewReader("{}")),
273 }, nil
274 },
275 }),
276 ),
277 )
278 if err != nil {
279 t.Fatalf("Unexpected error: %s", err)
280 }
281
282 req := &http.Request{
283 URL: &url.URL{},
284 Header: make(http.Header),
285 Body: io.NopCloser(strings.NewReader("{}")),
286 }
287 _, err = c.Perform(req)
288 if err != nil {
289 t.Fatalf("Unexpected error: %s", err)
290 }
291
292 if capturedReq.Header.Get("Accept") != compatibilityHeader {
293 t.Errorf("Expected compatibility Accept header, got: %s", capturedReq.Header.Get("Accept"))
294 }
295 if capturedReq.Header.Get("Content-Type") != compatibilityHeader {
296 t.Errorf("Expected compatibility Content-Type header, got: %s", capturedReq.Header.Get("Content-Type"))
297 }
298}
299
300func TestNew_WithCompatibilityModeEnv(t *testing.T) {
301 t.Setenv(esCompatHeader, "true")

Callers

nothing calls this directly

Calls 5

WithCompatibilityModeFunction · 0.85
WithTransportOptionsFunction · 0.85
PerformMethod · 0.65
NewFunction · 0.50
GetMethod · 0.45

Tested by

no test coverage detected