mirror of
https://github.com/typeable/rollbar-hs.git
synced 2024-09-11 05:35:27 +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
|
- 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
|
||||||
- lens >= 4.15
|
|
||||||
- lens-aeson >= 1.0
|
|
||||||
- rollbar-hs
|
- rollbar-hs
|
||||||
- text >= 1.2
|
- text >= 1.2
|
||||||
|
- unordered-containers >= 0.2
|
||||||
main: Main.hs
|
main: Main.hs
|
||||||
source-dirs: test
|
source-dirs: test
|
||||||
version: '0.3.0.1'
|
version: '0.3.0.1'
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
module Rollbar.Item.Data.Test where
|
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 Rollbar.Item
|
||||||
import Data.Aeson.Lens (key, members)
|
import Rollbar.QuickCheck ()
|
||||||
import Data.Text (Text)
|
|
||||||
|
|
||||||
import Rollbar.Item
|
import Test.QuickCheck (conjoin, quickCheck)
|
||||||
import Rollbar.QuickCheck ()
|
|
||||||
|
|
||||||
import Test.QuickCheck (conjoin, quickCheck)
|
import qualified Data.HashMap.Strict
|
||||||
|
|
||||||
props :: IO ()
|
props :: IO ()
|
||||||
props =
|
props =
|
||||||
@ -24,13 +25,20 @@ prop_valueDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
|
|||||||
prop_valueDataBodyHasRequiredKey x =
|
prop_valueDataBodyHasRequiredKey x =
|
||||||
length ms == 1 && fst (head ms) `elem` requiredBodyKeys
|
length ms == 1 && fst (head ms) `elem` requiredBodyKeys
|
||||||
where
|
where
|
||||||
ms = toJSON x ^@.. key "body" . members
|
ms = key "body" (toJSON x)
|
||||||
|
|
||||||
prop_encodingDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
|
prop_encodingDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
|
||||||
prop_encodingDataBodyHasRequiredKey x =
|
prop_encodingDataBodyHasRequiredKey x =
|
||||||
length ms == 1 && fst (head ms) `elem` requiredBodyKeys
|
length ms == 1 && fst (head ms) `elem` requiredBodyKeys
|
||||||
where
|
where
|
||||||
ms = encode x ^@.. key "body" . members
|
ms = foldMap (key "body") (decode' $ encode x)
|
||||||
|
|
||||||
requiredBodyKeys :: [Text]
|
requiredBodyKeys :: [Text]
|
||||||
requiredBodyKeys = ["trace", "trace_chain", "message", "crash_report"]
|
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 DataKinds #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
module Rollbar.Item.MissingHeaders.Test where
|
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 Prelude hiding (error)
|
||||||
import Data.Aeson.Lens (members)
|
|
||||||
|
|
||||||
import Prelude hiding (error)
|
import Rollbar.Item.MissingHeaders (MissingHeaders (..))
|
||||||
|
import Rollbar.QuickCheck ()
|
||||||
|
|
||||||
import Rollbar.Item.MissingHeaders (MissingHeaders(..))
|
import Test.QuickCheck (conjoin, quickCheck)
|
||||||
import Rollbar.QuickCheck ()
|
|
||||||
|
|
||||||
import Test.QuickCheck (conjoin, quickCheck)
|
import qualified Data.HashSet
|
||||||
|
|
||||||
import Data.Set as S
|
|
||||||
|
|
||||||
props :: IO ()
|
props :: IO ()
|
||||||
props = do
|
props = do
|
||||||
@ -38,48 +40,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 = toJSON hs ^@.. members & fmap fst & S.fromList
|
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 = encode hs ^@.. members & fmap fst & S.fromList
|
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 = toJSON hs ^@.. members & fmap fst & S.fromList
|
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 = encode hs ^@.. members & fmap fst & S.fromList
|
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 = toJSON hs ^@.. members & fmap fst & S.fromList
|
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 = 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 FlexibleInstances #-}
|
||||||
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
module Rollbar.Item.Request.Test where
|
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 Prelude hiding (error)
|
||||||
import Data.Aeson.Lens (members)
|
|
||||||
import Data.CaseInsensitive (original)
|
|
||||||
|
|
||||||
import Prelude hiding (error)
|
import Rollbar.Item.Request (MissingHeaders (..))
|
||||||
|
import Rollbar.QuickCheck ()
|
||||||
|
|
||||||
import Rollbar.Item.Request (MissingHeaders(..))
|
import Test.QuickCheck (conjoin, quickCheck)
|
||||||
import Rollbar.QuickCheck ()
|
|
||||||
|
|
||||||
import Test.QuickCheck (conjoin, quickCheck)
|
import qualified Data.Text.Encoding as TE
|
||||||
|
|
||||||
import Data.Set as S
|
import qualified Data.HashSet
|
||||||
import Data.Text.Encoding as TE
|
|
||||||
|
|
||||||
props :: IO ()
|
props :: IO ()
|
||||||
props =
|
props =
|
||||||
@ -29,14 +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 = toJSON hs ^@.. members & fmap fst & S.fromList
|
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 = encode hs ^@.. members & fmap fst & S.fromList
|
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 -> HashSet Text
|
||||||
|
keys = \case
|
||||||
|
Object o -> Data.HashSet.fromMap (void o)
|
||||||
|
_ -> mempty
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user