git.iko.soy/typeable/bloodhound
on master help sign in
Add test for simple case of creating an alias

Once we I the failing quickcheck tests on the more complex alias case, we can add a more complex integration test.

commite07c0c460e312003156e1b907fdd674cfce3c410 authorMichael Xavier <michael@michaelxavier.net> dateMon 26 Oct 2015, 09:06 (11 years ago) parenta72311a
2 files changed+21−2
src/Database/Bloodhound/Types.hs+2−2 tests/tests.hs+19
src/Database/Bloodhound/Types.hs+2−2
@@ -468,10 +468,10 @@ newtype IndexAliasRouting = IndexAliasRouting RoutingValue deriving (Show, Eq, T
468468
469469newtype RoutingValue = RoutingValue { routingValue :: Text } deriving (Show, Eq, ToJSON, FromJSON)
470470
471−newtype IndexAliasesSummary = IndexAliasesSummary [IndexAliasSummary]
471+newtype IndexAliasesSummary = IndexAliasesSummary { indexAliasesSummary :: [IndexAliasSummary] } deriving (Show, Eq)
472472
473473data IndexAliasSummary = IndexAliasSummary { indexAliasSummaryAlias :: IndexAlias
474− , indexAliasSummaryCreate :: IndexAliasCreate}
474+ , indexAliasSummaryCreate :: IndexAliasCreate} deriving (Show, Eq)
475475
476476{-| 'DocVersion' is an integer version number for a document between 1
477477and 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)
1414import Data.DeriveTH
1515import qualified Data.HashMap.Strict as HM
1616import Data.List (nub)
17+import qualified Data.List as L
1718import Data.List.NonEmpty (NonEmpty (..))
1819import qualified Data.List.NonEmpty as NE
1920import qualified Data.Map.Strict as M
@@ -981,6 +982,24 @@ main = hspec $ do
981982 liftIO $
982983 scan_search `shouldMatchList` [Just exampleTweet, Just otherTweet]
983984
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+
9841003 describe "JSON instances" $ do
9851004 propJSON (Proxy :: Proxy Version)
9861005 propJSON (Proxy :: Proxy IndexName)