dolt

package module
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

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

func WithDefaultCredentials() testcontainers.CustomizeRequestOption

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

Run creates an instance of the Dolt container type

Example
package main

import (
	"context"
	"fmt"
	"log"
	"path/filepath"

	"github.com/testcontainers/testcontainers-go/modules/dolt"
)

func main() {
	// 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")),
	)
	if err != nil {
		log.Fatalf("failed to run dolt container: %s", err) // nolint:gocritic
	}

	// Clean up the container
	defer func() {
		if err := doltContainer.Terminate(ctx); err != nil {
			log.Fatalf("failed to terminate dolt container: %s", err) // nolint:gocritic
		}
	}()
	// }

	state, err := doltContainer.State(ctx)
	if err != nil {
		log.Fatalf("failed to get container state: %s", err) // nolint:gocritic
	}

	fmt.Println(state.Running)

}
Output:
true
Example (Connect)
package main

import (
	"context"
	"database/sql"
	"fmt"
	"log"
	"path/filepath"

	"github.com/testcontainers/testcontainers-go/modules/dolt"
)

func main() {
	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")),
	)
	if err != nil {
		log.Fatalf("failed to run dolt container: %s", err) // nolint:gocritic
	}

	defer func() {
		if err := doltContainer.Terminate(ctx); err != nil {
			log.Fatalf("failed to terminate dolt container: %s", err) // nolint:gocritic
		}
	}()

	connectionString := doltContainer.MustConnectionString(ctx)

	db, err := sql.Open("mysql", connectionString)
	if err != nil {
		log.Fatalf("failed to open database connection: %s", err) // nolint:gocritic
	}
	defer db.Close()

	if err = db.Ping(); err != nil {
		log.Fatalf("failed to ping database: %s", err) // nolint:gocritic
	}
	stmt, err := db.Prepare("SELECT dolt_version();")
	if err != nil {
		log.Fatalf("failed to prepate sql statement: %s", err) // nolint:gocritic
	}
	defer stmt.Close()
	row := stmt.QueryRow()
	version := ""
	err = row.Scan(&version)
	if err != nil {
		log.Fatalf("failed to scan row: %s", err) // nolint:gocritic
	}

	fmt.Println(version)

}
Output:
1.32.4

func RunContainer deprecated

Deprecated: use Run instead RunContainer creates an instance of the Couchbase container type

func (*DoltContainer) ConnectionString

func (c *DoltContainer) ConnectionString(ctx context.Context, args ...string) (string, error)

func (*DoltContainer) MustConnectionString

func (c *DoltContainer) MustConnectionString(ctx context.Context, args ...string) string

Jump to

Keyboard shortcuts

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