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 Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error)
Run creates an instance of the Cassandra container type
Example ¶
// runCassandraContainer {
ctx := context.Background()
cassandraContainer, err := cassandra.Run(ctx,
"cassandra:4.1.3",
cassandra.WithInitScripts(filepath.Join("testdata", "init.cql")),
cassandra.WithConfigFile(filepath.Join("testdata", "config.yaml")),
)
defer func() {
if err := testcontainers.TerminateContainer(cassandraContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := cassandraContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
connectionHost, err := cassandraContainer.ConnectionHost(ctx)
if err != nil {
log.Printf("failed to get connection host: %s", err)
return
}
cluster := gocql.NewCluster(connectionHost)
session, err := cluster.CreateSession()
if err != nil {
log.Printf("failed to create session: %s", err)
return
}
defer session.Close()
var version string
err = session.Query("SELECT release_version FROM system.local").Scan(&version)
if err != nil {
log.Printf("failed to query: %s", err)
return
}
fmt.Println(version)
Output: true 4.1.3
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the Cassandra container type
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 9042 port, and obtaining the host and exposed port from the container