git.iko.soy/typeable/bloodhound
on master help sign in
Add some finishing touches
commit53f4095b539147db9faf2a3f6f48e5dac441834d authorMichael Xavier <michael@michaelxavier.net> dateMon 2 Nov 2015, 19:34 (11 years ago) parent0663f03
3 files changed+28
src/Database/Bloodhound/Client.hs+6 src/Database/Bloodhound/Types.hs+1 tests/tests.hs+21
src/Database/Bloodhound/Client.hs+6
@@ -283,6 +283,11 @@ existentialQuery url = do
283283 reply <- head url
284284 return (reply, respIsTwoHunna reply)
285285
286+
287+-- | Tries to parse a response body as the expected type @a@ and
288+-- failing that tries to parse it as an EsError. All well-formed, JSON
289+-- responses from elasticsearch should fall into these two
290+-- categories. If they don't, a 'StatusCodeException' will be thrown.
286291parseEsResponse :: (MonadBH m, MonadThrow m, FromJSON a) => Reply
287292 -> m (Either EsError a)
288293parseEsResponse reply
@@ -362,6 +367,7 @@ updateIndexAliases actions = bindM2 post url (return body)
362367 body = Just (encode bodyJSON)
363368 bodyJSON = object [ "actions" .= NE.toList actions]
364369
370+-- | Get all aliases configured on the server.
365371getIndexAliases :: (MonadBH m, MonadThrow m)
366372 => m (Either EsError IndexAliasesSummary)
367373getIndexAliases = parseEsResponse =<< get =<< url
src/Database/Bloodhound/Types.hs+1
@@ -469,6 +469,7 @@ newtype RoutingValue = RoutingValue { routingValue :: Text } deriving (Show, Eq,
469469
470470newtype IndexAliasesSummary = IndexAliasesSummary { indexAliasesSummary :: [IndexAliasSummary] } deriving (Show, Eq)
471471
472+{-| 'IndexAliasSummary' is a summary of an index alias configured for a server. -}
472473data IndexAliasSummary = IndexAliasSummary { indexAliasSummaryAlias :: IndexAlias
473474 , indexAliasSummaryCreate :: IndexAliasCreate} deriving (Show, Eq)
474475
tests/tests.hs+21
@@ -1082,6 +1082,27 @@ main = hspec $ do
10821082 L.find ((== alias) . indexAliasSummaryAlias) summs `shouldBe` Just expected
10831083 Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)) `finally` cleanup
10841084
1085+ it "handles an alias with routing and a filter" $ do
1086+ let alias = IndexAlias (testIndex) (IndexAliasName (IndexName "bloodhound-tests-twitter-1-alias"))
1087+ let sar = SearchAliasRouting (RoutingValue "search val" :| [])
1088+ let iar = IndexAliasRouting (RoutingValue "index val")
1089+ let routing = GranularAliasRouting (Just sar) (Just iar)
1090+ let filter = LimitFilter 42
1091+ let create = IndexAliasCreate (Just routing) (Just filter)
1092+ let action = AddAlias alias create
1093+
1094+ withTestEnv $ do
1095+ resetIndex
1096+ resp <- updateIndexAliases (action :| [])
1097+ liftIO $ NHTS.statusCode (responseStatus resp) `shouldBe` 200
1098+ let cleanup = withTestEnv (updateIndexAliases (RemoveAlias alias :| []))
1099+ (do aliases <- withTestEnv getIndexAliases
1100+ let expected = IndexAliasSummary alias create
1101+ case aliases of
1102+ Right (IndexAliasesSummary summs) ->
1103+ L.find ((== alias) . indexAliasSummaryAlias) summs `shouldBe` Just expected
1104+ Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)) `finally` cleanup
1105+
10851106 describe "JSON instances" $ do
10861107 propJSON (Proxy :: Proxy Version)
10871108 propJSON (Proxy :: Proxy IndexName)