Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrTLSNotEnabled = fmt.Errorf("tls not enabled")
Functions ¶
This section is empty.
Types ¶
type CockroachDBContainer ¶
type CockroachDBContainer struct { testcontainers.Container // contains filtered or unexported fields }
CockroachDBContainer represents the CockroachDB container type used in the module
func RunContainer ¶
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CockroachDBContainer, error)
RunContainer creates an instance of the CockroachDB container type
Example ¶
package main import ( "context" "fmt" "log" "net/url" "github.com/testcontainers/testcontainers-go/modules/cockroachdb" ) func main() { // runCockroachDBContainer { ctx := context.Background() cockroachdbContainer, err := cockroachdb.RunContainer(ctx) if err != nil { log.Fatalf("failed to start container: %s", err) } // Clean up the container defer func() { if err := cockroachdbContainer.Terminate(ctx); err != nil { log.Fatalf("failed to terminate container: %s", err) } }() // } state, err := cockroachdbContainer.State(ctx) if err != nil { log.Fatalf("failed to get container state: %s", err) // nolint:gocritic } fmt.Println(state.Running) addr, err := cockroachdbContainer.ConnectionString(ctx) if err != nil { log.Fatalf("failed to get connection string: %s", err) } u, err := url.Parse(addr) if err != nil { log.Fatalf("failed to parse connection string: %s", err) } u.Host = fmt.Sprintf("%s:%s", u.Hostname(), "xxx") fmt.Println(u.String()) }
Output: true postgres://root@localhost:xxx/defaultdb?sslmode=disable
func (*CockroachDBContainer) ConnectionString ¶
func (c *CockroachDBContainer) ConnectionString(ctx context.Context) (string, error)
ConnectionString returns the dial address to open a new connection to CockroachDB.
func (*CockroachDBContainer) MustConnectionString ¶
func (c *CockroachDBContainer) MustConnectionString(ctx context.Context) string
MustConnectionString panics if the address cannot be determined.
type Option ¶
type Option func(*options)
Option is an option for the CockroachDB container.
func WithDatabase ¶
WithDatabase sets the name of the database to use.
func WithPassword ¶
WithPassword sets the password when using password authentication.
func WithStoreSize ¶
WithStoreSize sets the amount of available in-memory storage. See https://www.cockroachlabs.com/docs/stable/cockroach-start#store
Click to show internal directories.
Click to hide internal directories.