1{-# LANGUAGE OverloadedStrings #-}
3module Test.BulkAPI (spec) where
8import qualified Data.Vector as V
9import qualified Lens.Micro.Aeson as LMA
15instance ToJSON BulkTest where
16 toJSON (BulkTest name') =
17 object ["name" .= name']
19instance FromJSON BulkTest where
20 parseJSON = withObject "BulkTest" parse
24 BulkTest <$> parseJSON t
29 it "inserts all documents we request" $ withTestEnv $ do
31 let firstTest = BulkTest "blah"
32 let secondTest = BulkTest "bloo"
33 let thirdTest = BulkTest "graffle"
34 let fourthTest = BulkTest "garabadoo"
35 let fifthTest = BulkTest "serenity"
36 let firstDoc = BulkIndex testIndex
37 testMapping (DocId "2") (toJSON firstTest)
38 let secondDoc = BulkCreate testIndex
39 testMapping (DocId "3") (toJSON secondTest)
40 let thirdDoc = BulkCreateEncoding testIndex
41 testMapping (DocId "4") (toEncoding thirdTest)
42 let fourthDoc = BulkIndexAuto testIndex
43 testMapping (toJSON fourthTest)
44 let fifthDoc = BulkIndexEncodingAuto testIndex
45 testMapping (toEncoding fifthTest)
46 let stream = V.fromList [firstDoc, secondDoc, thirdDoc, fourthDoc, fifthDoc]
48 -- liftIO $ pPrint bulkResp
49 _ <- refreshIndex testIndex
50 -- liftIO $ pPrint refreshResp
51 fDoc <- getDocument testIndex testMapping (DocId "2")
52 sDoc <- getDocument testIndex testMapping (DocId "3")
53 tDoc <- getDocument testIndex testMapping (DocId "4")
54 -- note that we cannot query for fourthDoc and fifthDoc since we
55 -- do not know their autogenerated ids.
59 :: Either String (EsResult BulkTest)
63 :: Either String (EsResult BulkTest)
67 :: Either String (EsResult BulkTest)
68 -- liftIO $ pPrint [maybeFirst, maybeSecond, maybeThird]
70 fmap getSource maybeFirst `shouldBe` Right (Just firstTest)
71 fmap getSource maybeSecond `shouldBe` Right (Just secondTest)
72 fmap getSource maybeThird `shouldBe` Right (Just thirdTest)
73 -- Since we can't get the docs by doc id, we check for their existence in
75 let query = MatchAllQuery Nothing
76 let search = mkSearch (Just query) Nothing
77 resp <- searchByIndex testIndex search
78 parsed <- parseEsResponse resp :: BH IO (Either EsError (SearchResult Value))
81 liftIO $ expectationFailure ("Expected a script-transformed result but got: " <> show e)
84 hitsTotal (searchHits sr) `shouldBe` 6
85 let nameList :: [Text]
95 `shouldBe` ["blah","bloo","graffle","garabadoo","serenity"]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list