packages feed

otel-effectful-1.0.0: test/Effectful/OpenTelemetry/Protocol/ExceptionSpec.hs

module Effectful.OpenTelemetry.Protocol.ExceptionSpec where

import Control.Exception (throwIO, try)
import Data.Either (isLeft)
import Effectful
import Effectful.Dispatch.Static (unsafeEff_)
import Effectful.Hspec (Hspec, it, shouldReturn, shouldSatisfy)
import Effectful.OpenTelemetry.Protocol.Environment (ConfigError (..))
import Effectful.OpenTelemetry.Protocol.Exception
import Prelude

spec :: (Hspec :> es) => Eff es ()
spec = do
    it "catch wrapped exception" $
        unsafeEff_
            ( try @ConfigError @()
                ( throwIO
                    . SomeOTLPException
                    . UnsupportedOTLPCompression
                    $ "foo"
                )
            )
            `shouldReturn` Left (UnsupportedOTLPCompression "foo")
    it "catch wrapper exception" $ do
        result <-
            unsafeEff_
                . try @SomeOTLPException @()
                . throwIO
                . SomeOTLPException
                . UnsupportedOTLPCompression
                $ "foo"
        result `shouldSatisfy` isLeft