forked from testcontainers/testcontainers-go
/
bigtable.go
50 lines (42 loc) · 1.2 KB
/
bigtable.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
package bigtable
import (
"context"
"fmt"
"github.com/testcontainers/testcontainers-go/wait"
"github.com/testcontainers/testcontainers-go"
)
// bigtableContainer represents the bigtable container type used in the module
type bigtableContainer struct {
testcontainers.Container
URI string
}
// setupBigtable creates an instance of the bigtable container type
func setupBigtable(ctx context.Context) (*bigtableContainer, error) {
req := testcontainers.ContainerRequest{
Image: "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators",
ExposedPorts: []string{"9000/tcp"},
WaitingFor: wait.ForLog("running"),
Cmd: []string{
"/bin/sh",
"-c",
"gcloud beta emulators bigtable start --host-port 0.0.0.0:9000",
},
}
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
return nil, err
}
mappedPort, err := container.MappedPort(ctx, "9000")
if err != nil {
return nil, err
}
hostIP, err := container.Host(ctx)
if err != nil {
return nil, err
}
uri := fmt.Sprintf("%s:%s", hostIP, mappedPort.Port())
return &bigtableContainer{Container: container, URI: uri}, nil
}