Commits

John Lenz  committed e8252eb

Add a failing test of couchDelete followed directly by couchPut

  • Participants
  • Parent commits 3f7629c

Comments (0)

Files changed (1)

File test/Database/CouchDB/Enumerator/Test/Basic.hs

 
 import           Control.Monad
 import           Control.Monad.Trans.Class (lift)
+import qualified Control.Exception.Lifted as E
+import           Data.Aeson ((.=))
 import qualified Data.Aeson as A
 import qualified Data.HashMap.Lazy as M
 import           Data.List (nubBy)
       testGroup "DB" [
           testCouchCase "basic connection"        connectTest
         , testCouchCase "basic error"             missingObjectTest
+        , testCouchCase "conflict"                conflictError
         --, testCouchProperty "single insert" (1,7) insertTest
         , testCouchCase "insert"                  insertTestCase
         , testCouchCase "basic delete"            deleteTest
 missingObjectTest :: CouchT IO ()
 missingObjectTest = assertRecvError (Just 404) $ couchGet "jaosihaweoghaweiouhawef" []
 
+conflictError :: CouchT IO ()
+conflictError = do
+    E.handle catch404 $ do rev <- couchRev "conflicttest"
+                           couchDelete "conflicttest" rev
+    --E.handle catch404 $ couchRev "somebadobject" >> return ()
+    couchPut_ "conflicttest" [] $ A.object [ "foo" .= True ]
+    return ()
+  where catch404 e@(CouchError c _) = unless (c == Just 404) $ E.throwIO e
+
 insertTestCase :: CouchT IO ()
 insertTestCase = replicateM_ 20 $ do
     objs <- lift $ sample' arbitrary