git.iko.soy/typeable/bloodhound
on 088ef73 help sign in
119 lines 4.7 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.Script as Script
29import qualified Test.Snapshots as Snapshots
30import qualified Test.Sorting as Sorting
31import qualified Test.SourceFiltering as SourceFiltering
32import qualified Test.Suggest as Suggest
33import qualified Test.Templates as Templates
35main :: IO ()
36main = hspec $ do
37 Aggregation.spec
38 Bulk.spec
39 Documents.spec
40 Highlights.spec
41 Indices.spec
42 JSON.spec
43 Query.spec
44 Script.spec
45 Snapshots.spec
46 Sorting.spec
47 SourceFiltering.spec
48 Suggest.spec
49 Templates.spec
51 describe "error parsing" $ do
52 it "can parse EsErrors for < 2.0" $ when' (atmost es16) $ withTestEnv $ do
53 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
54 let errorResp = eitherDecode (responseBody res)
55 liftIO (errorResp `shouldBe` Right (EsError 404 "IndexMissingException[[bogus] missing]"))
57 it "can parse EsErrors for >= 2.0" $ when' (atleast es20) $ withTestEnv $ do
58 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
59 let errorResp = eitherDecode (responseBody res)
60 liftIO (errorResp `shouldBe` Right (EsError 404 "no such index"))
62 describe "Monoid (SearchHits a)" $
63 prop "abides the monoid laws" $ eq $
64 prop_Monoid (T :: T (SearchHits ()))
66 describe "mkDocVersion" $
67 prop "can never construct an out of range docVersion" $ \i ->
68 let res = mkDocVersion i
69 in case res of
70 Nothing -> property True
71 Just dv -> (dv >= minBound) .&&.
72 (dv <= maxBound) .&&.
73 docVersionNumber dv === i
75 describe "getNodesInfo" $
76 it "fetches the responding node when LocalNode is used" $ withTestEnv $ do
77 res <- getNodesInfo LocalNode
78 liftIO $ case res of
79 -- This is really just a smoke test for response
80 -- parsing. Node info is so variable, there's not much I can
81 -- assert here.
82 Right NodesInfo {..} -> length nodesInfo `shouldBe` 1
83 Left e -> expectationFailure ("Expected NodesInfo but got " <> show e)
85 describe "getNodesStats" $
86 it "fetches the responding node when LocalNode is used" $ withTestEnv $ do
87 res <- getNodesStats LocalNode
88 liftIO $ case res of
89 -- This is really just a smoke test for response
90 -- parsing. Node stats is so variable, there's not much I can
91 -- assert here.
92 Right NodesStats {..} -> length nodesStats `shouldBe` 1
93 Left e -> expectationFailure ("Expected NodesStats but got " <> show e)
95 describe "Enum DocVersion" $
96 it "follows the laws of Enum, Bounded" $ do
97 evaluate (succ maxBound :: DocVersion) `shouldThrow` anyErrorCall
98 evaluate (pred minBound :: DocVersion) `shouldThrow` anyErrorCall
99 evaluate (toEnum 0 :: DocVersion) `shouldThrow` anyErrorCall
100 evaluate (toEnum 9200000000000000001 :: DocVersion) `shouldThrow` anyErrorCall
101 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
102 enumFrom (pred maxBound :: DocVersion) `shouldBe` [pred maxBound, maxBound]
103 enumFromThen minBound (pred maxBound :: DocVersion) `shouldBe` [minBound, pred maxBound]
105 describe "Scan & Scroll API" $
106 it "returns documents using the scan&scroll API" $ withTestEnv $ do
107 _ <- insertData
108 _ <- insertOther
109 let search =
110 (mkSearch
111 (Just $ MatchAllQuery Nothing) Nothing)
112 { size = Size 1 }
113 regular_search <- searchTweet search
114 scan_search' <- scanSearch testIndex testMapping search :: BH IO [Hit Tweet]
115 let scan_search = map hitSource scan_search'
116 liftIO $
117 regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
118 liftIO $
119 scan_search `shouldMatchList` [Just exampleTweet, Just otherTweet]