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
|
||||
- bytestring >= 0.10
|
||||
- case-insensitive >= 1.2
|
||||
- containers >= 0.5
|
||||
- hspec >= 2.4
|
||||
- hspec-golden-aeson >= 0.2
|
||||
- rollbar-hs
|
||||
|
@ -7,6 +7,8 @@
|
||||
module Rollbar.Item.MissingHeaders.Test where
|
||||
|
||||
import Data.Aeson (Value(Object), decode', encode, toJSON)
|
||||
import Data.Functor (void)
|
||||
import Data.HashSet (HashSet)
|
||||
import Data.Text (Text)
|
||||
|
||||
import Prelude hiding (error)
|
||||
@ -16,9 +18,7 @@ import Rollbar.QuickCheck ()
|
||||
|
||||
import Test.QuickCheck (conjoin, quickCheck)
|
||||
|
||||
import Data.Set as S
|
||||
|
||||
import qualified Data.HashMap.Strict
|
||||
import qualified Data.HashSet
|
||||
|
||||
props :: IO ()
|
||||
props = do
|
||||
@ -39,53 +39,55 @@ props = do
|
||||
|
||||
prop_valueAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
||||
prop_valueAuthorizationIsRemoved hs =
|
||||
"Authorization" `S.notMember` actual
|
||||
"Authorization" `notMember` actual
|
||||
where
|
||||
actual = S.fromList (keys $ toJSON hs)
|
||||
actual = keys (toJSON hs)
|
||||
|
||||
prop_encodingAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
||||
prop_encodingAuthorizationIsRemoved hs =
|
||||
"Authorization" `S.notMember` actual
|
||||
"Authorization" `notMember` actual
|
||||
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 hs =
|
||||
"X-AccessToken" `S.notMember` actual
|
||||
"X-AccessToken" `notMember` actual
|
||||
where
|
||||
actual = S.fromList (keys $ toJSON hs)
|
||||
actual = keys (toJSON hs)
|
||||
|
||||
prop_encodingX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
|
||||
prop_encodingX_AccessTokenIsRemoved hs =
|
||||
"X-AccessToken" `S.notMember` actual
|
||||
"X-AccessToken" `notMember` actual
|
||||
where
|
||||
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
||||
actual = foldMap keys (decode' $ encode hs)
|
||||
|
||||
prop_valueAllHeadersAreRemoved
|
||||
:: MissingHeaders
|
||||
'["Authorization", "this is made up", "Server", "X-AccessToken"]
|
||||
-> Bool
|
||||
prop_valueAllHeadersAreRemoved hs =
|
||||
"Authorization" `S.notMember` actual
|
||||
&& "this is made up" `S.notMember` actual
|
||||
&& "Server" `S.notMember` actual
|
||||
&& "X-AccessToken" `S.notMember` actual
|
||||
"Authorization" `notMember` actual
|
||||
&& "this is made up" `notMember` actual
|
||||
&& "Server" `notMember` actual
|
||||
&& "X-AccessToken" `notMember` actual
|
||||
where
|
||||
actual = S.fromList (keys $ toJSON hs)
|
||||
actual = keys (toJSON hs)
|
||||
|
||||
prop_encodingAllHeadersAreRemoved
|
||||
:: MissingHeaders
|
||||
'["Authorization", "this is made up", "Server", "X-AccessToken"]
|
||||
-> Bool
|
||||
prop_encodingAllHeadersAreRemoved hs =
|
||||
"Authorization" `S.notMember` actual
|
||||
&& "this is made up" `S.notMember` actual
|
||||
&& "Server" `S.notMember` actual
|
||||
&& "X-AccessToken" `S.notMember` actual
|
||||
"Authorization" `notMember` actual
|
||||
&& "this is made up" `notMember` actual
|
||||
&& "Server" `notMember` actual
|
||||
&& "X-AccessToken" `notMember` actual
|
||||
where
|
||||
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
||||
actual = foldMap keys (decode' $ encode hs)
|
||||
|
||||
keys :: Value -> [Text]
|
||||
keys :: Value -> HashSet Text
|
||||
keys = \case
|
||||
Object o -> Data.HashMap.Strict.keys o
|
||||
Object o -> Data.HashSet.fromMap (void o)
|
||||
_ -> 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.CaseInsensitive (original)
|
||||
import Data.Foldable (fold)
|
||||
import Data.Functor (void)
|
||||
import Data.HashSet (HashSet)
|
||||
import Data.Text (Text)
|
||||
|
||||
import Prelude hiding (error)
|
||||
@ -16,10 +19,9 @@ import Rollbar.QuickCheck ()
|
||||
|
||||
import Test.QuickCheck (conjoin, quickCheck)
|
||||
|
||||
import Data.Set as S
|
||||
import Data.Text.Encoding as TE
|
||||
import qualified Data.Text.Encoding as TE
|
||||
|
||||
import qualified Data.HashMap.Strict
|
||||
import qualified Data.HashSet
|
||||
|
||||
props :: IO ()
|
||||
props =
|
||||
@ -30,19 +32,22 @@ props =
|
||||
|
||||
prop_valueHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
|
||||
prop_valueHeadersArentWrapped hs@(MissingHeaders rhs) =
|
||||
actual `S.isSubsetOf` expected
|
||||
actual `isSubsetOf` expected
|
||||
where
|
||||
actual = S.fromList (keys $ toJSON hs)
|
||||
expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
|
||||
actual = keys (toJSON hs)
|
||||
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 hs@(MissingHeaders rhs) =
|
||||
actual `S.isSubsetOf` expected
|
||||
actual `isSubsetOf` expected
|
||||
where
|
||||
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
||||
expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
|
||||
actual = foldMap keys (decode' $ encode hs)
|
||||
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
|
||||
Object o -> Data.HashMap.Strict.keys o
|
||||
Object o -> Data.HashSet.fromMap (void o)
|
||||
_ -> mempty
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user