Fix unit tests
updateMany and updateAll don't throw exceptions. They return UpdateResult which reports errors.
This commit is contained in:
parent
1898928cf0
commit
6fe3cd982d
2 changed files with 21 additions and 20 deletions
|
@ -670,7 +670,6 @@ updateBlock ordered col (prevCount, docs) = do
|
||||||
NoConfirm -> ["w" =: (0 :: Int)]
|
NoConfirm -> ["w" =: (0 :: Int)]
|
||||||
Confirm params -> params
|
Confirm params -> params
|
||||||
doc <- runCommand $ updateCommandDocument col ordered docs writeConcern
|
doc <- runCommand $ updateCommandDocument col ordered docs writeConcern
|
||||||
|
|
||||||
let writeConcernError = maybeToList $ do
|
let writeConcernError = maybeToList $ do
|
||||||
wceDoc <- doc !? "writeConcernError"
|
wceDoc <- doc !? "writeConcernError"
|
||||||
return $ docToWriteConcernError wceDoc
|
return $ docToWriteConcernError wceDoc
|
||||||
|
@ -678,7 +677,7 @@ updateBlock ordered col (prevCount, docs) = do
|
||||||
let writeErrors = map docToWriteError $ fromMaybe [] (doc !? "writeErrors")
|
let writeErrors = map docToWriteError $ fromMaybe [] (doc !? "writeErrors")
|
||||||
let upsertedDocs = fromMaybe [] (doc !? "upserted")
|
let upsertedDocs = fromMaybe [] (doc !? "upserted")
|
||||||
return $ UpdateResult
|
return $ UpdateResult
|
||||||
False -- TODO it should be changed accordingly
|
((not $ true1 "ok" doc) || (length writeErrors > 0))
|
||||||
(at "n" doc)
|
(at "n" doc)
|
||||||
(at "nModified" doc)
|
(at "nModified" doc)
|
||||||
(map docToUpserted upsertedDocs)
|
(map docToUpserted upsertedDocs)
|
||||||
|
|
|
@ -250,7 +250,7 @@ spec = around withCleanDatabase $ do
|
||||||
it "can process different updates" $ do
|
it "can process different updates" $ do
|
||||||
_ <- db $ insert "team" ["name" =: "Yankees", "league" =: "American", "score" =: (Nothing :: Maybe Int)]
|
_ <- db $ insert "team" ["name" =: "Yankees", "league" =: "American", "score" =: (Nothing :: Maybe Int)]
|
||||||
_ <- db $ insert "team" ["name" =: "Giants" , "league" =: "MiLB", "score" =: (1 :: Int)]
|
_ <- db $ insert "team" ["name" =: "Giants" , "league" =: "MiLB", "score" =: (1 :: Int)]
|
||||||
(db $ updateMany "team" [ ( ["name" =: "Yankees"]
|
updateResult <- (db $ updateMany "team" [ ( ["name" =: "Yankees"]
|
||||||
, ["$inc" =: ["score" =: (1 :: Int)]]
|
, ["$inc" =: ["score" =: (1 :: Int)]]
|
||||||
, []
|
, []
|
||||||
)
|
)
|
||||||
|
@ -258,7 +258,8 @@ spec = around withCleanDatabase $ do
|
||||||
, ["$inc" =: ["score" =: (2 :: Int)]]
|
, ["$inc" =: ["score" =: (2 :: Int)]]
|
||||||
, []
|
, []
|
||||||
)
|
)
|
||||||
]) `shouldThrow` anyException
|
])
|
||||||
|
failed updateResult `shouldBe` True
|
||||||
updatedResult <- db $ rest =<< find ((select [] "team") {project = ["_id" =: (0 :: Int)]})
|
updatedResult <- db $ rest =<< find ((select [] "team") {project = ["_id" =: (0 :: Int)]})
|
||||||
(L.sort $ map L.sort updatedResult) `shouldBe` [ ["league" =: "American", "name" =: "Yankees", "score" =: (Nothing :: Maybe Int)]
|
(L.sort $ map L.sort updatedResult) `shouldBe` [ ["league" =: "American", "name" =: "Yankees", "score" =: (Nothing :: Maybe Int)]
|
||||||
, ["league" =: "MiLB" , "name" =: "Giants" , "score" =: (1 :: Int)]
|
, ["league" =: "MiLB" , "name" =: "Giants" , "score" =: (1 :: Int)]
|
||||||
|
@ -280,7 +281,7 @@ spec = around withCleanDatabase $ do
|
||||||
it "can process different updates" $ do
|
it "can process different updates" $ do
|
||||||
_ <- db $ insert "team" ["name" =: "Yankees", "league" =: "American", "score" =: (Nothing :: Maybe Int)]
|
_ <- db $ insert "team" ["name" =: "Yankees", "league" =: "American", "score" =: (Nothing :: Maybe Int)]
|
||||||
_ <- db $ insert "team" ["name" =: "Giants" , "league" =: "MiLB", "score" =: (1 :: Int)]
|
_ <- db $ insert "team" ["name" =: "Giants" , "league" =: "MiLB", "score" =: (1 :: Int)]
|
||||||
(db $ updateAll "team" [ ( ["name" =: "Yankees"]
|
updateResult <- (db $ updateAll "team" [ ( ["name" =: "Yankees"]
|
||||||
, ["$inc" =: ["score" =: (1 :: Int)]]
|
, ["$inc" =: ["score" =: (1 :: Int)]]
|
||||||
, []
|
, []
|
||||||
)
|
)
|
||||||
|
@ -288,7 +289,8 @@ spec = around withCleanDatabase $ do
|
||||||
, ["$inc" =: ["score" =: (2 :: Int)]]
|
, ["$inc" =: ["score" =: (2 :: Int)]]
|
||||||
, []
|
, []
|
||||||
)
|
)
|
||||||
]) `shouldThrow` anyException
|
])
|
||||||
|
failed updateResult `shouldBe` True
|
||||||
updatedResult <- db $ rest =<< find ((select [] "team") {project = ["_id" =: (0 :: Int)]})
|
updatedResult <- db $ rest =<< find ((select [] "team") {project = ["_id" =: (0 :: Int)]})
|
||||||
(L.sort $ map L.sort updatedResult) `shouldBe` [ ["league" =: "American", "name" =: "Yankees", "score" =: (Nothing :: Maybe Int)]
|
(L.sort $ map L.sort updatedResult) `shouldBe` [ ["league" =: "American", "name" =: "Yankees", "score" =: (Nothing :: Maybe Int)]
|
||||||
, ["league" =: "MiLB" , "name" =: "Giants" , "score" =: (3 :: Int)]
|
, ["league" =: "MiLB" , "name" =: "Giants" , "score" =: (3 :: Int)]
|
||||||
|
|
Loading…
Reference in a new issue