bloodhound-1.0.0.0: tests/Test/FreezeIndexSpec.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns -Wno-warnings-deprecations #-}
module Test.FreezeIndexSpec (spec) where
import Data.ByteString.Lazy qualified as LBS
import Database.Bloodhound.ElasticSearch7.Requests qualified as Requests
import TestsUtils.Common
import TestsUtils.Import
-- | Freeze/unfreeze return the standard @_shards@ envelope.
sampleShardsBytes :: LBS.ByteString
sampleShardsBytes =
"{\"_shards\":{\"total\":2,\"successful\":2,\"skipped\":0,\"failed\":0}}"
spec :: Spec
spec = do
-- ------------------------------------------------------------------ --
-- Pure JSON decoder tests (no ES required). --
-- ------------------------------------------------------------------ --
describe "ShardsResult decoding (freeze/unfreeze envelope)" $ do
it "decodes the {_shards} envelope returned by _freeze/_unfreeze" $ do
let Just (ShardsResult sr) = decode sampleShardsBytes :: Maybe ShardsResult
shardTotal sr `shouldBe` 2
shardsSuccessful sr `shouldBe` 2
shardsFailed sr `shouldBe` 0
-- ------------------------------------------------------------------ --
-- Endpoint shape (BHRequest, no ES required). --
-- ------------------------------------------------------------------ --
describe "freezeIndex endpoint shape" $ do
let idx = [qqIndexName|my-idx|]
it "POSTs /{index}/_freeze with an empty body" $ do
let req = Requests.freezeIndex idx
bhRequestMethod req `shouldBe` "POST"
getRawEndpoint (bhRequestEndpoint req)
`shouldBe` ["my-idx", "_freeze"]
bhRequestBody req `shouldBe` Just ""
describe "unfreezeIndex endpoint shape" $ do
let idx = [qqIndexName|my-idx|]
it "POSTs /{index}/_unfreeze with an empty body" $ do
let req = Requests.unfreezeIndex idx
bhRequestMethod req `shouldBe` "POST"
getRawEndpoint (bhRequestEndpoint req)
`shouldBe` ["my-idx", "_unfreeze"]
bhRequestBody req `shouldBe` Just ""