Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( // DefaultUser is the default username for the ArangoDB container. // This is the username to be used when connecting to the ArangoDB instance. DefaultUser = "root" )
Variables ¶
This section is empty.
Functions ¶
func WithRootPassword ¶
func WithRootPassword(password string) testcontainers.CustomizeRequestOption
WithRootPassword sets the password for the ArangoDB root user
Types ¶
type Container ¶
type Container struct {
testcontainers.Container
// contains filtered or unexported fields
}
Container represents the ArangoDB container type used in the module
func Run ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
Run creates an instance of the ArangoDB container type
Example ¶
// runArangoDBContainer {
ctx := context.Background()
const password = "t3stc0ntain3rs!"
arangodbContainer, err := tcarangodb.Run(ctx, "arangodb:3.11.5", tcarangodb.WithRootPassword(password))
defer func() {
if err := testcontainers.TerminateContainer(arangodbContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := arangodbContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
Output: true
Example (UsingClient) ¶
ctx := context.Background()
const password = "t3stc0ntain3rs!"
arangodbContainer, err := tcarangodb.Run(
ctx, "arangodb:3.11.5",
tcarangodb.WithRootPassword(password),
)
defer func() {
if err := testcontainers.TerminateContainer(arangodbContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
httpAddress, err := arangodbContainer.HTTPEndpoint(ctx)
if err != nil {
log.Printf("failed to get transport address: %s", err)
return
}
// Create an HTTP connection to the database
endpoint := connection.NewRoundRobinEndpoints([]string{httpAddress})
conn := connection.NewHttp2Connection(connection.DefaultHTTP2ConfigurationWrapper(endpoint, true))
// Add authentication
auth := connection.NewBasicAuth(arangodbContainer.Credentials())
err = conn.SetAuthentication(auth)
if err != nil {
log.Printf("Failed to set authentication: %v", err)
return
}
// Create a client
client := arangodb.NewClient(conn)
// Ask the version of the server
versionInfo, err := client.Version(context.Background())
if err != nil {
log.Printf("Failed to get version info: %v", err)
return
}
fmt.Println(versionInfo.Server)
Output: arango
func (*Container) Credentials ¶
Credentials returns the credentials for the ArangoDB container: first return value is the username, second is the password.
Click to show internal directories.
Click to hide internal directories.