-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest.hs
More file actions
57 lines (48 loc) · 1.74 KB
/
Copy pathTest.hs
File metadata and controls
57 lines (48 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE OverloadedStrings #-}
import Control.Exception (catch, SomeException(..))
import Test.Tasty.HUnit ((@?=))
import qualified Database.Sophia as S
import qualified System.Directory as Dir
import qualified Test.Tasty as T
import qualified Test.Tasty.HUnit as TUnit
main :: IO ()
main = T.defaultMain tests
ignoreExceptions :: IO () -> IO ()
ignoreExceptions act = act `catch` \(SomeException _) -> return ()
tests :: T.TestTree
tests =
T.testGroup "Unit tests"
[ TUnit.testCase "Create DB, call some APIs" $ do
ignoreExceptions $ Dir.removeDirectoryRecursive "/tmp/sophia-test-db"
putStrLn "Phase 1"
S.withEnv $ \env -> do
S.openDir env S.ReadWrite S.AllowCreation "/tmp/sophia-test-db"
S.withDb env $ \db -> do
TUnit.assertBool "Key must not exist" . not =<< S.hasValue db "Key"
do
res <- S.getValue db "Key"
res @?= Nothing
putStrLn "Phase 2"
S.setValue db "Key" "Val"
TUnit.assertBool "Key2 must not exist" . not =<< S.hasValue db "Key2"
TUnit.assertBool "Key must exist" =<< S.hasValue db "Key"
do
res <- S.getValue db "Key"
res @?= Just "Val"
putStrLn "Phase 3"
S.setValue db "A" "foo"
S.setValue db "Z" "bar"
S.withCursor db S.GTE "A" $ \cursor -> do
res <- S.fetchCursorAll cursor
res @?=
[ ("A", "foo")
, ("Key", "Val")
, ("Z", "bar")
]
putStrLn "Phase 4"
putStrLn "Deleting \"Key\""
S.delValue db "Key"
putStrLn "Done deleting"
TUnit.assertBool "Key must not exist" . not =<< S.hasValue db "Key"
putStrLn "Done!"
]