Last active
November 16, 2022 20:24
-
-
Save Abdulsametileri/ba4146d47e743a92c38c7e447f9d440d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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