packages feed

testcontainers-postgresql (empty) → 0.0.1

raw patch · 7 files changed

+272/−0 lines, 7 filesdep +basedep +testcontainersdep +text

Dependencies added: base, testcontainers, text

Files

+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2025, Nikita Volkov++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,34 @@+# testcontainers-postgresql++[![Hackage](https://img.shields.io/hackage/v/testcontainers-postgresql.svg)](https://hackage.haskell.org/package/testcontainers-postgresql)+[![Continuous Haddock](https://img.shields.io/badge/haddock-master-blue)](https://nikita-volkov.github.io/testcontainers-postgresql/)++A Haskell library providing Testcontainers integration for PostgreSQL databases. This library simplifies running PostgreSQL containers for testing purposes, with support for various PostgreSQL versions and authentication methods.++## Features++- **Multiple PostgreSQL Versions**: Support for PostgreSQL versions 9 through 17+- **Flexible Authentication**: Choose between trust-based authentication or username/password credentials+- **Log Forwarding**: Optional log forwarding to the console for debugging++## Quick Start++```haskell+import TestcontainersPostgresql+import TestcontainersPostgresql.Configs.Config+import TestcontainersPostgresql.Configs.Distro+import TestcontainersPostgresql.Configs.Auth++main :: IO ()+main = do+  let config = Config+        { forwardLogs = True+        , distro = Distro16  -- PostgreSQL 16+        , auth = TrustAuth   -- Trust-based authentication+        }++  run config $ \(host, port) -> do+    putStrLn $ "PostgreSQL is running at " ++ show host ++ ":" ++ show port+    -- Your test code here+    -- Connect to PostgreSQL using host and port+```
+ src/library/TestcontainersPostgresql.hs view
@@ -0,0 +1,26 @@+module TestcontainersPostgresql+  ( Configs.Config.Config (..),+    Configs.Distro.Distro (..),+    Configs.Auth.Auth (..),+    run,+  )+where++import Data.Function+import Data.Text (Text)+import qualified TestContainers+import qualified TestContainers.Hspec+import qualified TestcontainersPostgresql.Configs.Auth as Configs.Auth+import qualified TestcontainersPostgresql.Configs.Config as Configs.Config+import qualified TestcontainersPostgresql.Configs.Distro as Configs.Distro+import Prelude++setup :: (TestContainers.MonadDocker m) => Configs.Config.Config -> m (Text, Int)+setup config = do+  container <- TestContainers.run (Configs.Config.toContainerRequest config)+  pure $ TestContainers.containerAddress container 5432++-- | Run a session on a PostgreSQL container on the scope of a host and a port.+run :: Configs.Config.Config -> ((Text, Int) -> IO ()) -> IO ()+run config = do+  TestContainers.Hspec.withContainers (setup config)
+ src/library/TestcontainersPostgresql/Configs/Auth.hs view
@@ -0,0 +1,24 @@+module TestcontainersPostgresql.Configs.Auth where++import Data.Function+import Data.Text (Text)+import qualified TestContainers+import Prelude++data Auth+  = TrustAuth+  | CredentialsAuth Text Text+  deriving stock (Show, Eq)++updateContainerRequest :: Auth -> TestContainers.ContainerRequest -> TestContainers.ContainerRequest+updateContainerRequest = TestContainers.setEnv . toEnvs++toEnvs :: Auth -> [(Text, Text)]+toEnvs = \case+  TrustAuth ->+    [ ("POSTGRES_HOST_AUTH_METHOD", "trust")+    ]+  CredentialsAuth user password ->+    [ ("POSTGRES_USER", user),+      ("POSTGRES_PASSWORD", password)+    ]
+ src/library/TestcontainersPostgresql/Configs/Config.hs view
@@ -0,0 +1,29 @@+module TestcontainersPostgresql.Configs.Config where++import Data.Function+import qualified Data.Text.Lazy as Text.Lazy+import qualified TestContainers+import qualified TestcontainersPostgresql.Configs.Auth as Configs.Auth+import qualified TestcontainersPostgresql.Configs.Distro as Configs.Distro+import Prelude++data Config = Config+  { forwardLogs :: Bool,+    distro :: Configs.Distro.Distro,+    auth :: Configs.Auth.Auth+  }++toContainerRequest :: Config -> TestContainers.ContainerRequest+toContainerRequest (Config forwardLogs distro auth) =+  Configs.Distro.toContainerRequest distro+    & TestContainers.setExpose [5432]+    & TestContainers.setWaitingFor waitUntilReady+    & Configs.Auth.updateContainerRequest auth+    & (if forwardLogs then TestContainers.withFollowLogs TestContainers.consoleLogConsumer else id)+  where+    waitUntilReady :: TestContainers.WaitUntilReady+    waitUntilReady =+      mconcat+        [ TestContainers.waitForLogLine TestContainers.Stderr (Text.Lazy.isInfixOf "database system is ready to accept connections"),+          TestContainers.waitUntilMappedPortReachable 5432+        ]
+ src/library/TestcontainersPostgresql/Configs/Distro.hs view
@@ -0,0 +1,36 @@+module TestcontainersPostgresql.Configs.Distro where++import Data.Function+import Data.Text (Text)+import qualified TestContainers+import Prelude++data Distro+  = Distro9+  | Distro10+  | Distro11+  | Distro12+  | Distro13+  | Distro14+  | Distro15+  | Distro16+  | Distro17+  deriving stock (Show, Eq)++toTag :: Distro -> Text+toTag = \case+  Distro9 -> "postgres:9"+  Distro10 -> "postgres:10"+  Distro11 -> "postgres:11"+  Distro12 -> "postgres:12"+  Distro13 -> "postgres:13"+  Distro14 -> "postgres:14"+  Distro15 -> "postgres:15"+  Distro16 -> "postgres:16"+  Distro17 -> "postgres:17"++toToImage :: Distro -> TestContainers.ToImage+toToImage = TestContainers.fromTag . toTag++toContainerRequest :: Distro -> TestContainers.ContainerRequest+toContainerRequest = TestContainers.containerRequest . toToImage
+ testcontainers-postgresql.cabal view
@@ -0,0 +1,101 @@+cabal-version: 3.0+name: testcontainers-postgresql+version: 0.0.1+category: PostgreSQL, Codecs+synopsis: Testcontainers integration for PostgreSQL+homepage: https://github.com/nikita-volkov/testcontainers-postgresql+bug-reports: https://github.com/nikita-volkov/testcontainers-postgresql/issues+author: Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer: Nikita Volkov <nikita.y.volkov@mail.ru>+copyright: (c) 2025, Nikita Volkov+license: MIT+license-file: LICENSE+extra-doc-files:+  LICENSE+  README.md++source-repository head+  type: git+  location: https://github.com/nikita-volkov/testcontainers-postgresql++common base+  default-language: Haskell2010+  default-extensions:+    ApplicativeDo+    BangPatterns+    BinaryLiterals+    BlockArguments+    ConstraintKinds+    DataKinds+    DefaultSignatures+    DeriveDataTypeable+    DeriveFoldable+    DeriveFunctor+    DeriveTraversable+    DerivingStrategies+    DerivingVia+    DuplicateRecordFields+    EmptyDataDecls+    FlexibleContexts+    FlexibleInstances+    FunctionalDependencies+    GADTs+    GeneralizedNewtypeDeriving+    LambdaCase+    LiberalTypeSynonyms+    MagicHash+    MultiParamTypeClasses+    MultiWayIf+    NamedFieldPuns+    NoFieldSelectors+    NoImplicitPrelude+    NoMonomorphismRestriction+    NumericUnderscores+    OverloadedRecordDot+    OverloadedStrings+    ParallelListComp+    PatternGuards+    QuasiQuotes+    RankNTypes+    RecordWildCards+    ScopedTypeVariables+    StandaloneDeriving+    StrictData+    TemplateHaskell+    TupleSections+    TypeApplications+    TypeFamilies+    TypeOperators+    UnboxedTuples+    ViewPatterns++common executable+  import: base+  ghc-options:+    -O2+    -threaded+    -with-rtsopts=-N+    -rtsopts+    -funbox-strict-fields++common test+  import: base+  ghc-options:+    -threaded+    -with-rtsopts=-N++library+  import: base+  hs-source-dirs: src/library+  exposed-modules:+    TestcontainersPostgresql++  other-modules:+    TestcontainersPostgresql.Configs.Auth+    TestcontainersPostgresql.Configs.Config+    TestcontainersPostgresql.Configs.Distro++  build-depends:+    base >=4.11 && <5,+    testcontainers ^>=0.5.1,+    text >=1.2 && <3,