fxelasticsearchtest

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockESClient

func NewMockESClient(responses []MockResponse) (*elasticsearch.Client, error)

NewMockESClient creates an Elasticsearch client with mocked HTTP transport. This allows you to test with the real elasticsearch.Client API while controlling responses.

func NewMockESClientWithError

func NewMockESClientWithError(err error) (*elasticsearch.Client, error)

NewMockESClientWithError creates an Elasticsearch client that returns an error on requests. This is useful for testing error handling.

func NewMockESClientWithSingleResponse

func NewMockESClientWithSingleResponse(responseBody string, statusCode int) (*elasticsearch.Client, error)

NewMockESClientWithSingleResponse creates an Elasticsearch client with a single mock response. This is a convenience function for simple test cases.

Types

type MockResponse

type MockResponse struct {
	StatusCode   int
	ResponseBody string
	Error        error
}

MockResponse represents a single mock HTTP response.

type MockTransport

type MockTransport struct {
	// contains filtered or unexported fields
}

MockTransport provides HTTP transport mock for testing Elasticsearch client. This allows testing with the real elasticsearch.Client API without interface constraints.

func NewMockTransport

func NewMockTransport(responses []MockResponse) *MockTransport

NewMockTransport creates a new MockTransport with the given responses. Responses are returned in order. If more requests are made than responses provided, the last response is repeated.

func (*MockTransport) RoundTrip

func (t *MockTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL