John Lenz avatar John Lenz committed e8252eb

Add a failing test of couchDelete followed directly by couchPut

Comments (0)

Files changed (1)

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.