embeddedpostgres

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 28 Imported by: 0

README

embedded-postgres-test

Documentation

Index

Constants

View Source
const (
	V14 = PostgresVersion("14.5.0")
	V13 = PostgresVersion("13.8.0")
	V12 = PostgresVersion("12.12.0")
	V11 = PostgresVersion("11.17.0")
	V10 = PostgresVersion("10.22.0")
	V9  = PostgresVersion("9.6.24")
)

Predefined supported Postgres versions

Variables

View Source
var ErrPortNotAvailable = errors.New("port not available")

Functions

func Config

func Config(opts ...opt) *config

func WithDatabase

func WithDatabase(database string) opt

func WithLocale

func WithLocale(locale string) opt

WithLocale sets the default locale for initdb

func WithLogger added in v0.2.0

func WithLogger(logger *zap.Logger) opt

func WithPGConfig added in v0.2.0

func WithPGConfig(conf map[string]string) opt

func WithPGLogger

func WithPGLogger(logger io.Writer) opt

WithLogger sets the logger for postgres output

func WithPort

func WithPort(port uint32) opt

func WithRepository

func WithRepository(url string) opt

WithRepository sets BinaryRepositoryURL to fetch PG Binary in case of Maven proxy

func WithRuntimePath

func WithRuntimePath(path string) opt

func WithStartTimeout

func WithStartTimeout(d time.Duration) opt

func WithVersion

func WithVersion(version PostgresVersion) opt

WithVersion will set the Postgres binary version

Types

type CacheLocator

type CacheLocator func() (location string, exists bool)

CacheLocator retrieves the location of the Postgres binary cache returning it to location. The result of whether this cache is present will be returned to exists.

type EmbeddedPostgres

type EmbeddedPostgres struct {
	// contains filtered or unexported fields
}

EmbeddedPostgres maintains all configuration and runtime functions for maintaining the lifecycle of one Postgres process.

func NewDatabase

func NewDatabase(config ...*config) *EmbeddedPostgres

NewDatabase creates a new EmbeddedPostgres struct that can be used to start and stop a Postgres process. When called with no parameters it will assume a default configuration state provided by the DefaultConfig method. When called with parameters the first Config parameter will be used for configuration.

func (*EmbeddedPostgres) Connect

func (ep *EmbeddedPostgres) Connect(ctx context.Context) (*pgxpool.Pool, error)

func (*EmbeddedPostgres) ConnectionString

func (ep *EmbeddedPostgres) ConnectionString() string

func (*EmbeddedPostgres) Ping

func (ep *EmbeddedPostgres) Ping(ctx context.Context) error

func (*EmbeddedPostgres) RecoverStop

func (ep *EmbeddedPostgres) RecoverStop(ctx context.Context)

RecoverStop returns a deferrable function that will teardown in the event of a panic.

func (*EmbeddedPostgres) Start

func (ep *EmbeddedPostgres) Start(ctx context.Context) error

Start will try to start the configured Postgres process returning an error when there were any problems with invocation. If any error occurs Start will try to also Stop the Postgres process in order to not leave any sub-process running.

func (*EmbeddedPostgres) Stop

func (ep *EmbeddedPostgres) Stop(_ context.Context) error

Stop will try to stop the Postgres process gracefully returning an error when there were any problems.

func (*EmbeddedPostgres) URL

func (ep *EmbeddedPostgres) URL() string

type PostgresVersion

type PostgresVersion string

PostgresVersion represents the semantic version used to fetch and run the Postgres process

type RemoteFetchStrategy

type RemoteFetchStrategy func() error

RemoteFetchStrategy provides a strategy to fetch a Postgres binary so that it is available for use.

type VersionStrategy

type VersionStrategy func() (operatingSystem string, architecture string, postgresVersion PostgresVersion)

VersionStrategy provides a strategy that can be used to determine which version of Postgres should be used based on the operating system, architecture and desired Postgres version.

Jump to

Keyboard shortcuts

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