(t *testing.T)
| 525 | } |
| 526 | |
| 527 | func 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 | |
| 567 | func TestFingerprint(t *testing.T) { |
| 568 | body := []byte(`{"body": true"}"`) |
nothing calls this directly
no test coverage detected