Predefined supported Postgres versions.
const ( V15 = PostgresVersion("15.3.0") V14 = PostgresVersion("14.8.0") V13 = PostgresVersion("13.11.0") V12 = PostgresVersion("12.15.0") V11 = PostgresVersion("11.20.0") V10 = PostgresVersion("10.23.0") V9 = PostgresVersion("9.6.24") )
func TestGetConnectionURL(t *testing.T)
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 CacheLocator func() (location string, exists bool)
Config maintains the runtime configuration for the Postgres process to be created.
type Config struct {
// contains filtered or unexported fields
}
func DefaultConfig() Config
DefaultConfig provides a default set of configuration to be used "as is" or modified using the provided builders. The following can be assumed as defaults: Version: 14 Port: 5432 Database: postgres Username: postgres Password: postgres StartTimeout: 15 Seconds
func (c Config) BinariesPath(path string) Config
BinariesPath sets the path of the pre-downloaded postgres binaries. If this option is left unset, the binaries will be downloaded.
func (c Config) BinaryRepositoryURL(binaryRepositoryURL string) Config
BinaryRepositoryURL set BinaryRepositoryURL to fetch PG Binary in case of Maven proxy
func (c Config) CachePath(path string) Config
CachePath sets the path that will be used for storing Postgres binaries archive. If this option is not set, ~/.go-embedded-postgres will be used.
func (c Config) DataPath(path string) Config
DataPath sets the path that will be used for the Postgres data directory. If this option is set, a previously initialized data directory will be reused if possible.
func (c Config) Database(database string) Config
Database sets the database name that will be created.
func (c Config) GetConnectionURL() string
func (c Config) Locale(locale string) Config
Locale sets the default locale for initdb
func (c Config) Logger(logger io.Writer) Config
Logger sets the logger for postgres output
func (c Config) Password(password string) Config
Password sets the password that will be used to connect.
func (c Config) Port(port uint32) Config
Port sets the runtime port that Postgres can be accessed on.
func (c Config) RuntimePath(path string) Config
RuntimePath sets the path that will be used for the extracted Postgres runtime directory. If Postgres data directory is not set with DataPath(), this directory is also used as data directory.
func (c Config) StartParameters(parameters map[string]string) Config
StartParameters sets run-time parameters when starting Postgres (passed to Postgres via "-c").
These parameters can be used to override the default configuration values in postgres.conf such as max_connections=100. See https://www.postgresql.org/docs/current/runtime-config.html
func (c Config) StartTimeout(timeout time.Duration) Config
StartTimeout sets the max timeout that will be used when starting the Postgres process and creating the initial database.
func (c Config) Username(username string) Config
Username sets the username that will be used to connect.
func (c Config) Version(version PostgresVersion) Config
Version will set the Postgres binary version.
EmbeddedPostgres maintains all configuration and runtime functions for maintaining the lifecycle of one Postgres process.
type EmbeddedPostgres struct {
// contains filtered or unexported fields
}
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 (ep *EmbeddedPostgres) Start() 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 (ep *EmbeddedPostgres) Stop() error
Stop will try to stop the Postgres process gracefully returning an error when there were any problems.
PostgresVersion represents the semantic version used to fetch and run the Postgres process.
type PostgresVersion string
RemoteFetchStrategy provides a strategy to fetch a Postgres binary so that it is available for use.
type RemoteFetchStrategy func() error
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.
type VersionStrategy func() (operatingSystem string, architecture string, postgresVersion PostgresVersion)