Add some finishing touches

This commit is contained in:
Michael Xavier 2015-11-02 19:34:58 -08:00
parent 0663f0306d
commit 53f4095b53
3 changed files with 28 additions and 0 deletions

View File

@ -283,6 +283,11 @@ existentialQuery url = do
reply <- head url
return (reply, respIsTwoHunna reply)
-- | Tries to parse a response body as the expected type @a@ and
-- failing that tries to parse it as an EsError. All well-formed, JSON
-- responses from elasticsearch should fall into these two
-- categories. If they don't, a 'StatusCodeException' will be thrown.
parseEsResponse :: (MonadBH m, MonadThrow m, FromJSON a) => Reply
-> m (Either EsError a)
parseEsResponse reply
@ -362,6 +367,7 @@ updateIndexAliases actions = bindM2 post url (return body)
body = Just (encode bodyJSON)
bodyJSON = object [ "actions" .= NE.toList actions]
-- | Get all aliases configured on the server.
getIndexAliases :: (MonadBH m, MonadThrow m)
=> m (Either EsError IndexAliasesSummary)
getIndexAliases = parseEsResponse =<< get =<< url

View File

@ -469,6 +469,7 @@ newtype RoutingValue = RoutingValue { routingValue :: Text } deriving (Show, Eq,
newtype IndexAliasesSummary = IndexAliasesSummary { indexAliasesSummary :: [IndexAliasSummary] } deriving (Show, Eq)
{-| 'IndexAliasSummary' is a summary of an index alias configured for a server. -}
data IndexAliasSummary = IndexAliasSummary { indexAliasSummaryAlias :: IndexAlias
, indexAliasSummaryCreate :: IndexAliasCreate} deriving (Show, Eq)

View File

@ -1082,6 +1082,27 @@ main = hspec $ do
L.find ((== alias) . indexAliasSummaryAlias) summs `shouldBe` Just expected
Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)) `finally` cleanup
it "handles an alias with routing and a filter" $ do
let alias = IndexAlias (testIndex) (IndexAliasName (IndexName "bloodhound-tests-twitter-1-alias"))
let sar = SearchAliasRouting (RoutingValue "search val" :| [])
let iar = IndexAliasRouting (RoutingValue "index val")
let routing = GranularAliasRouting (Just sar) (Just iar)
let filter = LimitFilter 42
let create = IndexAliasCreate (Just routing) (Just filter)
let action = AddAlias alias create
withTestEnv $ do
resetIndex
resp <- updateIndexAliases (action :| [])
liftIO $ NHTS.statusCode (responseStatus resp) `shouldBe` 200
let cleanup = withTestEnv (updateIndexAliases (RemoveAlias alias :| []))
(do aliases <- withTestEnv getIndexAliases
let expected = IndexAliasSummary alias create
case aliases of
Right (IndexAliasesSummary summs) ->
L.find ((== alias) . indexAliasSummaryAlias) summs `shouldBe` Just expected
Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)) `finally` cleanup
describe "JSON instances" $ do
propJSON (Proxy :: Proxy Version)
propJSON (Proxy :: Proxy IndexName)