Skip to content

Commit

Permalink
catching failures
Browse files Browse the repository at this point in the history
  • Loading branch information
thma committed Nov 21, 2024
1 parent 3f585ed commit ae69791
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/GenericPersistenceSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ spec = do
insertMany conn manyPersons
countPersons <- count @Person conn allEntries
countPersons `shouldBe` 6
it "signals if counting fails" $ do
conn <- connect AutoCommit <$> connectSqlite3 ":memory:" -- no tables in db
eitherEA <- try (count @Person conn allEntries)
case eitherEA of
Left (DatabaseError msg) -> msg `shouldContain` "no such table: Person"
_ -> expectationFailure "Expected DatabaseError"
it "selectById returns Nothing if no Entity was found" $ do
conn <- prepareDB
person' <- selectById conn (1 :: Int) :: IO (Maybe Person)
Expand Down Expand Up @@ -264,6 +270,12 @@ spec = do
res `shouldBe` ()
allPersons <- select conn allEntries :: IO [Person]
length allPersons `shouldBe` 5
it "signals if deleting by id fails" $ do
conn <- prepareDB
eitherEA <- try (deleteById @Person conn (6 :: Int))
case eitherEA of
Left (EntityNotFound msg) -> msg `shouldContain` "does not exist"
_ -> expectationFailure "Expected EntityNotFound exception"

it "deletes multiple entities by a list of ids" $ do
conn <- prepareDB
Expand Down

0 comments on commit ae69791

Please sign in to comment.