Go wrapper around Docker Compose, useful for integration testing.
Example:
// Define Compose config.
var composeYML =`
test_mockserver:
container_name: ms
image: jamesdbloom/mockserver
ports:
- "10000:1080"
- "${SOME_ENV_VAR}" # This is replaced with the value of SOME_ENV_VAR.
test_postgres:
container_name: pg
image: postgres
ports:
- "5432"
`
// Start containers.
c, err := compose.Start(composeYML, true, true)
if err != nil {
panic(err)
}
defer c.Kill()
// Build MockServer public URL.
mockServerURL := fmt.Sprintf(
"http://%v:%v",
compose.MustInferDockerHost(),
c.Containers["ms"].MustGetFirstPublicPort(1080, "tcp"))
// Wait for MockServer to start accepting connections.
MustConnectWithDefaults(func() error {
_, err := http.Get(mockServerURL)
return err
})