2024-03-27 02:59:28 +00:00
|
|
|
module Test.Main where
|
|
|
|
|
|
|
|
import Prelude
|
|
|
|
|
2024-03-27 20:26:40 +00:00
|
|
|
import Control.Alternative (guard)
|
|
|
|
import Control.Monad.Rec.Class (untilJust)
|
|
|
|
import Data.Either (Either(..), hush)
|
|
|
|
import Data.Filterable (filter)
|
|
|
|
import Data.Maybe (Maybe(..), isNothing, maybe)
|
|
|
|
import Data.Newtype (wrap)
|
|
|
|
import Data.String as String
|
|
|
|
import Effect (Effect, untilE)
|
|
|
|
import Effect.Aff (Aff, bracket, delay, launchAff_, makeAff)
|
|
|
|
import Effect.Class (liftEffect)
|
|
|
|
import Effect.Console (log)
|
|
|
|
import Node.Buffer as Buffer
|
|
|
|
import Node.ChildProcess (ChildProcess)
|
|
|
|
import Node.ChildProcess as ChildProcess
|
|
|
|
import Node.ChildProcess.Aff as ChildProcess.Aff
|
|
|
|
import Node.ChildProcess.Types (Exit(..), stringSignal)
|
|
|
|
import Node.Encoding (Encoding(..))
|
|
|
|
import Node.EventEmitter as Event
|
2024-04-01 20:03:17 +00:00
|
|
|
import Test.Control.Monad.Postgres as Test.Control.Monad.Postgres
|
2024-03-27 02:59:28 +00:00
|
|
|
import Test.Data.Postgres as Test.Data.Postgres
|
2024-04-02 20:58:34 +00:00
|
|
|
import Test.Data.Postgres.Custom as Test.Data.Postgres.Custom
|
2024-06-14 21:09:59 +00:00
|
|
|
import Test.Data.Postgres.Interval as Test.Data.Postgres.Interval
|
2024-03-27 20:26:40 +00:00
|
|
|
import Test.Effect.Postgres.Client as Test.Effect.Postgres.Client
|
2024-06-29 19:42:47 +00:00
|
|
|
import Test.Effect.Postgres.Error as Test.Effect.Postgres.Error
|
2024-04-01 18:46:33 +00:00
|
|
|
import Test.Effect.Postgres.Pool as Test.Effect.Postgres.Pool
|
2024-03-27 20:26:40 +00:00
|
|
|
import Test.Spec.Reporter (specReporter)
|
2024-03-27 02:59:28 +00:00
|
|
|
import Test.Spec.Runner (runSpec)
|
|
|
|
|
2024-03-27 20:26:40 +00:00
|
|
|
spawnDb :: Aff ChildProcess
|
|
|
|
spawnDb =
|
|
|
|
let
|
|
|
|
isReady = do
|
|
|
|
{ exitStatus, error } <- liftEffect (ChildProcess.spawnSync "docker" [ "compose", "exec", "db", "pg_isready" ])
|
|
|
|
let
|
|
|
|
exitOk (Normally 0) = true
|
|
|
|
exitOk _ = false
|
|
|
|
pure $ isNothing error && exitOk exitStatus
|
|
|
|
waitReady =
|
|
|
|
void $ untilJust do
|
|
|
|
delay $ wrap $ 100.0
|
|
|
|
isReady' <- isReady
|
|
|
|
pure $ filter (const isReady') (Just unit)
|
|
|
|
in
|
|
|
|
do
|
|
|
|
liftEffect $ log $ "[db] starting..."
|
|
|
|
db <- liftEffect $ ChildProcess.spawn "docker" [ "compose", "up" ]
|
|
|
|
waitReady
|
|
|
|
liftEffect $ log $ "[db] started!"
|
|
|
|
pure db
|
|
|
|
|
|
|
|
killDb :: ChildProcess -> Aff Unit
|
|
|
|
killDb db = do
|
|
|
|
let
|
|
|
|
onexit eff = Event.on ChildProcess.exitH eff db
|
|
|
|
exit = makeAff \res -> mempty <$ onexit (const $ res $ Right unit)
|
|
|
|
_ <- liftEffect $ ChildProcess.kill' (stringSignal "SIGTERM") db
|
|
|
|
exit
|
|
|
|
|
2024-03-27 02:59:28 +00:00
|
|
|
main :: Effect Unit
|
2024-03-27 20:26:40 +00:00
|
|
|
main = launchAff_ do
|
|
|
|
bracket spawnDb killDb
|
|
|
|
$ const
|
|
|
|
$ runSpec [ specReporter ] do
|
2024-06-29 19:42:47 +00:00
|
|
|
Test.Effect.Postgres.Error.spec
|
2024-04-02 20:58:34 +00:00
|
|
|
Test.Data.Postgres.Custom.spec
|
2024-03-27 20:26:40 +00:00
|
|
|
Test.Data.Postgres.spec
|
2024-06-14 21:09:59 +00:00
|
|
|
Test.Data.Postgres.Interval.spec
|
2024-03-27 20:26:40 +00:00
|
|
|
Test.Effect.Postgres.Client.spec
|
2024-04-01 18:46:33 +00:00
|
|
|
Test.Effect.Postgres.Pool.spec
|
2024-04-01 20:03:17 +00:00
|
|
|
Test.Control.Monad.Postgres.spec
|