git.iko.soy/typeable/bloodhound
on master help sign in
Add test for simple case of creating an alias
e07c0c4Michael Xavier
src/Database/Bloodhound/Types.hs+2−2
@@ -468,10 +468,10 @@ newtype IndexAliasRouting = IndexAliasRouting RoutingValue deriving (Show, Eq, T
468
468
469newtype RoutingValue = RoutingValue { routingValue :: Text } deriving (Show, Eq, ToJSON, FromJSON)
469newtype RoutingValue = RoutingValue { routingValue :: Text } deriving (Show, Eq, ToJSON, FromJSON)
470
470
471−newtype IndexAliasesSummary = IndexAliasesSummary [IndexAliasSummary]
471+newtype IndexAliasesSummary = IndexAliasesSummary { indexAliasesSummary :: [IndexAliasSummary] } deriving (Show, Eq)
472
472
473data IndexAliasSummary = IndexAliasSummary { indexAliasSummaryAlias :: IndexAlias
473data IndexAliasSummary = IndexAliasSummary { indexAliasSummaryAlias :: IndexAlias
474− , indexAliasSummaryCreate :: IndexAliasCreate}
474+ , indexAliasSummaryCreate :: IndexAliasCreate} deriving (Show, Eq)
475
475
476{-| 'DocVersion' is an integer version number for a document between 1
476{-| 'DocVersion' is an integer version number for a document between 1
477and 9.2e+18 used for <<https://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html optimistic concurrency control>>.
477and 9.2e+18 used for <<https://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html optimistic concurrency control>>.
tests/tests.hs+19
@@ -14,6 +14,7 @@ import Data.Aeson.Types (parseEither)
14import Data.DeriveTH
14import Data.DeriveTH
15import qualified Data.HashMap.Strict as HM
15import qualified Data.HashMap.Strict as HM
16import Data.List (nub)
16import Data.List (nub)
17+import qualified Data.List as L
17import Data.List.NonEmpty (NonEmpty (..))
18import Data.List.NonEmpty (NonEmpty (..))
18import qualified Data.List.NonEmpty as NE
19import qualified Data.List.NonEmpty as NE
19import qualified Data.Map.Strict as M
20import qualified Data.Map.Strict as M
@@ -981,6 +982,24 @@ main = hspec $ do
981 liftIO $
982 liftIO $
982 scan_search `shouldMatchList` [Just exampleTweet, Just otherTweet]
983 scan_search `shouldMatchList` [Just exampleTweet, Just otherTweet]
983
984
985+ describe "index aliases" $ do
986+ it "handles the simple case of aliasing an existing index" $ do
987+ let alias = IndexAlias (testIndex) (IndexAliasName (IndexName "bloodhound-tests-twitter-1-alias"))
988+ let create = IndexAliasCreate Nothing Nothing
989+ let action = AddAlias alias create
990+
991+ withTestEnv $ do
992+ resetIndex
993+ resp <- updateIndexAliases (action :| [])
994+ liftIO $ NHTS.statusCode (responseStatus resp) `shouldBe` 200
995+ let cleanup = withTestEnv (updateIndexAliases (RemoveAlias alias :| []))
996+ (do aliases <- withTestEnv getIndexAliases
997+ let expected = IndexAliasSummary alias create
998+ case aliases of
999+ Right (IndexAliasesSummary summs) ->
1000+ L.find ((== alias) . indexAliasSummaryAlias) summs `shouldBe` Just expected
1001+ Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)) `finally` cleanup
1002+
984 describe "JSON instances" $ do
1003 describe "JSON instances" $ do
985 propJSON (Proxy :: Proxy Version)
1004 propJSON (Proxy :: Proxy Version)
986 propJSON (Proxy :: Proxy IndexName)
1005 propJSON (Proxy :: Proxy IndexName)