Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithPassword ¶
func WithPassword(password string) testcontainers.CustomizeRequestOption
WithPassword sets the password for the Databend container.
func WithUsername ¶
func WithUsername(username string) testcontainers.CustomizeRequestOption
WithUsername sets the username for the Databend container. WithUsername is Run option that configures the default query user by setting the `QUERY_DEFAULT_USER` container environment variable.
Types ¶
type DatabendContainer ¶
type DatabendContainer struct {
testcontainers.Container
// contains filtered or unexported fields
}
DatabendContainer represents the Databend container type used in the module
func Run ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*DatabendContainer, error)
Run creates an instance of the Databend container type
Example ¶
ctx := context.Background()
databendContainer, err := databend.Run(ctx,
"datafuselabs/databend:v1.2.615",
databend.WithUsername("test1"),
databend.WithPassword("pass1"),
)
defer func() {
if err := testcontainers.TerminateContainer(databendContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
state, err := databendContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
Output: true
Example (Connect) ¶
ctx := context.Background()
databendContainer, err := databend.Run(ctx,
"datafuselabs/databend:v1.2.615",
databend.WithUsername("root"),
databend.WithPassword("password"),
)
defer func() {
if err := testcontainers.TerminateContainer(databendContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
connectionString, err := databendContainer.ConnectionString(ctx, "sslmode=disable")
if err != nil {
log.Printf("failed to get connection string: %s", err)
return
}
db, err := sql.Open("databend", connectionString)
if err != nil {
log.Printf("failed to connect to Databend: %s", err)
return
}
defer db.Close()
var i int
row := db.QueryRow("select 1")
err = row.Scan(&i)
if err != nil {
log.Printf("failed to scan result: %s", err)
return
}
fmt.Println(i)
Output: 1
func (*DatabendContainer) ConnectionString ¶
func (*DatabendContainer) MustConnectionString ¶
func (c *DatabendContainer) MustConnectionString(ctx context.Context, args ...string) string
MustConnectionString panics if the address cannot be determined.
type DatabendOption
deprecated
type DatabendOption func(*DatabendContainer)
Deprecated: use testcontainers.ContainerCustomizer instead DatabendOption is an option for the Databend container.
func (DatabendOption) Customize
deprecated
func (o DatabendOption) Customize(*testcontainers.GenericContainerRequest) error
Deprecated: use testcontainers.ContainerCustomizer instead Customize is a NOOP. It's defined to satisfy the testcontainers.ContainerCustomizer interface.