mirror of
https://github.com/typeable/rollbar-hs.git
synced 2024-08-15 16:50:25 +03:00
Merge pull request #12 from joneshf/drop-dependencies
Drop dependencies
This commit is contained in:
commit
2ff6701ddf
@ -36,13 +36,11 @@ tests:
|
||||
- base >= 4.9
|
||||
- bytestring >= 0.10
|
||||
- case-insensitive >= 1.2
|
||||
- containers >= 0.5
|
||||
- hspec >= 2.4
|
||||
- hspec-golden-aeson >= 0.2
|
||||
- lens >= 4.15
|
||||
- lens-aeson >= 1.0
|
||||
- rollbar-hs
|
||||
- text >= 1.2
|
||||
- unordered-containers >= 0.2
|
||||
main: Main.hs
|
||||
source-dirs: test
|
||||
version: '0.3.0.1'
|
||||
|
@ -1,17 +1,18 @@
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Rollbar.Item.Data.Test where
|
||||
|
||||
import Control.Lens ((^@..))
|
||||
import Data.Aeson (Value (Null, Object), decode', encode,
|
||||
toJSON)
|
||||
import Data.Text (Text)
|
||||
|
||||
import Data.Aeson (encode, toJSON)
|
||||
import Data.Aeson.Lens (key, members)
|
||||
import Data.Text (Text)
|
||||
import Rollbar.Item
|
||||
import Rollbar.QuickCheck ()
|
||||
|
||||
import Rollbar.Item
|
||||
import Rollbar.QuickCheck ()
|
||||
import Test.QuickCheck (conjoin, quickCheck)
|
||||
|
||||
import Test.QuickCheck (conjoin, quickCheck)
|
||||
import qualified Data.HashMap.Strict
|
||||
|
||||
props :: IO ()
|
||||
props =
|
||||
@ -24,13 +25,20 @@ prop_valueDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
|
||||
prop_valueDataBodyHasRequiredKey x =
|
||||
length ms == 1 && fst (head ms) `elem` requiredBodyKeys
|
||||
where
|
||||
ms = toJSON x ^@.. key "body" . members
|
||||
ms = key "body" (toJSON x)
|
||||
|
||||
prop_encodingDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
|
||||
prop_encodingDataBodyHasRequiredKey x =
|
||||
length ms == 1 && fst (head ms) `elem` requiredBodyKeys
|
||||
where
|
||||
ms = encode x ^@.. key "body" . members
|
||||
ms = foldMap (key "body") (decode' $ encode x)
|
||||
|
||||
requiredBodyKeys :: [Text]
|
||||
requiredBodyKeys = ["trace", "trace_chain", "message", "crash_report"]
|
||||
|
||||
key :: Text -> Value -> [(Text, Value)]
|
||||
key k = \case
|
||||
Object o -> case Data.HashMap.Strict.lookupDefault Null k o of
|
||||
Object o -> Data.HashMap.Strict.toList o
|
||||
_ -> mempty
|
||||
_ -> mempty
|
||||
|
@ -1,23 +1,25 @@
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
module Rollbar.Item.MissingHeaders.Test where
|
||||
|
||||
import Control.Lens ((&), (^@..))
|
||||
import Data.Aeson (Value (Object), decode', encode,
|
||||
toJSON)
|
||||
import Data.Functor (void)
|
||||
import Data.HashSet (HashSet)
|
||||
import Data.Text (Text)
|
||||
|
||||
import Data.Aeson (encode, toJSON)
|
||||
import Data.Aeson.Lens (members)
|
||||
import Prelude hiding (error)
|
||||
|
||||
import Prelude hiding (error)
|
||||
import Rollbar.Item.MissingHeaders (MissingHeaders (..))
|
||||
import Rollbar.QuickCheck ()
|
||||
|
||||
import Rollbar.Item.MissingHeaders (MissingHeaders(..))
|
||||
import Rollbar.QuickCheck ()
|
||||
import Test.QuickCheck (conjoin, quickCheck)
|
||||
|
||||
import Test.QuickCheck (conjoin, quickCheck)
|
||||
|
||||
import Data.Set as S
|
||||
import qualified Data.HashSet
|
||||
|
||||
props :: IO ()
|
||||
props = do
|
||||
@ -38,48 +40,55 @@ props = do
|
||||
|
||||
prop_valueAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
||||
prop_valueAuthorizationIsRemoved hs =
|
||||
"Authorization" `S.notMember` actual
|
||||
"Authorization" `notMember` actual
|
||||
where
|
||||
actual = toJSON hs ^@.. members & fmap fst & S.fromList
|
||||
actual = keys (toJSON hs)
|
||||
|
||||
prop_encodingAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
||||
prop_encodingAuthorizationIsRemoved hs =
|
||||
"Authorization" `S.notMember` actual
|
||||
"Authorization" `notMember` actual
|
||||
where
|
||||
actual = encode hs ^@.. members & fmap fst & S.fromList
|
||||
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 = toJSON hs ^@.. members & fmap fst & S.fromList
|
||||
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 = encode hs ^@.. members & fmap fst & S.fromList
|
||||
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 = toJSON hs ^@.. members & fmap fst & S.fromList
|
||||
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 = encode hs ^@.. members & fmap fst & S.fromList
|
||||
actual = foldMap keys (decode' $ encode hs)
|
||||
|
||||
keys :: Value -> HashSet Text
|
||||
keys = \case
|
||||
Object o -> Data.HashSet.fromMap (void o)
|
||||
_ -> mempty
|
||||
|
||||
notMember x = not . Data.HashSet.member x
|
||||
|
@ -1,24 +1,27 @@
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
module Rollbar.Item.Request.Test where
|
||||
|
||||
import Control.Lens ((&), (^@..))
|
||||
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 Data.Aeson (encode, toJSON)
|
||||
import Data.Aeson.Lens (members)
|
||||
import Data.CaseInsensitive (original)
|
||||
import Prelude hiding (error)
|
||||
|
||||
import Prelude hiding (error)
|
||||
import Rollbar.Item.Request (MissingHeaders (..))
|
||||
import Rollbar.QuickCheck ()
|
||||
|
||||
import Rollbar.Item.Request (MissingHeaders(..))
|
||||
import Rollbar.QuickCheck ()
|
||||
import Test.QuickCheck (conjoin, quickCheck)
|
||||
|
||||
import Test.QuickCheck (conjoin, quickCheck)
|
||||
import qualified Data.Text.Encoding as TE
|
||||
|
||||
import Data.Set as S
|
||||
import Data.Text.Encoding as TE
|
||||
import qualified Data.HashSet
|
||||
|
||||
props :: IO ()
|
||||
props =
|
||||
@ -29,14 +32,22 @@ props =
|
||||
|
||||
prop_valueHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
|
||||
prop_valueHeadersArentWrapped hs@(MissingHeaders rhs) =
|
||||
actual `S.isSubsetOf` expected
|
||||
actual `isSubsetOf` expected
|
||||
where
|
||||
actual = toJSON hs ^@.. members & fmap fst & S.fromList
|
||||
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 = encode hs ^@.. members & fmap fst & S.fromList
|
||||
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 -> HashSet Text
|
||||
keys = \case
|
||||
Object o -> Data.HashSet.fromMap (void o)
|
||||
_ -> mempty
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user