Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- introducePostgresViaNix :: forall context (m :: Type -> Type). (HasBaseContext context, HasNixContext context, MonadUnliftIO m, MonadMask m) => PostgresNixOptions -> SpecFree (LabelValue "postgres" PostgresContext :> context) m () -> SpecFree context m ()
- withPostgresViaNix :: (HasBaseContextMonad context m, HasNixContext context, MonadUnliftIO m, MonadMask m, MonadFail m, MonadLogger m) => PostgresNixOptions -> (PostgresContext -> m a) -> m a
- withPostgresViaNix' :: (HasBaseContextMonad context m, MonadUnliftIO m, MonadMask m, MonadFail m, MonadLogger m) => NixContext -> PostgresNixOptions -> (PostgresContext -> m a) -> m a
- introducePostgresUnixSocketViaNix :: forall context (m :: Type -> Type). (HasBaseContext context, HasNixContext context, MonadUnliftIO m, MonadMask m) => PostgresNixOptions -> SpecFree (LabelValue "postgres" PostgresContext :> context) m () -> SpecFree context m ()
- withPostgresUnixSocketViaNix :: (HasBaseContextMonad context m, HasNixContext context, MonadUnliftIO m, MonadFail m, MonadMask m, MonadLogger m) => PostgresNixOptions -> (FilePath -> m a) -> m a
- withPostgresUnixSocketViaNix' :: (HasBaseContextMonad context m, MonadUnliftIO m, MonadFail m, MonadMask m, MonadLogger m) => NixContext -> PostgresNixOptions -> (FilePath -> m a) -> m a
- introducePostgresViaContainer :: forall context (m :: Type -> Type). (HasBaseContext context, MonadUnliftIO m, MonadMask m) => PostgresContainerOptions -> SpecFree (LabelValue "postgres" PostgresContext :> context) m () -> SpecFree context m ()
- withPostgresContainer :: (HasCallStack, MonadUnliftIO m, MonadLoggerIO m, MonadMask m, HasBaseContextMonad context m) => PostgresContainerOptions -> (PostgresContext -> m a) -> m a
- data PostgresNixOptions = PostgresNixOptions {}
- defaultPostgresNixOptions :: PostgresNixOptions
- postgres :: Label "postgres" PostgresContext
- data PostgresContext = PostgresContext {}
- data PostgresContainerOptions = PostgresContainerOptions {}
- defaultPostgresContainerOptions :: PostgresContainerOptions
- data NetworkAddress
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.
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
.
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).
withPostgresContainer Source #
Arguments
:: (HasCallStack, MonadUnliftIO m, MonadLoggerIO m, MonadMask m, HasBaseContextMonad context m) | |
=> PostgresContainerOptions | Options |
-> (PostgresContext -> m a) | |
-> m a |
Bracket-style variant of introducePostgresViaContainer
.
Types
data PostgresNixOptions Source #
Constructors
PostgresNixOptions | |
Fields
|
postgres :: Label "postgres" PostgresContext Source #
data PostgresContext Source #
Constructors
PostgresContext | |
Fields
|
Instances
Show PostgresContext Source # | |
Defined in Test.Sandwich.Contexts.PostgreSQL Methods showsPrec :: Int -> PostgresContext -> ShowS # show :: PostgresContext -> String # showList :: [PostgresContext] -> ShowS # |
data PostgresContainerOptions Source #
Constructors
PostgresContainerOptions | |
Instances
Show PostgresContainerOptions Source # | |
Defined in Test.Sandwich.Contexts.PostgreSQL Methods showsPrec :: Int -> PostgresContainerOptions -> ShowS # show :: PostgresContainerOptions -> String # showList :: [PostgresContainerOptions] -> ShowS # | |
Eq PostgresContainerOptions Source # | |
Defined in Test.Sandwich.Contexts.PostgreSQL Methods (==) :: PostgresContainerOptions -> PostgresContainerOptions -> Bool # (/=) :: PostgresContainerOptions -> PostgresContainerOptions -> Bool # |
Re-exports
data NetworkAddress Source #
Constructors
NetworkAddressTCP | |
NetworkAddressUnix | |
Fields |
Instances
Show NetworkAddress Source # | |
Defined in Test.Sandwich.Contexts.Types.Network Methods showsPrec :: Int -> NetworkAddress -> ShowS # show :: NetworkAddress -> String # showList :: [NetworkAddress] -> ShowS # | |
Eq NetworkAddress Source # | |
Defined in Test.Sandwich.Contexts.Types.Network Methods (==) :: NetworkAddress -> NetworkAddress -> Bool # (/=) :: NetworkAddress -> NetworkAddress -> Bool # |