Documentation
¶
Index ¶
- func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption
- func WithCredsFile(credsFile string) testcontainers.CustomizeRequestOption
- func WithDatabase(database string) testcontainers.CustomizeRequestOption
- func WithDefaultCredentials() testcontainers.CustomizeRequestOptiondeprecated
- func WithDoltCloneRemoteUrl(url string) testcontainers.CustomizeRequestOption
- func WithDoltCredsPublicKey(key string) testcontainers.CustomizeRequestOption
- func WithPassword(password string) testcontainers.CustomizeRequestOption
- func WithScripts(scripts ...string) testcontainers.CustomizeRequestOption
- func WithUsername(username string) testcontainers.CustomizeRequestOption
- type DoltContainer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithConfigFile ¶
func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption
func WithCredsFile ¶
func WithCredsFile(credsFile string) testcontainers.CustomizeRequestOption
func WithDatabase ¶
func WithDatabase(database string) testcontainers.CustomizeRequestOption
func WithDefaultCredentials
deprecated
func WithDefaultCredentials() testcontainers.CustomizeRequestOption
Deprecated: this function will be removed in the next major release.
func WithDoltCloneRemoteUrl ¶
func WithDoltCloneRemoteUrl(url string) testcontainers.CustomizeRequestOption
func WithDoltCredsPublicKey ¶
func WithDoltCredsPublicKey(key string) testcontainers.CustomizeRequestOption
func WithPassword ¶
func WithPassword(password string) testcontainers.CustomizeRequestOption
func WithScripts ¶
func WithScripts(scripts ...string) testcontainers.CustomizeRequestOption
func WithUsername ¶
func WithUsername(username string) testcontainers.CustomizeRequestOption
Types ¶
type DoltContainer ¶
type DoltContainer struct {
testcontainers.Container
// contains filtered or unexported fields
}
DoltContainer represents the Dolt container type used in the module
func Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*DoltContainer, error)
Run creates an instance of the Dolt container type
Example ¶
// runDoltContainer {
ctx := context.Background()
doltContainer, err := dolt.Run(ctx,
"dolthub/dolt-sql-server:1.32.4",
dolt.WithConfigFile(filepath.Join("testdata", "dolt_1_32_4.cnf")),
dolt.WithDatabase("foo"),
dolt.WithUsername("root"),
dolt.WithPassword("password"),
dolt.WithScripts(filepath.Join("testdata", "schema.sql")),
)
defer func() {
if err := testcontainers.TerminateContainer(doltContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to run dolt container: %s", err)
return
}
// }
state, err := doltContainer.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()
doltContainer, err := dolt.Run(ctx,
"dolthub/dolt-sql-server:1.32.4",
dolt.WithConfigFile(filepath.Join("testdata", "dolt_1_32_4.cnf")),
dolt.WithDatabase("foo"),
dolt.WithUsername("bar"),
dolt.WithPassword("password"),
dolt.WithScripts(filepath.Join("testdata", "schema.sql")),
)
defer func() {
if err := testcontainers.TerminateContainer(doltContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to run dolt container: %s", err)
return
}
connectionString := doltContainer.MustConnectionString(ctx)
db, err := sql.Open("mysql", connectionString)
if err != nil {
log.Printf("failed to open database connection: %s", err)
return
}
defer db.Close()
if err = db.Ping(); err != nil {
log.Printf("failed to ping database: %s", err)
return
}
stmt, err := db.Prepare("SELECT dolt_version();")
if err != nil {
log.Printf("failed to prepare sql statement: %s", err)
return
}
defer stmt.Close()
row := stmt.QueryRow()
version := ""
err = row.Scan(&version)
if err != nil {
log.Printf("failed to scan row: %s", err)
return
}
fmt.Println(version)
Output: 1.32.4
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*DoltContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the Couchbase container type
func (*DoltContainer) ConnectionString ¶
func (*DoltContainer) MustConnectionString ¶
func (c *DoltContainer) MustConnectionString(ctx context.Context, args ...string) string
Click to show internal directories.
Click to hide internal directories.