Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( DefaultBaseImage = "docker.elastic.co/elasticsearch/elasticsearch" DefaultBaseImageOSS = "docker.elastic.co/elasticsearch/elasticsearch-oss" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ElasticsearchContainer ¶
type ElasticsearchContainer struct { testcontainers.Container Settings Options }
ElasticsearchContainer represents the Elasticsearch container type used in the module
func RunContainer ¶
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ElasticsearchContainer, error)
RunContainer creates an instance of the Elasticsearch container type
Example ¶
// runElasticsearchContainer { ctx := context.Background() elasticsearchContainer, err := elasticsearch.RunContainer(ctx, testcontainers.WithImage("docker.elastic.co/elasticsearch/elasticsearch:8.9.0")) if err != nil { log.Fatalf("failed to start container: %s", err) } defer func() { if err := elasticsearchContainer.Terminate(ctx); err != nil { log.Fatalf("failed to terminate container: %s", err) } }() // } state, err := elasticsearchContainer.State(ctx) if err != nil { log.Fatalf("failed to get container state: %s", err) // nolint:gocritic } fmt.Println(state.Running)
Output: true
Example (ConnectUsingElasticsearchClient) ¶
// elasticsearchClient { ctx := context.Background() elasticsearchContainer, err := elasticsearch.RunContainer( ctx, testcontainers.WithImage("docker.elastic.co/elasticsearch/elasticsearch:8.9.0"), elasticsearch.WithPassword("foo"), ) if err != nil { log.Fatalf("failed to start container: %s", err) } defer func() { err := elasticsearchContainer.Terminate(ctx) if err != nil { log.Fatalf("failed to terminate container: %s", err) } }() cfg := es.Config{ Addresses: []string{ elasticsearchContainer.Settings.Address, }, Username: "elastic", Password: elasticsearchContainer.Settings.Password, CACert: elasticsearchContainer.Settings.CACert, } esClient, err := es.NewClient(cfg) if err != nil { log.Fatalf("error creating the client: %s", err) // nolint:gocritic } resp, err := esClient.Info() if err != nil { log.Fatalf("error getting response: %s", err) } defer resp.Body.Close() // } var esResp ElasticsearchResponse if err := json.NewDecoder(resp.Body).Decode(&esResp); err != nil { log.Fatalf("error decoding response: %s", err) } fmt.Println(esResp.Tagline)
Output: You Know, for Search
Example (WithUsingPassword) ¶
// usingPassword { ctx := context.Background() elasticsearchContainer, err := elasticsearch.RunContainer( ctx, testcontainers.WithImage("docker.elastic.co/elasticsearch/elasticsearch:7.9.2"), elasticsearch.WithPassword("foo"), ) if err != nil { log.Fatalf("failed to start container: %s", err) } defer func() { err := elasticsearchContainer.Terminate(ctx) if err != nil { log.Fatalf("failed to terminate container: %s", err) } }() // } fmt.Println(strings.HasPrefix(elasticsearchContainer.Settings.Address, "http://")) fmt.Println(elasticsearchContainer.Settings.Password)
Output: true foo
type Option ¶
type Option func(*Options)
Option is an option for the Elasticsearch container.
func WithPassword ¶
WithPassword sets the password for the Elasticsearch container.
Click to show internal directories.
Click to hide internal directories.