arangodb

package module
v0.44.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 6 Imported by: 0

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

Run creates an instance of the ArangoDB container type

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/testcontainers/testcontainers-go"
	tcarangodb "github.com/testcontainers/testcontainers-go/modules/arangodb"
)

func main() {
	// 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)
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/arangodb/go-driver/v2/arangodb"
	"github.com/arangodb/go-driver/v2/connection"

	"github.com/testcontainers/testcontainers-go"
	tcarangodb "github.com/testcontainers/testcontainers-go/modules/arangodb"
)

func main() {
	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

func (c *Container) Credentials() (string, string)

Credentials returns the credentials for the ArangoDB container: first return value is the username, second is the password.

func (*Container) HTTPEndpoint

func (c *Container) HTTPEndpoint(ctx context.Context) (string, error)

HTTPEndpoint returns the HTTP endpoint of the ArangoDB container, using the following format: `http://$host:$port`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL