Add tests

This commit is contained in:
rightfold 2017-05-06 17:09:05 +02:00
parent a1276bc057
commit 64c84351ec
No known key found for this signature in database
GPG Key ID: 199D0373AC917A8F
2 changed files with 54 additions and 0 deletions

View File

@ -19,5 +19,9 @@
"repository": {
"type": "git",
"url": "https://github.com/rightfold/purescript-postgresql-client.git"
},
"devDependencies": {
"purescript-assert": "^3.0.0",
"purescript-eff": "^3.1.0"
}
}

50
test/Main.purs Normal file
View File

@ -0,0 +1,50 @@
module Test.Main
( main
) where
import Control.Monad.Aff (launchAff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Exception (EXCEPTION)
import Data.Tuple.Nested ((/\))
import Database.PostgreSQL (POSTGRESQL, PoolConfiguration, Query(..), execute, newPool, query, withConnection)
import Prelude
import Test.Assert (ASSERT, assert)
main :: eff. Eff (assert :: ASSERT, exception :: EXCEPTION, postgreSQL :: POSTGRESQL | eff) Unit
main = void $ launchAff do
pool <- newPool config
withConnection pool \conn -> do
execute conn (Query """
CREATE TEMPORARY TABLE foods (
name text NOT NULL,
delicious boolean NOT NULL,
PRIMARY KEY (name)
)
""") unit
execute conn (Query """
INSERT INTO foods (name, delicious)
VALUES ($1, $2), ($3, $4), ($5, $6)
""") ("pork" /\ true /\ "sauerkraut" /\ false /\ "rookworst" /\ true /\ unit)
query conn (Query """
SELECT name
FROM foods
WHERE delicious
ORDER BY name ASC
""") unit
>>= liftEff <<< assert <<< (==) ["pork" /\ unit, "rookworst" /\ unit]
pure unit
config :: PoolConfiguration
config =
{ user: "postgres"
, password: "lol123"
, host: "127.0.0.1"
, port: 5432
, database: "purspg"
, max: 10
, idleTimeoutMillis: 1000
}