cassandra

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2023 License: MIT Imports: 5 Imported by: 0

README

Gnomock Cassandra

Gnomock Cassandra is a Gnomock preset for running tests against a real Cassandra container, without mocks.

package cassandra_test

func TestPreset(t *testing.T) {
	t.Parallel()

	for _, version := range []string{"4.0", "3"} {
		t.Run(version, testPreset(version))
	}
}

func testPreset(version string) func(t *testing.T) {
	return func(t *testing.T) {
		p := cassandra.Preset(
			cassandra.WithVersion(version),
		)
		container, err := gnomock.Start(p)

		defer func() { require.NoError(t, gnomock.Stop(container)) }()

		require.NoError(t, err)

		addr := container.DefaultAddress()
		require.NotEmpty(t, addr)

		cluster := gocql.NewCluster(addr)
		cluster.Authenticator = gocql.PasswordAuthenticator{
			Username: cassandra.DefaultUser,
			Password: cassandra.DefaultPassword,
		}

		session, err := cluster.CreateSession()
		require.NoError(t, err)

		defer session.Close()

		err = session.Query("create keyspace gnomock with replication = {'class':'SimpleStrategy', 'replication_factor' : 1};").Exec()
		require.NoError(t, err)

		err = session.Query("CREATE TABLE gnomock.test (id UUID, PRIMARY KEY (id));").Exec()
		require.NoError(t, err)
	}
}

Documentation

Overview

Package cassandra includes Cassandra implementation of Gnomock Preset interface. This Preset can be passed to gnomock.Start() function to create a configured Cassandra container to use in tests.

Cassandra containers always use cassandra/cassandra username/password pair, it is currently not possible to use different values.

Index

Constants

View Source
const (
	DefaultUser     = "cassandra"
	DefaultPassword = "cassandra"
)

By default, Cassandra containers will use these values.

Variables

This section is empty.

Functions

func Preset

func Preset(opts ...Option) gnomock.Preset

Preset creates a new Gmomock Cassandra preset. This preset includes a Cassandra specific healthcheck function and default Cassandra image and port.

Containers created using this preset should be accessed using cassandra/cassandra username/password pair.

Types

type Option

type Option func(*P)

Option is an optional configuration of this Gnomock preset. Use available Options to configure the container.

func WithVersion

func WithVersion(version string) Option

WithVersion sets image version.

type P

type P struct {
	Version string `json:"version"`
}

P is a Gnomock Preset implementation for Cassandra.

func (*P) Image

func (p *P) Image() string

Image returns an image that should be pulled to create this container.

func (*P) Options

func (p *P) Options() []gnomock.Option

Options returns a list of options to configure this container.

func (*P) Ports

func (p *P) Ports() gnomock.NamedPorts

Ports returns ports that should be used to access this container.

Jump to

Keyboard shortcuts

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