Skip to content

Show that index creation is broken badly #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mongoDB.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ test-suite test
main-is: Main.hs
other-modules: Spec
, QuerySpec
, IndexSpec
, TestImport
ghc-options: -Wall -with-rtsopts "-K64m"
type: exitcode-stdio-1.0
Expand Down
30 changes: 30 additions & 0 deletions test/IndexSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules, ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}

module IndexSpec (spec) where

import TestImport
import System.Environment (getEnv)
import System.IO.Error (catchIOError)

testDBName :: Database
testDBName = "mongodb-haskell-test"

db :: Action IO a -> IO a
db action = do
mongodbHost <- getEnv mongodbHostEnvVariable `catchIOError` (\_ -> return "localhost")
pipe <- connect (host mongodbHost)
result <- access pipe master testDBName action
close pipe
return result

withCleanDatabase :: ActionWith () -> IO ()
withCleanDatabase action = dropDB >> action () >> dropDB >> return ()
where
dropDB = db $ dropDatabase testDBName

spec :: Spec
spec = around withCleanDatabase $ do
describe "make index" $ do
it "single row index" $ do
db (createIndex (index "thiscollection" ["field" =: (1::Int)]) >> getIndexes "thiscollection") `shouldReturn` [["field" =: (1::Int)]]