mirror of
https://github.com/typeable/rollbar-hs.git
synced 2024-09-11 05:35:27 +03:00
Drop lens
and lens-aeson
We can do without these two things. It should make maintaining constraints easier and scratch builds quicker.
This commit is contained in:
parent
a78cb83998
commit
a797a33866
@ -39,10 +39,9 @@ tests:
|
|||||||
- containers >= 0.5
|
- 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,11 +1,9 @@
|
|||||||
{-# 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.Aeson (encode, toJSON)
|
|
||||||
import Data.Aeson.Lens (key, members)
|
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
|
||||||
import Rollbar.Item
|
import Rollbar.Item
|
||||||
@ -13,6 +11,8 @@ import Rollbar.QuickCheck ()
|
|||||||
|
|
||||||
import Test.QuickCheck (conjoin, quickCheck)
|
import Test.QuickCheck (conjoin, quickCheck)
|
||||||
|
|
||||||
|
import qualified Data.HashMap.Strict
|
||||||
|
|
||||||
props :: IO ()
|
props :: IO ()
|
||||||
props =
|
props =
|
||||||
quickCheck $ conjoin
|
quickCheck $ conjoin
|
||||||
@ -24,13 +24,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,14 +1,13 @@
|
|||||||
{-# 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.Text (Text)
|
||||||
import Data.Aeson (encode, toJSON)
|
|
||||||
import Data.Aeson.Lens (members)
|
|
||||||
|
|
||||||
import Prelude hiding (error)
|
import Prelude hiding (error)
|
||||||
|
|
||||||
@ -19,6 +18,8 @@ import Test.QuickCheck (conjoin, quickCheck)
|
|||||||
|
|
||||||
import Data.Set as S
|
import Data.Set as S
|
||||||
|
|
||||||
|
import qualified Data.HashMap.Strict
|
||||||
|
|
||||||
props :: IO ()
|
props :: IO ()
|
||||||
props = do
|
props = do
|
||||||
quickCheck $ conjoin
|
quickCheck $ conjoin
|
||||||
@ -40,25 +41,25 @@ prop_valueAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
|||||||
prop_valueAuthorizationIsRemoved hs =
|
prop_valueAuthorizationIsRemoved hs =
|
||||||
"Authorization" `S.notMember` actual
|
"Authorization" `S.notMember` actual
|
||||||
where
|
where
|
||||||
actual = toJSON hs ^@.. members & fmap fst & S.fromList
|
actual = S.fromList (keys $ toJSON hs)
|
||||||
|
|
||||||
prop_encodingAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
prop_encodingAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
|
||||||
prop_encodingAuthorizationIsRemoved hs =
|
prop_encodingAuthorizationIsRemoved hs =
|
||||||
"Authorization" `S.notMember` actual
|
"Authorization" `S.notMember` actual
|
||||||
where
|
where
|
||||||
actual = encode hs ^@.. members & fmap fst & S.fromList
|
actual = S.fromList (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" `S.notMember` actual
|
||||||
where
|
where
|
||||||
actual = toJSON hs ^@.. members & fmap fst & S.fromList
|
actual = S.fromList (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" `S.notMember` actual
|
||||||
where
|
where
|
||||||
actual = encode hs ^@.. members & fmap fst & S.fromList
|
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
||||||
|
|
||||||
prop_valueAllHeadersAreRemoved
|
prop_valueAllHeadersAreRemoved
|
||||||
:: MissingHeaders
|
:: MissingHeaders
|
||||||
@ -70,7 +71,7 @@ prop_valueAllHeadersAreRemoved hs =
|
|||||||
&& "Server" `S.notMember` actual
|
&& "Server" `S.notMember` actual
|
||||||
&& "X-AccessToken" `S.notMember` actual
|
&& "X-AccessToken" `S.notMember` actual
|
||||||
where
|
where
|
||||||
actual = toJSON hs ^@.. members & fmap fst & S.fromList
|
actual = S.fromList (keys $ toJSON hs)
|
||||||
|
|
||||||
prop_encodingAllHeadersAreRemoved
|
prop_encodingAllHeadersAreRemoved
|
||||||
:: MissingHeaders
|
:: MissingHeaders
|
||||||
@ -82,4 +83,9 @@ prop_encodingAllHeadersAreRemoved hs =
|
|||||||
&& "Server" `S.notMember` actual
|
&& "Server" `S.notMember` actual
|
||||||
&& "X-AccessToken" `S.notMember` actual
|
&& "X-AccessToken" `S.notMember` actual
|
||||||
where
|
where
|
||||||
actual = encode hs ^@.. members & fmap fst & S.fromList
|
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
||||||
|
|
||||||
|
keys :: Value -> [Text]
|
||||||
|
keys = \case
|
||||||
|
Object o -> Data.HashMap.Strict.keys o
|
||||||
|
_ -> mempty
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
{-# 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.Aeson (encode, toJSON)
|
|
||||||
import Data.Aeson.Lens (members)
|
|
||||||
import Data.CaseInsensitive (original)
|
import Data.CaseInsensitive (original)
|
||||||
|
import Data.Text (Text)
|
||||||
|
|
||||||
import Prelude hiding (error)
|
import Prelude hiding (error)
|
||||||
|
|
||||||
@ -20,6 +19,8 @@ import Test.QuickCheck (conjoin, quickCheck)
|
|||||||
import Data.Set as S
|
import Data.Set as S
|
||||||
import Data.Text.Encoding as TE
|
import Data.Text.Encoding as TE
|
||||||
|
|
||||||
|
import qualified Data.HashMap.Strict
|
||||||
|
|
||||||
props :: IO ()
|
props :: IO ()
|
||||||
props =
|
props =
|
||||||
quickCheck $ conjoin
|
quickCheck $ conjoin
|
||||||
@ -31,12 +32,17 @@ prop_valueHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
|
|||||||
prop_valueHeadersArentWrapped hs@(MissingHeaders rhs) =
|
prop_valueHeadersArentWrapped hs@(MissingHeaders rhs) =
|
||||||
actual `S.isSubsetOf` expected
|
actual `S.isSubsetOf` expected
|
||||||
where
|
where
|
||||||
actual = toJSON hs ^@.. members & fmap fst & S.fromList
|
actual = S.fromList (keys $ toJSON hs)
|
||||||
expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
|
expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
|
||||||
|
|
||||||
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 `S.isSubsetOf` expected
|
||||||
where
|
where
|
||||||
actual = encode hs ^@.. members & fmap fst & S.fromList
|
actual = S.fromList (foldMap keys $ decode' $ encode hs)
|
||||||
expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
|
expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
|
||||||
|
|
||||||
|
keys :: Value -> [Text]
|
||||||
|
keys = \case
|
||||||
|
Object o -> Data.HashMap.Strict.keys o
|
||||||
|
_ -> mempty
|
||||||
|
Loading…
Reference in New Issue
Block a user