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

Function TestMetaHeader

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

Source from the content-addressed store, hash-verified

795}
796
797func TestMetaHeader(t *testing.T) {
798 t.Run("MetaHeader with elastictransport", func(t *testing.T) {
799 tp, err := elastictransport.New(elastictransport.Config{
800 URLs: []*url.URL{{Scheme: "http", Host: "foo"}},
801 Transport: &mockTransp{
802 RoundTripFunc: func(request *http.Request) (*http.Response, error) {
803 h := request.Header.Get(HeaderClientMeta)
804 if !metaHeaderReValidation.MatchString(h) {
805 t.Errorf("expected client metaheader to validate regexp, got: %s", h)
806 }
807
808 return &http.Response{
809 Header: http.Header{"X-Elastic-Product": []string{"Elasticsearch"}},
810 StatusCode: http.StatusOK,
811 Status: "OK",
812 Body: io.NopCloser(strings.NewReader("")),
813 }, nil
814 },
815 },
816 })
817 if err != nil {
818 t.Fatalf("Unexpected error: %s", err)
819 }
820
821 c, err := New()
822 if err != nil {
823 t.Fatalf("Unexpected error: %s", err)
824 }
825 c.Transport = tp
826
827 _, err = c.Info()
828 if err != nil {
829 t.Fatalf("Unexpected error: %s", err)
830 }
831 })
832
833 t.Run("Metaheader with typedclient", func(t *testing.T) {
834 tp, err := elastictransport.New(elastictransport.Config{
835 URLs: []*url.URL{{Scheme: "http", Host: "foo"}},
836 Transport: &mockTransp{
837 RoundTripFunc: func(request *http.Request) (*http.Response, error) {
838 h := request.Header.Get(HeaderClientMeta)
839 if !metaHeaderReValidation.MatchString(h) {
840 t.Errorf("expected client metaheader to validate regexp, got: %s", h)
841 }
842 if !strings.Contains(h, "hl=1") {
843 t.Errorf("invalid metaheader, should contain hl=1, got: %s", h)
844 }
845
846 return &http.Response{
847 Header: http.Header{"X-Elastic-Product": []string{"Elasticsearch"}},
848 StatusCode: http.StatusOK,
849 Status: "OK",
850 Body: io.NopCloser(strings.NewReader("")),
851 }, nil
852 },
853 },
854 })

Callers

nothing calls this directly

Calls 6

NewTypedFunction · 0.85
DoMethod · 0.65
NewFunction · 0.50
RunMethod · 0.45
GetMethod · 0.45
InfoMethod · 0.45

Tested by

no test coverage detected