Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( // Deprecated: it will be removed in the next major version DefaultBaseImage = "docker.elastic.co/elasticsearch/elasticsearch" // Deprecated: it will be removed in the next major version 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 Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ElasticsearchContainer, error)
Run creates an instance of the Elasticsearch container type
Example ¶
// runElasticsearchContainer { ctx := context.Background() elasticsearchContainer, err := elasticsearch.Run(ctx, "docker.elastic.co/elasticsearch/elasticsearch:8.9.0") defer func() { if err := testcontainers.TerminateContainer(elasticsearchContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } // } state, err := elasticsearchContainer.State(ctx) if err != nil { log.Printf("failed to get container state: %s", err) return } fmt.Println(state.Running)
Output: true
Example (ConnectUsingElasticsearchClient) ¶
// elasticsearchClient { ctx := context.Background() elasticsearchContainer, err := elasticsearch.Run( ctx, "docker.elastic.co/elasticsearch/elasticsearch:8.9.0", elasticsearch.WithPassword("foo"), ) defer func() { if err := testcontainers.TerminateContainer(elasticsearchContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } 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.Printf("error creating the client: %s", err) return } resp, err := esClient.Info() if err != nil { log.Printf("error getting response: %s", err) return } defer resp.Body.Close() // } var esResp ElasticsearchResponse if err := json.NewDecoder(resp.Body).Decode(&esResp); err != nil { log.Printf("error decoding response: %s", err) return } fmt.Println(esResp.Tagline)
Output: You Know, for Search
Example (WithUsingPassword) ¶
// usingPassword { ctx := context.Background() elasticsearchContainer, err := elasticsearch.Run( ctx, "docker.elastic.co/elasticsearch/elasticsearch:7.9.2", elasticsearch.WithPassword("foo"), ) defer func() { if err := testcontainers.TerminateContainer(elasticsearchContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } // } fmt.Println(strings.HasPrefix(elasticsearchContainer.Settings.Address, "http://")) fmt.Println(elasticsearchContainer.Settings.Password)
Output: true foo
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ElasticsearchContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the Elasticsearch container type
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.