git.iko.soy/typeable/bloodhound
on master help sign in
tests passing
891eee6Chris Allen
bloodhound.cabal−1
@@ -32,7 +32,6 @@ library
32 bytestring >= 0.10.0 && <0.11,
32 bytestring >= 0.10.0 && <0.11,
33 containers >= 0.5.0.0 && <0.6,
33 containers >= 0.5.0.0 && <0.6,
34 aeson >= 0.7 && <0.11,
34 aeson >= 0.7 && <0.11,
35− aeson-extra >= 0.1 && <0.2,
36 http-client >= 0.3 && <0.5,
35 http-client >= 0.3 && <0.5,
37 network-uri >= 2.6 && <2.7,
36 network-uri >= 2.6 && <2.7,
38 semigroups >= 0.15 && <0.18,
37 semigroups >= 0.15 && <0.18,
src/Database/Bloodhound/Types.hs+6−7
@@ -236,8 +236,7 @@ import Control.Monad.Except
236import Control.Monad.Reader
236import Control.Monad.Reader
237import Control.Monad.State
237import Control.Monad.State
238import Control.Monad.Writer
238import Control.Monad.Writer
239−import Data.Aeson hiding ((.:?))
239+import Data.Aeson
240−import Data.Aeson.Compat ((.:?))
241import Data.Aeson.Types (Pair, emptyObject, parseMaybe)
240import Data.Aeson.Types (Pair, emptyObject, parseMaybe)
242import qualified Data.ByteString.Lazy.Char8 as L
241import qualified Data.ByteString.Lazy.Char8 as L
243import qualified Data.HashMap.Strict as HM (union)
242import qualified Data.HashMap.Strict as HM (union)
@@ -2409,11 +2408,11 @@ instance (FromJSON a) => FromJSON (SearchHits a) where
2409
2408
2410instance (FromJSON a) => FromJSON (Hit a) where
2409instance (FromJSON a) => FromJSON (Hit a) where
2411 parseJSON (Object v) = Hit <$>
2410 parseJSON (Object v) = Hit <$>
2412− v .: "_index" <*>
2411+ v .: "_index" <*>
2413− v .: "_type" <*>
2412+ v .: "_type" <*>
2414− v .: "_id" <*>
2413+ v .: "_id" <*>
2415− v .: "_score" <*>
2414+ v .: "_score" <*>
2416− v .:? "_source" <*>
2415+ v .:? "_source" <*>
2417 v .:? "highlight"
2416 v .:? "highlight"
2418 parseJSON _ = empty
2417 parseJSON _ = empty
2419
2418
tests/tests.hs+17−8
@@ -14,6 +14,7 @@ import Data.List (nub)
14import Data.List.NonEmpty (NonEmpty (..))
14import Data.List.NonEmpty (NonEmpty (..))
15import qualified Data.List.NonEmpty as NE
15import qualified Data.List.NonEmpty as NE
16import qualified Data.Map.Strict as M
16import qualified Data.Map.Strict as M
17+import qualified Data.Maybe as MY
17import Data.Monoid
18import Data.Monoid
18import Data.Text (Text)
19import Data.Text (Text)
19import qualified Data.Text as T
20import qualified Data.Text as T
@@ -27,7 +28,7 @@ import Network.HTTP.Client
27import qualified Network.HTTP.Types.Status as NHTS
28import qualified Network.HTTP.Types.Status as NHTS
28import Prelude hiding (filter)
29import Prelude hiding (filter)
29import Test.Hspec
30import Test.Hspec
30−import Test.QuickCheck.Property.Monoid (prop_Monoid, eq, T(..))
31+import Test.QuickCheck.Property.Monoid (T (..), eq, prop_Monoid)
31
32
32import Test.Hspec.QuickCheck (prop)
33import Test.Hspec.QuickCheck (prop)
33import Test.QuickCheck
34import Test.QuickCheck
@@ -196,8 +197,9 @@ insertWithSpaceInId = do
196searchTweet :: Search -> BH IO (Either String Tweet)
197searchTweet :: Search -> BH IO (Either String Tweet)
197searchTweet search = do
198searchTweet search = do
198 result <- searchTweets search
199 result <- searchTweets search
199− let myTweet = fmap (hitSource . head . hits . searchHits) result
200+ let myTweet :: Either String Tweet
201+ myTweet = grabFirst result
200− return (either (Left "myTweet was Nothing") id myTweet)
202+ return myTweet
201
203
202searchTweets :: Search -> BH IO (Either String (SearchResult Tweet))
204searchTweets :: Search -> BH IO (Either String (SearchResult Tweet))
203searchTweets search = eitherDecode . responseBody <$> searchByIndex testIndex search
205searchTweets search = eitherDecode . responseBody <$> searchByIndex testIndex search
@@ -247,8 +249,7 @@ searchExpectSource src expected = do
247 let search = (mkSearch (Just query) Nothing) { source = Just src }
249 let search = (mkSearch (Just query) Nothing) { source = Just src }
248 reply <- searchAll search
250 reply <- searchAll search
249 let result = eitherDecode (responseBody reply) :: Either String (SearchResult Value)
251 let result = eitherDecode (responseBody reply) :: Either String (SearchResult Value)
250− let value = fmap (hitSource . head . hits . searchHits) result
252+ let value = grabFirst result
251− liftIO (print value)
252 liftIO $
253 liftIO $
253 value `shouldBe` expected
254 value `shouldBe` expected
254
255
@@ -314,6 +315,13 @@ instance Arbitrary a => Arbitrary (SearchHits a) where
314getSource :: EsResult a -> Maybe a
315getSource :: EsResult a -> Maybe a
315getSource = fmap _source . foundResult
316getSource = fmap _source . foundResult
316
317
318+-- grabFirst :: Either String (SearchResult a) -> Either String a
319+grabFirst r =
320+ case fmap (hitSource . head . hits . searchHits) r of
321+ (Left e) -> Left e
322+ (Right Nothing) -> Left "Source was missing"
323+ (Right (Just x)) -> Right x
324+
317main :: IO ()
325main :: IO ()
318main = hspec $ do
326main = hspec $ do
319
327
@@ -488,7 +496,7 @@ main = hspec $ do
488 (Just IdentityFilter) (Just [sortSpec]) Nothing Nothing
496 (Just IdentityFilter) (Just [sortSpec]) Nothing Nothing
489 False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing
497 False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing
490 result <- searchTweets search
498 result <- searchTweets search
491− let myTweet = fmap (hitSource . head . hits . searchHits) result
499+ let myTweet = grabFirst result
492 liftIO $
500 liftIO $
493 myTweet `shouldBe` Right otherTweet
501 myTweet `shouldBe` Right otherTweet
494
502
@@ -705,6 +713,7 @@ main = hspec $ do
705 fmap aggregations res `shouldBe` Right (Just (M.fromList [ docCountPair "bitemyapps" 1
713 fmap aggregations res `shouldBe` Right (Just (M.fromList [ docCountPair "bitemyapps" 1
706 , docCountPair "notmyapps" 1
714 , docCountPair "notmyapps" 1
707 ]))
715 ]))
716+
708 -- Interaction of date serialization and date histogram aggregation is broken.
717 -- Interaction of date serialization and date histogram aggregation is broken.
709 -- it "returns date histogram aggregation results" $ withTestEnv $ do
718 -- it "returns date histogram aggregation results" $ withTestEnv $ do
710 -- _ <- insertData
719 -- _ <- insertData
@@ -754,7 +763,7 @@ main = hspec $ do
754 it "doesn't include source when sources are disabled" $ withTestEnv $ do
763 it "doesn't include source when sources are disabled" $ withTestEnv $ do
755 searchExpectSource
764 searchExpectSource
756 NoSource
765 NoSource
757− (Left "key \"_source\" not present")
766+ (Left "Source was missing")
758
767
759 it "includes a source" $ withTestEnv $ do
768 it "includes a source" $ withTestEnv $ do
760 searchExpectSource
769 searchExpectSource
@@ -850,4 +859,4 @@ main = hspec $ do
850 liftIO $
859 liftIO $
851 regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
860 regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
852 liftIO $
861 liftIO $
853− scan_search `shouldMatchList` [exampleTweet, otherTweet]
862+ scan_search `shouldMatchList` [Just exampleTweet, Just otherTweet]