git.iko.soy/typeable/bloodhound
on 0.16.0.0 help sign in
117 lines 4.6 kB history raw
1{-# LANGUAGE CPP #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE RecordWildCards #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE TypeOperators #-}
7{-# OPTIONS_GHC -fno-warn-orphans #-}
8#if __GLASGOW_HASKELL__ < 800
9{-# OPTIONS_GHC -fcontext-stack=100 #-}
10#endif
11#if __GLASGOW_HASKELL__ >= 802
12{-# LANGUAGE MonoLocalBinds #-}
13#endif
14module Main where
16import Test.Common
17import Test.Import
19import Prelude
21import qualified Test.Aggregation as Aggregation
22import qualified Test.BulkAPI as Bulk
23import qualified Test.Documents as Documents
24import qualified Test.Highlights as Highlights
25import qualified Test.Indices as Indices
26import qualified Test.JSON as JSON
27import qualified Test.Query as Query
28import qualified Test.Snapshots as Snapshots
29import qualified Test.Sorting as Sorting
30import qualified Test.SourceFiltering as SourceFiltering
31import qualified Test.Suggest as Suggest
32import qualified Test.Templates as Templates
34main :: IO ()
35main = hspec $ do
36 Aggregation.spec
37 Bulk.spec
38 Documents.spec
39 Highlights.spec
40 Indices.spec
41 JSON.spec
42 Query.spec
43 Snapshots.spec
44 Sorting.spec
45 SourceFiltering.spec
46 Suggest.spec
47 Templates.spec
49 describe "error parsing" $ do
50 it "can parse EsErrors for < 2.0" $ when' (atmost es16) $ withTestEnv $ do
51 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
52 let errorResp = eitherDecode (responseBody res)
53 liftIO (errorResp `shouldBe` Right (EsError 404 "IndexMissingException[[bogus] missing]"))
55 it "can parse EsErrors for >= 2.0" $ when' (atleast es20) $ withTestEnv $ do
56 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
57 let errorResp = eitherDecode (responseBody res)
58 liftIO (errorResp `shouldBe` Right (EsError 404 "no such index"))
60 describe "Monoid (SearchHits a)" $
61 prop "abides the monoid laws" $ eq $
62 prop_Monoid (T :: T (SearchHits ()))
64 describe "mkDocVersion" $
65 prop "can never construct an out of range docVersion" $ \i ->
66 let res = mkDocVersion i
67 in case res of
68 Nothing -> property True
69 Just dv -> (dv >= minBound) .&&.
70 (dv <= maxBound) .&&.
71 docVersionNumber dv === i
73 describe "getNodesInfo" $
74 it "fetches the responding node when LocalNode is used" $ withTestEnv $ do
75 res <- getNodesInfo LocalNode
76 liftIO $ case res of
77 -- This is really just a smoke test for response
78 -- parsing. Node info is so variable, there's not much I can
79 -- assert here.
80 Right NodesInfo {..} -> length nodesInfo `shouldBe` 1
81 Left e -> expectationFailure ("Expected NodesInfo but got " <> show e)
83 describe "getNodesStats" $
84 it "fetches the responding node when LocalNode is used" $ withTestEnv $ do
85 res <- getNodesStats LocalNode
86 liftIO $ case res of
87 -- This is really just a smoke test for response
88 -- parsing. Node stats is so variable, there's not much I can
89 -- assert here.
90 Right NodesStats {..} -> length nodesStats `shouldBe` 1
91 Left e -> expectationFailure ("Expected NodesStats but got " <> show e)
93 describe "Enum DocVersion" $
94 it "follows the laws of Enum, Bounded" $ do
95 evaluate (succ maxBound :: DocVersion) `shouldThrow` anyErrorCall
96 evaluate (pred minBound :: DocVersion) `shouldThrow` anyErrorCall
97 evaluate (toEnum 0 :: DocVersion) `shouldThrow` anyErrorCall
98 evaluate (toEnum 9200000000000000001 :: DocVersion) `shouldThrow` anyErrorCall
99 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
100 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
101 enumFromThen minBound (pred maxBound :: DocVersion) `shouldBe` [minBound, pred maxBound]
103 describe "Scan & Scroll API" $
104 it "returns documents using the scan&scroll API" $ withTestEnv $ do
105 _ <- insertData
106 _ <- insertOther
107 let search =
108 (mkSearch
109 (Just $ MatchAllQuery Nothing) Nothing)
110 { size = Size 1 }
111 regular_search <- searchTweet search
112 scan_search' <- scanSearch testIndex testMapping search :: BH IO [Hit Tweet]
113 let scan_search = map hitSource scan_search'
114 liftIO $
115 regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
116 liftIO $
117 scan_search `shouldMatchList` [Just exampleTweet, Just otherTweet]