mirror of
https://github.com/typeable/rollbar-hs.git
synced 2024-09-11 05:35:27 +03:00
Simplify tests
We can eschew the conversions if we stay with `unordered-containers`. It's semantically the same. Also, we can drop `containers` as a dependency!
This commit is contained in:
parent
a797a33866
commit
f240812a64
@ -36,7 +36,6 @@ tests:
|
|||||||
- base >= 4.9
|
- base >= 4.9
|
||||||
- bytestring >= 0.10
|
- bytestring >= 0.10
|
||||||
- case-insensitive >= 1.2
|
- case-insensitive >= 1.2
|
||||||
- containers >= 0.5
|
|
||||||
- hspec >= 2.4
|
- hspec >= 2.4
|
||||||
- hspec-golden-aeson >= 0.2
|
- hspec-golden-aeson >= 0.2
|
||||||
- rollbar-hs
|
- rollbar-hs
|
||||||
|
@ -6,8 +6,10 @@
|
|||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
module Rollbar.Item.MissingHeaders.Test where
|
module Rollbar.Item.MissingHeaders.Test where
|
||||||
|
|
||||||
import Data.Aeson (Value(Object), decode', encode, toJSON)
|
import Data.Aeson (Value(Object), decode', encode, toJSON)
|
||||||
import Data.Text (Text)
|
import Data.Functor (void)
|
||||||
|
import Data.HashSet (HashSet)
|
||||||
|
import Data.Text (Text)
|
||||||
|
|
||||||
import Prelude hiding (error)
|
import Prelude hiding (error)
|
||||||
|
|
||||||
@ -16,9 +18,7 @@ import Rollbar.QuickCheck ()
|
|||||||
|
|
||||||
import Test.QuickCheck (conjoin, quickCheck)
|
import Test.QuickCheck (conjoin, quickCheck)
|
||||||
|
|
||||||
import Data.Set as S
|
import qualified Data.HashSet
|
||||||
|
|
||||||
import qualified Data.HashMap.Strict
|
|
||||||
|
|
||||||
props :: IO ()
|
props :: IO ()
|
||||||
props = do
|
props = do
|
||||||
@ -39,53 +39,55 @@ props = do
|
|||||||
|
|
||||||
prop_valueAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
prop_valueAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
||||||
prop_valueAuthorizationIsRemoved hs =
|
prop_valueAuthorizationIsRemoved hs =
|
||||||
"Authorization" `S.notMember` actual
|
"Authorization" `notMember` actual
|
||||||
where
|
where
|
||||||
actual = S.fromList (keys $ toJSON hs)
|
actual = keys (toJSON hs)
|
||||||
|
|
||||||
prop_encodingAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
prop_encodingAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
||||||
prop_encodingAuthorizationIsRemoved hs =
|
prop_encodingAuthorizationIsRemoved hs =
|
||||||
"Authorization" `S.notMember` actual
|
"Authorization" `notMember` actual
|
||||||
where
|
where
|
||||||
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
actual = foldMap keys (decode' $ encode hs)
|
||||||
|
|
||||||
prop_valueX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
|
prop_valueX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
|
||||||
prop_valueX_AccessTokenIsRemoved hs =
|
prop_valueX_AccessTokenIsRemoved hs =
|
||||||
"X-AccessToken" `S.notMember` actual
|
"X-AccessToken" `notMember` actual
|
||||||
where
|
where
|
||||||
actual = S.fromList (keys $ toJSON hs)
|
actual = keys (toJSON hs)
|
||||||
|
|
||||||
prop_encodingX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
|
prop_encodingX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
|
||||||
prop_encodingX_AccessTokenIsRemoved hs =
|
prop_encodingX_AccessTokenIsRemoved hs =
|
||||||
"X-AccessToken" `S.notMember` actual
|
"X-AccessToken" `notMember` actual
|
||||||
where
|
where
|
||||||
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
actual = foldMap keys (decode' $ encode hs)
|
||||||
|
|
||||||
prop_valueAllHeadersAreRemoved
|
prop_valueAllHeadersAreRemoved
|
||||||
:: MissingHeaders
|
:: MissingHeaders
|
||||||
'["Authorization", "this is made up", "Server", "X-AccessToken"]
|
'["Authorization", "this is made up", "Server", "X-AccessToken"]
|
||||||
-> Bool
|
-> Bool
|
||||||
prop_valueAllHeadersAreRemoved hs =
|
prop_valueAllHeadersAreRemoved hs =
|
||||||
"Authorization" `S.notMember` actual
|
"Authorization" `notMember` actual
|
||||||
&& "this is made up" `S.notMember` actual
|
&& "this is made up" `notMember` actual
|
||||||
&& "Server" `S.notMember` actual
|
&& "Server" `notMember` actual
|
||||||
&& "X-AccessToken" `S.notMember` actual
|
&& "X-AccessToken" `notMember` actual
|
||||||
where
|
where
|
||||||
actual = S.fromList (keys $ toJSON hs)
|
actual = keys (toJSON hs)
|
||||||
|
|
||||||
prop_encodingAllHeadersAreRemoved
|
prop_encodingAllHeadersAreRemoved
|
||||||
:: MissingHeaders
|
:: MissingHeaders
|
||||||
'["Authorization", "this is made up", "Server", "X-AccessToken"]
|
'["Authorization", "this is made up", "Server", "X-AccessToken"]
|
||||||
-> Bool
|
-> Bool
|
||||||
prop_encodingAllHeadersAreRemoved hs =
|
prop_encodingAllHeadersAreRemoved hs =
|
||||||
"Authorization" `S.notMember` actual
|
"Authorization" `notMember` actual
|
||||||
&& "this is made up" `S.notMember` actual
|
&& "this is made up" `notMember` actual
|
||||||
&& "Server" `S.notMember` actual
|
&& "Server" `notMember` actual
|
||||||
&& "X-AccessToken" `S.notMember` actual
|
&& "X-AccessToken" `notMember` actual
|
||||||
where
|
where
|
||||||
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
actual = foldMap keys (decode' $ encode hs)
|
||||||
|
|
||||||
keys :: Value -> [Text]
|
keys :: Value -> HashSet Text
|
||||||
keys = \case
|
keys = \case
|
||||||
Object o -> Data.HashMap.Strict.keys o
|
Object o -> Data.HashSet.fromMap (void o)
|
||||||
_ -> mempty
|
_ -> mempty
|
||||||
|
|
||||||
|
notMember x = not . Data.HashSet.member x
|
||||||
|
@ -7,6 +7,9 @@ module Rollbar.Item.Request.Test where
|
|||||||
|
|
||||||
import Data.Aeson (Value(Object), decode', encode, toJSON)
|
import Data.Aeson (Value(Object), decode', encode, toJSON)
|
||||||
import Data.CaseInsensitive (original)
|
import Data.CaseInsensitive (original)
|
||||||
|
import Data.Foldable (fold)
|
||||||
|
import Data.Functor (void)
|
||||||
|
import Data.HashSet (HashSet)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
|
||||||
import Prelude hiding (error)
|
import Prelude hiding (error)
|
||||||
@ -16,10 +19,9 @@ import Rollbar.QuickCheck ()
|
|||||||
|
|
||||||
import Test.QuickCheck (conjoin, quickCheck)
|
import Test.QuickCheck (conjoin, quickCheck)
|
||||||
|
|
||||||
import Data.Set as S
|
import qualified Data.Text.Encoding as TE
|
||||||
import Data.Text.Encoding as TE
|
|
||||||
|
|
||||||
import qualified Data.HashMap.Strict
|
import qualified Data.HashSet
|
||||||
|
|
||||||
props :: IO ()
|
props :: IO ()
|
||||||
props =
|
props =
|
||||||
@ -30,19 +32,22 @@ props =
|
|||||||
|
|
||||||
prop_valueHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
|
prop_valueHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
|
||||||
prop_valueHeadersArentWrapped hs@(MissingHeaders rhs) =
|
prop_valueHeadersArentWrapped hs@(MissingHeaders rhs) =
|
||||||
actual `S.isSubsetOf` expected
|
actual `isSubsetOf` expected
|
||||||
where
|
where
|
||||||
actual = S.fromList (keys $ toJSON hs)
|
actual = keys (toJSON hs)
|
||||||
expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
|
expected = Data.HashSet.fromList $ fold . TE.decodeUtf8' . original . fst <$> rhs
|
||||||
|
isSubsetOf x y = Data.HashSet.difference x y == mempty
|
||||||
|
|
||||||
prop_encodingHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
|
prop_encodingHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
|
||||||
prop_encodingHeadersArentWrapped hs@(MissingHeaders rhs) =
|
prop_encodingHeadersArentWrapped hs@(MissingHeaders rhs) =
|
||||||
actual `S.isSubsetOf` expected
|
actual `isSubsetOf` expected
|
||||||
where
|
where
|
||||||
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
actual = foldMap keys (decode' $ encode hs)
|
||||||
expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
|
expected = Data.HashSet.fromList $ fold . TE.decodeUtf8' . original . fst <$> rhs
|
||||||
|
isSubsetOf x y = Data.HashSet.difference x y == mempty
|
||||||
|
|
||||||
keys :: Value -> [Text]
|
keys :: Value -> HashSet Text
|
||||||
keys = \case
|
keys = \case
|
||||||
Object o -> Data.HashMap.Strict.keys o
|
Object o -> Data.HashSet.fromMap (void o)
|
||||||
_ -> mempty
|
_ -> mempty
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user