cassandra

package module
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithConfigFile

func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption

WithConfigFile sets the YAML config file to be used for the cassandra container It will also set the "configFile" parameter to the path of the config file as a command line argument to the container.

func WithInitScripts

func WithInitScripts(scripts ...string) testcontainers.CustomizeRequestOption

WithInitScripts sets the init cassandra queries to be run when the container starts

Types

type CassandraContainer

type CassandraContainer struct {
	testcontainers.Container
}

CassandraContainer represents the Cassandra container type used in the module

func RunContainer

func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error)

RunContainer creates an instance of the Cassandra container type

Example
// runCassandraContainer {
ctx := context.Background()

cassandraContainer, err := cassandra.RunContainer(ctx,
	testcontainers.WithImage("cassandra:4.1.3"),
	cassandra.WithInitScripts(filepath.Join("testdata", "init.cql")),
	cassandra.WithConfigFile(filepath.Join("testdata", "config.yaml")),
)
if err != nil {
	log.Fatalf("failed to start container: %s", err)
}

// Clean up the container
defer func() {
	if err := cassandraContainer.Terminate(ctx); err != nil {
		log.Fatalf("failed to terminate container: %s", err)
	}
}()
// }

state, err := cassandraContainer.State(ctx)
if err != nil {
	log.Fatalf("failed to get container state: %s", err) // nolint:gocritic
}

fmt.Println(state.Running)

connectionHost, err := cassandraContainer.ConnectionHost(ctx)
if err != nil {
	log.Fatalf("failed to get connection host: %s", err)
}

cluster := gocql.NewCluster(connectionHost)
session, err := cluster.CreateSession()
if err != nil {
	log.Fatalf("failed to create session: %s", err)
}
defer session.Close()

var version string
err = session.Query("SELECT release_version FROM system.local").Scan(&version)
if err != nil {
	log.Fatalf("failed to query: %s", err)
}

fmt.Println(version)
Output:

true
4.1.3

func (*CassandraContainer) ConnectionHost

func (c *CassandraContainer) ConnectionHost(ctx context.Context) (string, error)

ConnectionHost returns the host and port of the cassandra container, using the default, native 9000 port, and obtaining the host and exposed port from the container

Jump to

Keyboard shortcuts

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