git.iko.soy/typeable/bloodhound
on index-hack help sign in
136 lines 5.4 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 Data.Aeson as Aeson
22import qualified Test.Aggregation as Aggregation
23import qualified Test.BulkAPI as Bulk
24import qualified Test.Documents as Documents
25import qualified Test.Highlights as Highlights
26import qualified Test.Indices as Indices
27import qualified Test.JSON as JSON
28import qualified Test.Query as Query
29import qualified Test.Script as Script
30import qualified Test.Snapshots as Snapshots
31import qualified Test.Sorting as Sorting
32import qualified Test.SourceFiltering as SourceFiltering
33import qualified Test.Suggest as Suggest
34import qualified Test.Templates as Templates
36main :: IO ()
37main = hspec $ do
38 Aggregation.spec
39 Bulk.spec
40 Documents.spec
41 Highlights.spec
42 Indices.spec
43 JSON.spec
44 Query.spec
45 Script.spec
46 Snapshots.spec
47 Sorting.spec
48 SourceFiltering.spec
49 Suggest.spec
50 Templates.spec
52 describe "error parsing" $ do
53 it "can parse EsErrors for < 2.0" $ when' (atmost es16) $ withTestEnv $ do
54 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
55 let errorResp = eitherDecode (responseBody res)
56 liftIO (errorResp `shouldBe` Right (EsError 404 "IndexMissingException[[bogus] missing]"))
58 it "can parse EsErrors for >= 2.0" $ when' (atleast es20) $ withTestEnv $ do
59 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
60 let errorResp = eitherDecode (responseBody res)
61 liftIO (errorResp `shouldBe` Right (EsError 404 "no such index"))
63 describe "Monoid (SearchHits a)" $
64 prop "abides the monoid laws" $ eq $
65 prop_Monoid (T :: T (SearchHits ()))
67 describe "mkDocVersion" $
68 prop "can never construct an out of range docVersion" $ \i ->
69 let res = mkDocVersion i
70 in case res of
71 Nothing -> property True
72 Just dv -> (dv >= minBound) .&&.
73 (dv <= maxBound) .&&.
74 docVersionNumber dv === i
76 describe "getNodesInfo" $
77 it "fetches the responding node when LocalNode is used" $ withTestEnv $ do
78 res <- getNodesInfo LocalNode
79 liftIO $ case res of
80 -- This is really just a smoke test for response
81 -- parsing. Node info is so variable, there's not much I can
82 -- assert here.
83 Right NodesInfo {..} -> length nodesInfo `shouldBe` 1
84 Left e -> expectationFailure ("Expected NodesInfo but got " <> show e)
86 describe "getNodesStats" $
87 it "fetches the responding node when LocalNode is used" $ withTestEnv $ do
88 res <- getNodesStats LocalNode
89 liftIO $ case res of
90 -- This is really just a smoke test for response
91 -- parsing. Node stats is so variable, there's not much I can
92 -- assert here.
93 Right NodesStats {..} -> length nodesStats `shouldBe` 1
94 Left e -> expectationFailure ("Expected NodesStats but got " <> show e)
96 describe "Enum DocVersion" $
97 it "follows the laws of Enum, Bounded" $ do
98 evaluate (succ maxBound :: DocVersion) `shouldThrow` anyErrorCall
99 evaluate (pred minBound :: DocVersion) `shouldThrow` anyErrorCall
100 evaluate (toEnum 0 :: DocVersion) `shouldThrow` anyErrorCall
101 evaluate (toEnum 9200000000000000001 :: DocVersion) `shouldThrow` anyErrorCall
102 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
103 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
104 enumFromThen minBound (pred maxBound :: DocVersion) `shouldBe` [minBound, pred maxBound]
106 describe "Scan & Scroll API" $
107 it "returns documents using the scan&scroll API" $ withTestEnv $ do
108 _ <- insertData
109 _ <- insertOther
110 let search =
111 (mkSearch
112 (Just $ MatchAllQuery Nothing) Nothing)
113 { size = Size 1 }
114 regular_search <- searchTweet search
115 scan_search' <- scanSearch testIndex testMapping search :: BH IO [Hit Tweet]
116 let scan_search = map hitSource scan_search'
117 liftIO $
118 regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
119 liftIO $
120 scan_search `shouldMatchList` [Just exampleTweet, Just otherTweet]
122 describe "Search After API" $
123 it "returns document for search after query" $ withTestEnv $ do
124 _ <- insertData
125 _ <- insertOther
126 let
127 sortSpec = DefaultSortSpec $ mkSort (FieldName "user") Ascending
128 searchAfterKey = [Aeson.toJSON ("bitemyapp" :: String)]
129 search = Search Nothing
130 Nothing (Just [sortSpec]) Nothing Nothing
131 False (From 0) (Size 10) SearchTypeQueryThenFetch (Just searchAfterKey)
132 Nothing Nothing Nothing Nothing
133 result <- searchTweets search
134 let myTweet = grabFirst result
135 liftIO $
136 myTweet `shouldBe` Right otherTweet