dockertest

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

README

dockertest

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.PostgresWithDockerNetwork(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.SpiceDBWithDockerNetwork(network),
)

if err := dockertest.MigrateSpiceDB(connString,
    dockertest.MigrateSpiceDBWithDockerPool(pool),
    dockertest.MigrateSpiceDBWithDockerNetwork(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 NewPool = dockertest.NewPool

Functions

func CortexWithAlertmanagerURL

func CortexWithAlertmanagerURL(amURL string) dockerCortexOption

CortexWithAlertmanagerURL is an option to assign alertmanager url

func CortexWithDockerNetwork

func CortexWithDockerNetwork(network *docker.Network) dockerCortexOption

CortexWithDockerNetwork is an option to assign docker network

func CortexWithDockerPool

func CortexWithDockerPool(pool *dockertest.Pool) dockerCortexOption

CortexWithDockerPool is an option to assign docker pool

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

CortexWithDockerNetwork 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 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 MigrateMinio

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

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

func MigrateMinioWithDockerNetwork

func MigrateMinioWithDockerNetwork(network *docker.Network) dockerMigrateMinioOption

MigrateMinioWithDockerNetwork is an option to assign docker network

func MigrateMinioWithDockerPool

func MigrateMinioWithDockerPool(pool *dockertest.Pool) dockerMigrateMinioOption

MigrateMinioWithDockerPool is an option to assign docker pool

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 MigrateSpiceDBWithDockerNetwork

func MigrateSpiceDBWithDockerNetwork(network *docker.Network) dockerMigrateSpiceDBOption

MigrateSpiceDBWithDockerNetwork is an option to assign docker network

func MigrateSpiceDBWithDockerPool

func MigrateSpiceDBWithDockerPool(pool *dockertest.Pool) dockerMigrateSpiceDBOption

MigrateSpiceDBWithDockerPool is an option to assign docker pool

func MigrateSpiceDBWithVersionTag

func MigrateSpiceDBWithVersionTag(versionTag string) dockerMigrateSpiceDBOption

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

func MinioWithDockerNetwork

func MinioWithDockerNetwork(network *docker.Network) dockerMinioOption

MinioWithDockerNetwork is an option to assign docker network

func MinioWithDockerPool

func MinioWithDockerPool(pool *dockertest.Pool) dockerMinioOption

MinioWithDockerPool is an option to assign docker pool

func MinioWithVersionTag

func MinioWithVersionTag(versionTag string) dockerMinioOption

MinioWithVersionTag is an option to assign version tag of a `quay.io/minio/minio` 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 PostgresWithDockerNetwork

func PostgresWithDockerNetwork(network *docker.Network) dockerPostgresOption

PostgresWithDockerNetwork is an option to assign docker network

func PostgresWithDockerPool

func PostgresWithDockerPool(pool *dockertest.Pool) dockerPostgresOption

PostgresWithDockerPool is an option to assign docker pool

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 SpiceDBWithDockerNetwork

func SpiceDBWithDockerNetwork(network *docker.Network) dockerSpiceDBOption

SpiceDBWithDockerNetwork is an option to assign docker network

func SpiceDBWithDockerPool

func SpiceDBWithDockerPool(pool *dockertest.Pool) dockerSpiceDBOption

SpiceDBWithDockerPool is an option to assign docker pool

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

type Pool

type Pool = dockertest.Pool

type and function aliasing to avoid conflicting dockertest name

type Resource

type Resource = dockertest.Resource

Jump to

Keyboard shortcuts

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