Skip to content

Instantly share code, notes, and snippets.

@fbiville
Created November 27, 2020 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbiville/15050a734802a6374b3d3aafbedbfb55 to your computer and use it in GitHub Desktop.
Save fbiville/15050a734802a6374b3d3aafbedbfb55 to your computer and use it in GitHub Desktop.
Medium blogpost code snippet 1
import (
"context"
"fmt"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
func startContainer(ctx context.Context, username, password string) (testcontainers.Container, error) {
request := testcontainers.ContainerRequest{
Image: "neo4j", // get latest Neo4j Docker image
ExposedPorts: []string{"7687/tcp"}, // expose only Bolt port
Env: map[string]string{"NEO4J_AUTH": fmt.Sprintf("%s/%s", username, password)}, // override default credentials
WaitingFor: wait.ForLog("Bolt enabled"), // wait for Bolt
}
return testcontainers.GenericContainer(
ctx,
testcontainers.GenericContainerRequest{
ContainerRequest: request,
Started: true, // start container immediately
},
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment