module Database.Redis.General.Tests ( tests ) where ------------------------------------------------------------------------------ import Test.Framework (Test) import Test.Framework.Providers.HUnit -- import Test.Framework.Providers.QuickCheck2 import qualified Test.HUnit as H -- import Test.QuickCheck -- import Test.QuickCheck.Monadic import Database.Redis ------------------------------------------------------------------------------ -- N.B. These aren't proper tests yet, just checks ------------------------------------------------------------------------------ tests :: [Test] tests = [ testCase "redis keyExists" keyExistsTest , testCase "redis keyExistsB" keyExistsBTest , testCase "redis keyType" keyTypeTest , testCase "redis keyTypeB" keyTypeBTest , testCase "redis keys" keysTest , testCase "redis keysB" keysBTest , testCase "redis keyRandom" keyRandomTest , testCase "redis keyRename" keyRenameTest ] ------------------------------------------------------------------------------ keyExistsTest :: H.Assertion keyExistsTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- itemSet con "thekey" "thevalue" returning <- keyExists con "thekey" _ <- keyDelete con ["thekey"] disconnect con H.assertEqual "keyExistsTest" (Just $ RedisInteger 1) returning ------------------------------------------------------------------------------ keyExistsBTest :: H.Assertion keyExistsBTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- itemSetB con (toUTF8 "thebkey") (toUTF8 "thevalue") returning <- keyExistsB con (toUTF8 "thebkey") _ <- keyDeleteB con $ map toUTF8 ["thebkey"] disconnect con H.assertEqual "keyExistsB" (Just $ RedisInteger 1) returning ------------------------------------------------------------------------------ keyTypeTest :: H.Assertion keyTypeTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- itemSet con "typekey" "typevalue" returning <- keyType con "typekey" _ <- keyDelete con ["typekey"] disconnect con H.assertEqual "keyType" (Just $ RedisSingle $ toUTF8 "string") returning ------------------------------------------------------------------------------ keyTypeBTest :: H.Assertion keyTypeBTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- itemSet con "typebkey" "typevalue" returning <- keyTypeB con (toUTF8 "typebkey") _ <- keyDelete con ["typebkey"] disconnect con H.assertEqual "keyTypeB" (Just $ RedisSingle $ toUTF8 "string") returning ------------------------------------------------------------------------------ keysTest :: H.Assertion keysTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- itemSet con "keystest0" "value" _ <- itemSet con "keystest1" "value" returning <- keys con "keys*" _ <- keyDelete con ["keystest0"] _ <- keyDelete con ["keystest1"] disconnect con H.assertEqual "keys" (Just (RedisBulk [Just (RedisBulk [Just (RedisSingle $ toUTF8 "keystest0")]) ,Just (RedisBulk [Just (RedisSingle $ toUTF8 "keystest1")]) ,Nothing])) returning ------------------------------------------------------------------------------ keysBTest :: H.Assertion keysBTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- itemSetB con (toUTF8 "keystest2") (toUTF8 "value") _ <- itemSetB con (toUTF8 "keystest3") (toUTF8 "value") returning <- keysB con (toUTF8 "keys*") _ <- keyDeleteB con $ map toUTF8 ["keystest2"] _ <- keyDeleteB con $ map toUTF8 ["keystest3"] disconnect con H.assertEqual "keysB" (Just (RedisBulk [Just (RedisBulk [Just (RedisSingle $ toUTF8 "keystest2")]) ,Just (RedisBulk [Just (RedisSingle $ toUTF8 "keystest3")]) ,Nothing])) returning ------------------------------------------------------------------------------ keyRandomTest :: H.Assertion keyRandomTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- keyRandom con disconnect con H.assertEqual "keyRandom" "blah" "blah" ------------------------------------------------------------------------------ keyRenameTest :: H.Assertion keyRenameTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- itemSet con "renametest" "special" _ <- keyRename con "renametest" "success" returning <- keys con "success" disconnect con H.assertEqual "keysRename" (Just (RedisBulk [Just (RedisBulk [Just (RedisSingle $ toUTF8 "success")]) ,Nothing])) returning