dockertestx

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

README

dockertestx

This package is an abstraction of several dockerized data storages using ory/dockertest to bootstrap a specific dockerized instance.

Example postgres

// create postgres instance
pgDocker, err := dockertest.CreatePostgres(
    dockertest.PostgresWithDetail(
        pgUser, pgPass, pgDBName,
    ),
)

// get connection string
connString := pgDocker.GetExternalConnString()

// purge docker
if err := pgDocker.GetPool().Purge(pgDocker.GetResouce()); err != nil {
    return fmt.Errorf("could not purge resource: %w", err)
}

Example spice db

  • bootsrap spice db with postgres and wire them internally via network bridge
// create custom pool
pool, err := dockertest.NewPool("")
if err != nil {
    return nil, err
}

// create a bridge network for testing
network, err = pool.Client.CreateNetwork(docker.CreateNetworkOptions{
    Name: fmt.Sprintf("bridge-%s", uuid.New().String()),
})
if err != nil {
    return nil, err
}


// create postgres instance
pgDocker, err := dockertest.CreatePostgres(
    dockertest.PostgresWithDockerPool(pool),
    dockertest.PostgresWithDockertestNetwork(network),
    dockertest.PostgresWithDetail(
        pgUser, pgPass, pgDBName,
    ),
)

// get connection string
connString := pgDocker.GetInternalConnString()

// create spice db instance
spiceDocker, err := dockertest.CreateSpiceDB(connString,
    dockertest.SpiceDBWithDockerPool(pool),
    dockertest.SpiceDBWithDockertestNetwork(network),
)

if err := dockertest.MigrateSpiceDB(connString,
    dockertest.MigrateSpiceDBWithDockerPool(pool),
    dockertest.MigrateSpiceDBWithDockertestNetwork(network),
); err != nil {
    return err
}

// purge docker resources
if err := pool.Purge(spiceDocker.GetResouce()); err != nil {
    return fmt.Errorf("could not purge resource: %w", err)
}
if err := pool.Purge(pgDocker.GetResouce()); err != nil {
    return fmt.Errorf("could not purge resource: %w", err)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//go:embed configs/nginx/cortex_nginx.conf
	NginxCortexConfig string
)

Functions

func CortexWithAlertmanagerURL

func CortexWithAlertmanagerURL(amURL string) dockerCortexOption

CortexWithAlertmanagerURL is an option to assign alertmanager url

func CortexWithDockerPool

func CortexWithDockerPool(pool *dockertest.Pool) dockerCortexOption

CortexWithDockerPool is an option to assign docker pool

func CortexWithDockertestNetwork

func CortexWithDockertestNetwork(network *dockertest.Network) dockerCortexOption

CortexWithDockertestNetwork is an option to assign docker network

func CortexWithModule

func CortexWithModule(moduleName string) dockerCortexOption

CortexWithModule is an option to assign cortex module name e.g. all, alertmanager, querier, etc

func CortexWithS3Endpoint

func CortexWithS3Endpoint(s3URL string) dockerCortexOption

CortexWithS3Endpoint is an option to assign external s3/minio storage

func CortexWithVersionTag

func CortexWithVersionTag(versionTag string) dockerCortexOption

CortexWithDockertestNetwork is an option to assign version tag of a `quay.io/cortexproject/cortex` image

func CreateCortex

func CreateCortex(opts ...dockerCortexOption) (*dockerCortex, error)

CreateCortex is a function to create a dockerized single-process cortex with s3/minio as the backend storage

func CreateMinio

func CreateMinio(opts ...dockerMinioOption) (*dockerMinio, error)

CreateMinio creates a minio instance with default configurations

func CreateNginx

func CreateNginx(opts ...dockerNginxOption) (*dockerNginx, error)

CreateNginx is a function to create a dockerized nginx

func CreatePostgres

func CreatePostgres(opts ...dockerPostgresOption) (*dockerPostgres, error)

CreatePostgres creates a postgres instance with default configurations

func CreateSpiceDB

func CreateSpiceDB(postgresConnectionURL string, opts ...dockerSpiceDBOption) (*dockerSpiceDB, error)

CreateSpiceDB creates a spicedb instance with postgres backend and default configurations

func DockerHostAddress

func DockerHostAddress() string

func MigrateMinio

func MigrateMinio(minioHost string, bucketName string, opts ...dockerMigrateMinioOption) error

MigrateMinio does migration of a `bucketName` to a minio located in `minioHost`

func MigrateMinioWithDockerPool

func MigrateMinioWithDockerPool(pool *dockertest.Pool) dockerMigrateMinioOption

MigrateMinioWithDockerPool is an option to assign docker pool

func MigrateMinioWithDockertestNetwork

func MigrateMinioWithDockertestNetwork(network *dockertest.Network) dockerMigrateMinioOption

MigrateMinioWithDockertestNetwork is an option to assign docker network

func MigrateMinioWithVersionTag

func MigrateMinioWithVersionTag(versionTag string) dockerMigrateMinioOption

MigrateMinioWithVersionTag is an option to assign version tag of a `minio/mc` image

func MigrateSpiceDB

func MigrateSpiceDB(postgresConnectionURL string, opts ...dockerMigrateMinioOption) error

MigrateSpiceDB migrates spicedb with postgres backend

func MigrateSpiceDBWithDockerPool

func MigrateSpiceDBWithDockerPool(pool *dockertest.Pool) dockerMigrateSpiceDBOption

MigrateSpiceDBWithDockerPool is an option to assign docker pool

func MigrateSpiceDBWithDockertestNetwork

func MigrateSpiceDBWithDockertestNetwork(network *dockertest.Network) dockerMigrateSpiceDBOption

MigrateSpiceDBWithDockertestNetwork is an option to assign docker network

func MigrateSpiceDBWithVersionTag

func MigrateSpiceDBWithVersionTag(versionTag string) dockerMigrateSpiceDBOption

MigrateSpiceDBWithVersionTag is an option to assign version tag of a `quay.io/authzed/spicedb` image

func MinioWithDockerPool

func MinioWithDockerPool(pool *dockertest.Pool) dockerMinioOption

MinioWithDockerPool is an option to assign docker pool

func MinioWithDockertestNetwork

func MinioWithDockertestNetwork(network *dockertest.Network) dockerMinioOption

MinioWithDockertestNetwork is an option to assign docker network

func MinioWithVersionTag

func MinioWithVersionTag(versionTag string) dockerMinioOption

MinioWithVersionTag is an option to assign version tag of a `quay.io/minio/minio` image

func NginxWithConfigVariables

func NginxWithConfigVariables(cv map[string]string) dockerNginxOption

func NginxWithDockerPool

func NginxWithDockerPool(pool *dockertest.Pool) dockerNginxOption

NginxWithDockerPool is an option to assign docker pool

func NginxWithDockertestNetwork

func NginxWithDockertestNetwork(network *dockertest.Network) dockerNginxOption

NginxWithDockertestNetwork is an option to assign docker network

func NginxWithExposedPort

func NginxWithExposedPort(port string) dockerNginxOption

NginxWithDockerPool is an option to assign docker pool

func NginxWithHealthEndpoint

func NginxWithHealthEndpoint(healthEndpoint string) dockerNginxOption

NginxWithHealthEndpoint is an option to assign health endpoint

func NginxWithPresetConfig

func NginxWithPresetConfig(presetConfig string) dockerNginxOption

func NginxWithVersionTag

func NginxWithVersionTag(versionTag string) dockerNginxOption

NginxWithVersionTag is an option to assign version tag of a `nginx` image

func PostgresWithDetail

func PostgresWithDetail(
	username string,
	password string,
	dbName string,
) dockerPostgresOption

PostgresWithDetail is an option to assign custom details like username, password, and database name

func PostgresWithDockerPool

func PostgresWithDockerPool(pool *dockertest.Pool) dockerPostgresOption

PostgresWithDockerPool is an option to assign docker pool

func PostgresWithDockertestNetwork

func PostgresWithDockertestNetwork(network *dockertest.Network) dockerPostgresOption

PostgresWithDockertestNetwork is an option to assign docker network

func PostgresWithDockertestResourceExpiry

func PostgresWithDockertestResourceExpiry(expiryInSeconds uint) dockerPostgresOption

PostgresWithDockertestResourceExpiry is an option to assign docker resource expiry time

func PostgresWithLogger

func PostgresWithLogger(logger log.Logger) dockerPostgresOption

func PostgresWithVersionTag

func PostgresWithVersionTag(versionTag string) dockerPostgresOption

PostgresWithVersionTag is an option to assign version tag of a `postgres` image

func SpiceDBWithDockerPool

func SpiceDBWithDockerPool(pool *dockertest.Pool) dockerSpiceDBOption

SpiceDBWithDockerPool is an option to assign docker pool

func SpiceDBWithDockertestNetwork

func SpiceDBWithDockertestNetwork(network *dockertest.Network) dockerSpiceDBOption

SpiceDBWithDockertestNetwork is an option to assign docker network

func SpiceDBWithLogLevel

func SpiceDBWithLogLevel(logLevel string) dockerSpiceDBOption

func SpiceDBWithPreSharedKey

func SpiceDBWithPreSharedKey(preSharedKey string) dockerSpiceDBOption

SpiceDBWithPreSharedKey is an option to assign pre-shared-key

func SpiceDBWithVersionTag

func SpiceDBWithVersionTag(versionTag string) dockerSpiceDBOption

SpiceDBWithVersionTag is an option to assign version tag of a `quay.io/authzed/spicedb` image

Types

This section is empty.

Jump to

Keyboard shortcuts

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