couchdb-enumerator 0.3.1 → 0.3.2
raw patch · 3 files changed
+27/−20 lines, 3 filesdep +unordered-containersdep ~aesondep ~attoparsecdep ~attoparsec-enumeratorPVP ok
version bump matches the API change (PVP)
Dependencies added: unordered-containers
Dependency ranges changed: aeson, attoparsec, attoparsec-enumerator, containers
API changes (from Hackage documentation)
Files
- Database/CouchDB/Enumerator.hs +1/−1
- couchdb-enumerator.cabal +12/−11
- tests.hs +14/−8
Database/CouchDB/Enumerator.hs view
@@ -90,7 +90,7 @@ import qualified Data.ByteString as B import qualified Data.ByteString.UTF8 as BU8 import Data.Enumerator hiding (map)-import qualified Data.Map as M+import qualified Data.HashMap.Lazy as M import qualified Data.Text as T import qualified Data.Text.Encoding as TE import Data.Typeable (Typeable)
couchdb-enumerator.cabal view
@@ -1,10 +1,10 @@ Name: couchdb-enumerator-Version: 0.3.1+Version: 0.3.2 Cabal-Version: >= 1.8 License: BSD3 License-File: LICENSE-Author: John Lenz <jlenz2@math.uiuc.edu>-Maintainer: John Lenz <jlenz2@math.uiuc.edu>+Author: John Lenz <lenz@math.uic.edu>+Maintainer: John Lenz <lenz@math.uic.edu> Synopsis: Couch DB client library using http-enumerator and aeson Category: Database, Web Description:@@ -33,18 +33,18 @@ Database.CouchDB.Enumerator Build-Depends:- aeson >= 0.3 && < 0.4- , attoparsec >= 0.8 && < 0.10- , attoparsec-enumerator >= 0.2 && < 0.3+ aeson >= 0.4 && < 0.5+ , attoparsec >= 0.8 && < 0.11+ , attoparsec-enumerator >= 0.2 && < 0.4 , base >= 4 && < 5 , bytestring >= 0.9 && < 0.10- , containers >= 0.3 && < 0.5 , enumerator >= 0.4 && < 0.5 , http-types >= 0.6 && < 0.7 , http-enumerator >= 0.7 && < 0.8 , monad-control >= 0.2 && < 0.3 , text >= 0.11 && < 0.12 , transformers >= 0.2 && < 0.3+ , unordered-containers >= 0.1 && < 0.2 , utf8-string >= 0.3 && < 0.4 Executable test-couch@@ -53,20 +53,21 @@ if flag(test) Buildable: True Build-Depends:- aeson >= 0.3 && < 0.4- , attoparsec >= 0.8 && < 0.10- , attoparsec-enumerator >= 0.2 && < 0.3+ aeson >= 0.4 && < 0.5+ , attoparsec >= 0.8 && < 0.11+ , attoparsec-enumerator >= 0.2 && < 0.4 , base >= 4 && < 5 , bytestring >= 0.9 && < 0.10- , containers >= 0.3 && < 0.5 , enumerator >= 0.4 && < 0.5 , http-types >= 0.6 && < 0.7 , http-enumerator >= 0.7 && < 0.8 , monad-control >= 0.2 && < 0.3 , text >= 0.11 && < 0.12 , transformers >= 0.2 && < 0.3+ , unordered-containers >= 0.1 && < 0.2 , utf8-string >= 0.3 && < 0.4 + , containers , QuickCheck >= 2 , HUnit , test-framework
tests.hs view
@@ -18,7 +18,7 @@ import Data.Enumerator hiding (map, length, head, run, drop) import qualified Data.Enumerator.List as EL import Data.List (find, deleteBy, nubBy)-import qualified Data.Map as M+import qualified Data.HashMap.Lazy as M import Data.Maybe (fromJust) import qualified Data.Text as T import qualified Data.Vector as V@@ -51,7 +51,7 @@ type CouchT m a = ReaderT CouchConnection m a testCouch :: CouchT IO a -> IO ()-testCouch c = withCouchConnection "server" 5984 "test" (runReaderT c) >> return ()+testCouch c = withCouchConnection "172.16.5.2" 5984 "testcouchenum" (runReaderT c) >> return () testCouchCase :: String -> CouchT IO a -> Test testCouchCase s c = testCase s $ testCouch c@@ -68,10 +68,16 @@ ++ T.unpack t ++ " received " ++ T.unpack t' assertStr _ _ = assertFailure "expecting a JSON string" +member :: T.Text -> A.Object -> Bool+member k o = M.lookup k o /= Nothing++isSubmapOf :: A.Object -> A.Object -> Bool+isSubmapOf x y = 0 == M.size (M.difference x y)+ -- | Assert that the given key exists, and the value matches the given assertion assertObjMember :: T.Text -> (A.Value -> Assertion) -> A.Object -> Assertion assertObjMember t f x = do- assertBool (T.unpack t ++ " is missing") $ M.member t x+ assertBool (T.unpack t ++ " is missing") $ member t x f $ fromJust $ M.lookup t x -- | Expect a couch error with the given code@@ -83,13 +89,13 @@ checkLoad :: String -> A.Object -> CouchT IO () checkLoad n obj = do obj' <- couchGet n []- lift $ assertBool "returned object does not match" $ M.isSubmapOf obj obj'+ lift $ assertBool "returned object does not match" $ isSubmapOf obj obj' -- | Delete the given object, useful for the start of a test clearObject :: String -> CouchT IO () clearObject n = go `catch` \(e@(CouchError i _)) -> unless (i == Just 404) $ throwIO e where go = do obj <- couchGet n []- unless (M.member "_rev" obj) $ fail "_rev is missing"+ unless (member "_rev" obj) $ fail "_rev is missing" let (A.String rev) = fromJust $ M.lookup "_rev" obj couchDelete n rev @@ -135,7 +141,7 @@ connectTest :: CouchT IO () connectTest = do v <- couchGet "" []- lift $ assertObjMember "db_name" (assertStr "test") v+ lift $ assertObjMember "db_name" (assertStr "testcouchenum") v missingObjectTest :: CouchT IO () missingObjectTest = assertRecvError (Just 404) $ couchGet "jaosihaweoghaweiouhawef" []@@ -177,9 +183,9 @@ checkEqual :: (Monad m) => [A.Object] -> [A.Object] -> Iteratee a m () checkEqual [] [] = return () checkEqual [] (x:_) = error $ "Extra object in list 2 " ++ show (A.encode x)-checkEqual (x:xs) lst2 = case find (M.isSubmapOf x) lst2 of+checkEqual (x:xs) lst2 = case find (isSubmapOf x) lst2 of Nothing -> error $ "Unable to find " ++ show (A.encode $ A.Object x)- Just _ -> checkEqual xs $ deleteBy M.isSubmapOf x lst2+ Just _ -> checkEqual xs $ deleteBy isSubmapOf x lst2 assertViewRet :: (MonadIO m) => [A.Object] -> Enumerator A.Object m () -> m () assertViewRet lst e = run_ (e $$ EL.consume >>= checkEqual lst)