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

Function TestProductCheckError

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

Source from the content-addressed store, hash-verified

525}
526
527func TestProductCheckError(t *testing.T) {
528 var requestPaths []string
529 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
530 requestPaths = append(requestPaths, r.URL.Path)
531 if len(requestPaths) == 1 {
532 // Simulate transient error from a proxy on the first request.
533 // This must not be cached by the client.
534 w.WriteHeader(http.StatusBadGateway)
535 return
536 }
537
538 w.Header().Set("X-Elastic-Product", "Elasticsearch")
539 _, _ = w.Write([]byte("{}"))
540 }))
541 defer server.Close()
542
543 c, err := New(WithAddresses(server.URL), WithTransportOptions(elastictransport.WithDisableRetry()))
544 if err != nil {
545 t.Fatalf("Unexpected error: %s", err)
546 }
547 if _, err := c.Cat.Indices(); err != nil {
548 t.Fatalf("unexpected error: %s", err)
549 }
550 if c.productCheckSuccess {
551 t.Fatalf("product check should be invalid, got %v", c.productCheckSuccess)
552 }
553 if _, err := c.Cat.Indices(); err != nil {
554 t.Fatalf("unexpected error: %s", err)
555 }
556 if n := len(requestPaths); n != 2 {
557 t.Fatalf("expected 2 requests, got %d", n)
558 }
559 if !reflect.DeepEqual(requestPaths, []string{"/_cat/indices", "/_cat/indices"}) {
560 t.Fatalf("unexpected request paths: %s", requestPaths)
561 }
562 if !c.productCheckSuccess {
563 t.Fatalf("product check should be valid, got : %v", c.productCheckSuccess)
564 }
565}
566
567func TestFingerprint(t *testing.T) {
568 body := []byte(`{"body": true"}"`)

Callers

nothing calls this directly

Calls 8

WithAddressesFunction · 0.85
WithTransportOptionsFunction · 0.85
CloseMethod · 0.65
NewFunction · 0.50
SetMethod · 0.45
HeaderMethod · 0.45
WriteMethod · 0.45
IndicesMethod · 0.45

Tested by

no test coverage detected