I’d like to use testcontainers for integration testing. I need to test against a clickhouse storage.
The docker image is yandex/clichouse-server
My code thus far (imported mostly from the official redis example on testcontainers website):
ctx := context.Background()
req := testcontainers.ContainerRequest{
Image: "yandex/clickhouse-server",
ExposedPorts: []string{"9000/tcp"},
}
chContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
require.NoError(t, err, "unexpected error while creating clickhouse container")
endpoint, err := chContainer.Endpoint(ctx, "")
require.NoError(t, err)
This throws an error port not found
on getting the endpoint, and I’m not sure where to go from there.
2
Answers
Here is what I got working after trial / errors:
This spins up a clickhouse container and returns the sql.Db or t/o after 10 seconds.
Have you tried using the wait APIs in Testcontainers Go? https://github.com/testcontainers/testcontainers-go/tree/main/wait
With them you’ll be able to wait for multiple things (even at the same time):
You can find useful examples in the repository. I.e., and example for a log entry:
EDIT: a more elaborated example, including a wait strategy using HTTP requests would be: