Commits

Bryan O'Sullivan committed f51d44f

Add basic QuickCheck property testing support.

Comments (0)

Files changed (1)

tests/Properties.hs

+import Control.Applicative ((<$>))
+import Control.Exception (finally)
+import Control.Monad (forM_)
+import Data.IORef (IORef, modifyIORef, newIORef, readIORef)
+import Network.Riak.Connection (defaultClient)
+import Network.Riak.Connection.Pool (Pool, create, withConnection)
+import Network.Riak.Content (binary)
+import Network.Riak.Types (Bucket, Key, Quorum(..))
+import System.IO.Unsafe (unsafePerformIO)
+import Test.Framework (defaultMain, testGroup)
+import Test.Framework.Providers.QuickCheck2 (testProperty)
+import Test.QuickCheck (Arbitrary(..))
+import Test.QuickCheck.Monadic (assert, monadicIO, run)
+import qualified Data.ByteString.Lazy as L
+import qualified Network.Riak.Basic as B
+import qualified Network.Riak.JSON as J
+import qualified Network.Riak.Value as V
+
+instance Arbitrary L.ByteString where
+    arbitrary     = L.pack `fmap` arbitrary
+
+cruft :: IORef [(Bucket, Key)]
+{-# NOINLINE cruft #-}
+cruft = unsafePerformIO $ newIORef []
+
+pool :: Pool
+{-# NOINLINE pool #-}
+pool = unsafePerformIO $
+       create defaultClient 1 1 1
+
+t_put_get b k v = monadicIO $ assert . uncurry (==) =<< run act
+ where
+  act = withConnection pool $ \c -> do
+          modifyIORef cruft ((b,k):)
+          p <- Just <$> B.put c b k Nothing (binary v) Default Default
+          r <- B.get c b k Default
+          return (p,r)
+
+main = defaultMain tests `finally` cleanup
+  where
+    cleanup = withConnection pool $ \c -> do
+                bks <- readIORef cruft
+                forM_ bks $ \(b,k) -> B.delete c b k Default
+
+tests = [
+  testProperty "t_put_get" t_put_get
+ ]
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.