Tests a single insertion
This commit is contained in:
+11
-2
@@ -36,5 +36,14 @@ Test-Suite spec
|
|||||||
Hs-Source-Dirs: src , test
|
Hs-Source-Dirs: src , test
|
||||||
Ghc-Options: -Wall
|
Ghc-Options: -Wall
|
||||||
Main-Is: Spec.hs
|
Main-Is: Spec.hs
|
||||||
Build-Depends: base, hspec2, HDBC,
|
Build-Depends: base, hspec2
|
||||||
HDBC-postgresql
|
, HDBC, HDBC-postgresql
|
||||||
|
, warp, wai >= 3.0.1 && < 3.0.2
|
||||||
|
, http-types, scientific, time
|
||||||
|
, bytestring, aeson, network
|
||||||
|
, text, optparse-applicative
|
||||||
|
, unordered-containers
|
||||||
|
, regex-base
|
||||||
|
, http-media, regex-tdfa
|
||||||
|
, Ranged-sets
|
||||||
|
, transformers
|
||||||
|
|||||||
+14
-3
@@ -1,3 +1,5 @@
|
|||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module PgQuerySpec where
|
module PgQuerySpec where
|
||||||
|
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
@@ -5,7 +7,10 @@ import Test.Hspec
|
|||||||
import Database.HDBC
|
import Database.HDBC
|
||||||
import Database.HDBC.PostgreSQL
|
import Database.HDBC.PostgreSQL
|
||||||
|
|
||||||
loadFixture :: String -> IO ()
|
import PgQuery (insert)
|
||||||
|
import Types (SqlRow(..))
|
||||||
|
|
||||||
|
loadFixture :: String -> IO Connection
|
||||||
loadFixture name = do
|
loadFixture name = do
|
||||||
conn <- connectPostgreSQL "postgres://postgres:@localhost:5432/dbapi_test"
|
conn <- connectPostgreSQL "postgres://postgres:@localhost:5432/dbapi_test"
|
||||||
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
|
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
|
||||||
@@ -13,6 +18,7 @@ loadFixture name = do
|
|||||||
runRaw conn "create schema public"
|
runRaw conn "create schema public"
|
||||||
runRaw conn sql
|
runRaw conn sql
|
||||||
commit conn
|
commit conn
|
||||||
|
return conn
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = hspec spec
|
main = hspec spec
|
||||||
@@ -20,8 +26,13 @@ main = hspec spec
|
|||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = beforeAll (loadFixture "schema") $ do
|
spec = beforeAll (loadFixture "schema") $ do
|
||||||
describe "insert" $
|
describe "insert" $
|
||||||
it "can insert into an empty table" $ \_ ->
|
it "can insert into an empty table" $ \conn -> do
|
||||||
head [23 ..] `shouldBe` (23 :: Int)
|
_ <- insert "public" "auto_incrementing_pk" (SqlRow [
|
||||||
|
("non_nullable_string", toSql ("a string that isn't null" :: String))
|
||||||
|
]) conn
|
||||||
|
r <- quickQuery conn "select count(1) from auto_incrementing_pk" []
|
||||||
|
commit conn
|
||||||
|
[[toSql (1 :: Int)]] `shouldBe` r
|
||||||
|
|
||||||
describe "insert again" $
|
describe "insert again" $
|
||||||
it "is true" $ \_ ->
|
it "is true" $ \_ ->
|
||||||
|
|||||||
Reference in New Issue
Block a user