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

Function TestResponseCheckOnly

elasticsearch_internal_test.go:426–525  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

424}
425
426func TestResponseCheckOnly(t *testing.T) {
427 tests := []struct {
428 name string
429 response *http.Response
430 requestErr error
431 wantErr bool
432 }{
433 {
434 name: "Valid answer with header",
435 response: &http.Response{
436 Header: http.Header{"X-Elastic-Product": []string{"Elasticsearch"}},
437 Body: io.NopCloser(strings.NewReader("{}")),
438 },
439 wantErr: false,
440 },
441 {
442 name: "Valid answer without header",
443 response: &http.Response{
444 StatusCode: http.StatusOK,
445 Body: io.NopCloser(strings.NewReader("{}")),
446 },
447 wantErr: true,
448 },
449 {
450 name: "Valid answer with header and response check",
451 response: &http.Response{
452 Header: http.Header{"X-Elastic-Product": []string{"Elasticsearch"}},
453 Body: io.NopCloser(strings.NewReader("{}")),
454 },
455 wantErr: false,
456 },
457 {
458 name: "Valid answer without header and response check",
459 response: &http.Response{
460 StatusCode: http.StatusOK,
461 Body: io.NopCloser(strings.NewReader("{}")),
462 },
463 wantErr: true,
464 },
465 {
466 name: "Request failed",
467 response: nil,
468 requestErr: errors.New("request failed"),
469 wantErr: true,
470 },
471 {
472 name: "Valid request, 500 response",
473 response: &http.Response{
474 StatusCode: http.StatusInternalServerError,
475 Body: io.NopCloser(strings.NewReader("")),
476 },
477 requestErr: nil,
478 wantErr: false,
479 },
480 {
481 name: "Valid request, 404 response",
482 response: &http.Response{
483 StatusCode: http.StatusNotFound,

Callers

nothing calls this directly

Calls 4

WithTransportOptionsFunction · 0.85
NewFunction · 0.50
RunMethod · 0.45
IndicesMethod · 0.45

Tested by

no test coverage detected