/
request.go
53 lines (48 loc) · 1.54 KB
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package elasticsearch
import (
"time"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-units"
"go.nhat.io/testcontainers-extra"
extrawait "go.nhat.io/testcontainers-extra/wait"
)
// Request creates a new request for starting an elasticsearch server.
func Request(opts ...testcontainers.GenericContainerOption) testcontainers.StartGenericContainerRequest {
finalOpts := make([]testcontainers.GenericContainerOption, 1, len(opts)+1)
finalOpts[0] = testcontainers.PopulateHostPortEnv
finalOpts = append(finalOpts, opts...)
return testcontainers.StartGenericContainerRequest{
Request: testcontainers.ContainerRequest{
Name: "elasticsearch",
Image: "docker.elastic.co/elasticsearch/elasticsearch:7.15.1",
ExposedPorts: []string{":9200"},
Env: map[string]string{
"xpack.security.enabled": "false",
"discovery.type": "single-node",
"ES_JAVA_OPTS": "-Xms512m -Xmx512m",
},
Resources: container.Resources{Ulimits: []*units.Ulimit{
{
Name: "memlock",
Hard: -1,
Soft: -1,
},
{
Name: "nofile",
Hard: 65536,
Soft: 65536,
},
}},
WaitingFor: extrawait.ForHealthCheckCmd("curl", "--silent", "--fail", "localhost:9200/_cluster/health").
WithRetries(3).
WithStartPeriod(time.Minute).
WithTestTimeout(5 * time.Second).
WithTestInterval(10 * time.Second),
},
Options: finalOpts,
}
}
// URL returns the url for connecting to server.
func URL() string {
return "http://$ELASTICSEARCH_9200_HOST:$ELASTICSEARCH_9200_PORT/"
}