sandwich-contexts-0.3.0.2: Contexts for the Sandwich test library
Safe HaskellNone
LanguageHaskell2010

Test.Sandwich.Contexts.PostgreSQL

Description

This module provides tools for introducing PostgreSQL databases, either via a container (Docker or Podman) or via a raw process (typically obtaining the binary from Nix).

The container method is traditional, but the raw method can be nice because it tends to leave less junk on the system such as container images, networks, and volumes.

A note about raw processes and random TCP ports: starting a Postgres process on a randomly chosen port is tricky, because Postgres currently lacks a setting for choosing its own port and reporting it back to us. So, the only way to start it on a random TCP port is to first manually find a free port on the system and then start Postgres with it. Since this procedure is inherently racy, it can cause failures if your tests are starting lots of Postgres instances (or other network-using processes) in parallel. This module takes a different approach: it starts the Postgres instance on a Unix socket, which can never fail. You can connect to it via the Unix socket directly if you like. If you use the TCP-based methods like introducePostgresViaNix, they will open a TCP socket inside the test process and then run a proxy to forward packets to the Postgres server's Unix socket.

Synopsis

Raw PostgreSQL via Nix (TCP socket)

introducePostgresViaNix Source #

Arguments

:: forall context (m :: Type -> Type). (HasBaseContext context, HasNixContext context, MonadUnliftIO m, MonadMask m) 
=> PostgresNixOptions

Options

-> SpecFree (LabelValue "postgres" PostgresContext :> context) m () 
-> SpecFree context m () 

Introduce a PostgreSQL instance, using a suitable package from Nix.

withPostgresViaNix Source #

Arguments

:: (HasBaseContextMonad context m, HasNixContext context, MonadUnliftIO m, MonadMask m, MonadFail m, MonadLogger m) 
=> PostgresNixOptions

Options

-> (PostgresContext -> m a) 
-> m a 

Bracket-style variant of introducePostgresViaNix.

withPostgresViaNix' Source #

Arguments

:: (HasBaseContextMonad context m, MonadUnliftIO m, MonadMask m, MonadFail m, MonadLogger m) 
=> NixContext

Nix context

-> PostgresNixOptions

Options

-> (PostgresContext -> m a) 
-> m a 

Lower-level variant of withPostgresViaNix.

Raw PostgreSQL via Nix (Unix socket)

introducePostgresUnixSocketViaNix Source #

Arguments

:: forall context (m :: Type -> Type). (HasBaseContext context, HasNixContext context, MonadUnliftIO m, MonadMask m) 
=> PostgresNixOptions

Options

-> SpecFree (LabelValue "postgres" PostgresContext :> context) m () 
-> SpecFree context m () 

Same as introducePostgresViaNix, but the postgresAddress of the PostgresContext will be a Unix socket.

withPostgresUnixSocketViaNix Source #

Arguments

:: (HasBaseContextMonad context m, HasNixContext context, MonadUnliftIO m, MonadFail m, MonadMask m, MonadLogger m) 
=> PostgresNixOptions

Options

-> (FilePath -> m a) 
-> m a 

Bracket-style variant of introducePostgresUnixSocketViaNix.

withPostgresUnixSocketViaNix' Source #

Arguments

:: (HasBaseContextMonad context m, MonadUnliftIO m, MonadFail m, MonadMask m, MonadLogger m) 
=> NixContext

Options

-> PostgresNixOptions 
-> (FilePath -> m a) 
-> m a 

Lower-level variant of withPostgresUnixSocket.

Containerized PostgreSQL

introducePostgresViaContainer Source #

Arguments

:: forall context (m :: Type -> Type). (HasBaseContext context, MonadUnliftIO m, MonadMask m) 
=> PostgresContainerOptions

Options

-> SpecFree (LabelValue "postgres" PostgresContext :> context) m () 
-> SpecFree context m () 

Introduce a PostgresSQL instance via a container (either Docker or Podman).

Types

data PostgresNixOptions Source #

Constructors

PostgresNixOptions 

Fields

data PostgresContext Source #

Constructors

PostgresContext 

Fields

Instances

Instances details
Show PostgresContext Source # 
Instance details

Defined in Test.Sandwich.Contexts.PostgreSQL

Re-exports