Skip to content

Instantly share code, notes, and snippets.

@Abdulsametileri
Last active November 16, 2022 20:24
Show Gist options
  • Save Abdulsametileri/ba4146d47e743a92c38c7e447f9d440d to your computer and use it in GitHub Desktop.
Save Abdulsametileri/ba4146d47e743a92c38c7e447f9d440d to your computer and use it in GitHub Desktop.
func (t *TestContainerWrapper) RunContainer() error {
req := testcontainers.ContainerRequest{
Image: fmt.Sprintf("%s:%s", RedpandaImage, RedpandaVersion),
ExposedPorts: []string{
"9092:9092/tcp",
},
Cmd: []string{"redpanda", "start"},
WaitingFor: wait.ForLog("Successfully started Redpanda!"),
AutoRemove: true,
}
container, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
return fmt.Errorf("could not create container: %w", err)
}
mPort, err := container.MappedPort(context.Background(), "9092")
if err != nil {
return fmt.Errorf("could not get mapped port from the container: %w", err)
}
t.container = container
t.hostPort = mPort.Int()
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment