@@ -7,7 +7,7 @@ import TestImport
77import Control.Concurrent (threadDelay )
88import Control.Exception
99import Control.Monad (forM_ , when )
10- import System.Environment (getEnv )
10+ import System.Environment (getEnv , lookupEnv )
1111import System.IO.Error (catchIOError )
1212import qualified Data.List as L
1313
@@ -17,12 +17,26 @@ testDBName :: Database
1717testDBName = " mongodb-haskell-test"
1818
1919db :: Action IO a -> IO a
20- db action = do
20+ db action = bracket start end inbetween
21+ where
22+ start = lookupEnv " CONNECTION_STRING" >>= getPipe
23+ end (_, pipe) = close pipe
24+ inbetween (testuser, pipe) = do
25+ logged_in <-
26+ access pipe master " admin" $ do
27+ auth (u_name testuser) (u_passwd testuser)
28+ assert logged_in $ pure ()
29+ access pipe master testDBName action
30+ getPipe Nothing = do
31+ let user = TestUser " testadmin" " 123"
2132 mongodbHost <- getEnv mongodbHostEnvVariable `catchIOError` (\ _ -> return " localhost" )
2233 pipe <- connect (host mongodbHost)
23- result <- access pipe master testDBName action
24- close pipe
25- return result
34+ pure (user, pipe)
35+ getPipe (Just cs) = do
36+ let creds = extractMongoAtlasCredentials . T. pack $ cs
37+ user = TestUser " testadmin" (atlas_password creds)
38+ pipe <- connectAtlas creds
39+ pure (user, pipe)
2640
2741getWireVersion :: IO Int
2842getWireVersion = db $ do
@@ -68,6 +82,8 @@ fineGrainedBigDocument = (flip map) [1..1000] $ \i -> (fromString $ "team" ++ (s
6882hugeDocument :: Document
6983hugeDocument = (flip map ) [1 .. 1000000 ] $ \ i -> (fromString $ " team" ++ (show i)) =: (" team " ++ (show i) ++ " name" )
7084
85+ data TestUser = TestUser { u_name :: T. Text , u_passwd :: T. Text}
86+
7187spec :: Spec
7288spec = around withCleanDatabase $ do
7389 describe " useDb" $ do
@@ -78,11 +94,13 @@ spec = around withCleanDatabase $ do
7894
7995 describe " collectionWithDot" $ do
8096 it " uses a collection with dots in the name" $ do
81- let coll = " collection.with.dot"
82- _id <- db $ insert coll [" name" =: " jack" , " color" =: " blue" ]
83- Just doc <- db $ findOne (select [" name" =: " jack" ] coll)
84- doc !? " color" `shouldBe` (Just " blue" )
85-
97+ -- Dots in collection names are disallowed from Mongo 6 on
98+ mongo_version <- getEnv " MONGO_VERSION"
99+ when (mongo_version `elem` [" mongo:5.0" , " mongo:4.0" ]) $ do
100+ let collec = " collection.with.dot"
101+ _id <- db $ insert collec [" name" =: " jack" , " color" =: " blue" ]
102+ Just doc <- db $ findOne (select [" name" =: " jack" ] collec)
103+ doc !? " color" `shouldBe` Just " blue"
86104
87105 describe " insert" $ do
88106 it " inserts a document to the collection and returns its _id" $ do
@@ -497,4 +515,3 @@ spec = around withCleanDatabase $ do
497515 , sort = [ " _id" =: 1 ]
498516 }
499517 result `shouldBe` [[" _id" =: " jane" ], [" _id" =: " jill" ], [" _id" =: " joe" ]]
500-
0 commit comments