git.iko.soy/typeable/rollbar-hs
on master help sign in
Drop `lens` and `lens-aeson`
a797a33joneshf
package.yaml+1−2
@@ -39,10 +39,9 @@ tests:
39 - containers >= 0.5
39 - containers >= 0.5
40 - hspec >= 2.4
40 - hspec >= 2.4
41 - hspec-golden-aeson >= 0.2
41 - hspec-golden-aeson >= 0.2
42− - lens >= 4.15
43− - lens-aeson >= 1.0
44 - rollbar-hs
42 - rollbar-hs
45 - text >= 1.2
43 - text >= 1.2
44+ - unordered-containers >= 0.2
46 main: Main.hs
45 main: Main.hs
47 source-dirs: test
46 source-dirs: test
48version: '0.3.0.1'
47version: '0.3.0.1'
test/Rollbar/Item/Data/Test.hs+13−6
@@ -1,11 +1,9 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
3module Rollbar.Item.Data.Test where
4module Rollbar.Item.Data.Test where
4
5
5−import Control.Lens ((^@..))
6−
7−import Data.Aeson (encode, toJSON)
6+import Data.Aeson (Value(Null, Object), decode', encode, toJSON)
8−import Data.Aeson.Lens (key, members)
9import Data.Text (Text)
7import Data.Text (Text)
10
8
11import Rollbar.Item
9import Rollbar.Item
@@ -13,6 +11,8 @@ import Rollbar.QuickCheck ()
13
11
14import Test.QuickCheck (conjoin, quickCheck)
12import Test.QuickCheck (conjoin, quickCheck)
15
13
14+import qualified Data.HashMap.Strict
15+
16props :: IO ()
16props :: IO ()
17props =
17props =
18 quickCheck $ conjoin
18 quickCheck $ conjoin
@@ -24,13 +24,20 @@ prop_valueDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
24prop_valueDataBodyHasRequiredKey x =
24prop_valueDataBodyHasRequiredKey x =
25 length ms == 1 && fst (head ms) `elem` requiredBodyKeys
25 length ms == 1 && fst (head ms) `elem` requiredBodyKeys
26 where
26 where
27− ms = toJSON x ^@.. key "body" . members
27+ ms = key "body" (toJSON x)
28
28
29prop_encodingDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
29prop_encodingDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
30prop_encodingDataBodyHasRequiredKey x =
30prop_encodingDataBodyHasRequiredKey x =
31 length ms == 1 && fst (head ms) `elem` requiredBodyKeys
31 length ms == 1 && fst (head ms) `elem` requiredBodyKeys
32 where
32 where
33− ms = encode x ^@.. key "body" . members
33+ ms = foldMap (key "body") (decode' $ encode x)
34
34
35requiredBodyKeys :: [Text]
35requiredBodyKeys :: [Text]
36requiredBodyKeys = ["trace", "trace_chain", "message", "crash_report"]
36requiredBodyKeys = ["trace", "trace_chain", "message", "crash_report"]
37+
38+key :: Text -> Value -> [(Text, Value)]
39+key k = \case
40+ Object o -> case Data.HashMap.Strict.lookupDefault Null k o of
41+ Object o -> Data.HashMap.Strict.toList o
42+ _ -> mempty
43+ _ -> mempty
test/Rollbar/Item/MissingHeaders/Test.hs+16−10
@@ -1,14 +1,13 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE LambdaCase #-}
4{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE TypeOperators #-}
6{-# LANGUAGE TypeOperators #-}
6module Rollbar.Item.MissingHeaders.Test where
7module Rollbar.Item.MissingHeaders.Test where
7
8
8−import Control.Lens ((&), (^@..))
9+import Data.Aeson (Value(Object), decode', encode, toJSON)
9−
10−import Data.Aeson (encode, toJSON)
11−import Data.Aeson.Lens (members)
10+import Data.Text (Text)
12
11
13import Prelude hiding (error)
12import Prelude hiding (error)
14
13
@@ -19,6 +18,8 @@ import Test.QuickCheck (conjoin, quickCheck)
19
18
20import Data.Set as S
19import Data.Set as S
21
20
21+import qualified Data.HashMap.Strict
22+
22props :: IO ()
23props :: IO ()
23props = do
24props = do
24 quickCheck $ conjoin
25 quickCheck $ conjoin
@@ -40,25 +41,25 @@ prop_valueAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
40prop_valueAuthorizationIsRemoved hs =
41prop_valueAuthorizationIsRemoved hs =
41 "Authorization" `S.notMember` actual
42 "Authorization" `S.notMember` actual
42 where
43 where
43− actual = toJSON hs ^@.. members & fmap fst & S.fromList
44+ actual = S.fromList (keys $ toJSON hs)
44
45
45prop_encodingAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
46prop_encodingAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
46prop_encodingAuthorizationIsRemoved hs =
47prop_encodingAuthorizationIsRemoved hs =
47 "Authorization" `S.notMember` actual
48 "Authorization" `S.notMember` actual
48 where
49 where
49− actual = encode hs ^@.. members & fmap fst & S.fromList
50+ actual = S.fromList (foldMap keys $ decode' $ encode hs)
50
51
51prop_valueX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
52prop_valueX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
52prop_valueX_AccessTokenIsRemoved hs =
53prop_valueX_AccessTokenIsRemoved hs =
53 "X-AccessToken" `S.notMember` actual
54 "X-AccessToken" `S.notMember` actual
54 where
55 where
55− actual = toJSON hs ^@.. members & fmap fst & S.fromList
56+ actual = S.fromList (keys $ toJSON hs)
56
57
57prop_encodingX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
58prop_encodingX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
58prop_encodingX_AccessTokenIsRemoved hs =
59prop_encodingX_AccessTokenIsRemoved hs =
59 "X-AccessToken" `S.notMember` actual
60 "X-AccessToken" `S.notMember` actual
60 where
61 where
61− actual = encode hs ^@.. members & fmap fst & S.fromList
62+ actual = S.fromList (foldMap keys $ decode' $ encode hs)
62
63
63prop_valueAllHeadersAreRemoved
64prop_valueAllHeadersAreRemoved
64 :: MissingHeaders
65 :: MissingHeaders
@@ -70,7 +71,7 @@ prop_valueAllHeadersAreRemoved hs =
70 && "Server" `S.notMember` actual
71 && "Server" `S.notMember` actual
71 && "X-AccessToken" `S.notMember` actual
72 && "X-AccessToken" `S.notMember` actual
72 where
73 where
73− actual = toJSON hs ^@.. members & fmap fst & S.fromList
74+ actual = S.fromList (keys $ toJSON hs)
74
75
75prop_encodingAllHeadersAreRemoved
76prop_encodingAllHeadersAreRemoved
76 :: MissingHeaders
77 :: MissingHeaders
@@ -82,4 +83,9 @@ prop_encodingAllHeadersAreRemoved hs =
82 && "Server" `S.notMember` actual
83 && "Server" `S.notMember` actual
83 && "X-AccessToken" `S.notMember` actual
84 && "X-AccessToken" `S.notMember` actual
84 where
85 where
85− actual = encode hs ^@.. members & fmap fst & S.fromList
86+ actual = S.fromList (foldMap keys $ decode' $ encode hs)
87+
88+keys :: Value -> [Text]
89+keys = \case
90+ Object o -> Data.HashMap.Strict.keys o
91+ _ -> mempty
test/Rollbar/Item/Request/Test.hs+12−6
@@ -1,14 +1,13 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FlexibleInstances #-}
3+{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE TypeOperators #-}
5{-# LANGUAGE TypeOperators #-}
5module Rollbar.Item.Request.Test where
6module Rollbar.Item.Request.Test where
6
7
7−import Control.Lens ((&), (^@..))
8−
9−import Data.Aeson (encode, toJSON)
8+import Data.Aeson (Value(Object), decode', encode, toJSON)
10−import Data.Aeson.Lens (members)
11import Data.CaseInsensitive (original)
9import Data.CaseInsensitive (original)
10+import Data.Text (Text)
12
11
13import Prelude hiding (error)
12import Prelude hiding (error)
14
13
@@ -20,6 +19,8 @@ import Test.QuickCheck (conjoin, quickCheck)
20import Data.Set as S
19import Data.Set as S
21import Data.Text.Encoding as TE
20import Data.Text.Encoding as TE
22
21
22+import qualified Data.HashMap.Strict
23+
23props :: IO ()
24props :: IO ()
24props =
25props =
25 quickCheck $ conjoin
26 quickCheck $ conjoin
@@ -31,12 +32,17 @@ prop_valueHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
31prop_valueHeadersArentWrapped hs@(MissingHeaders rhs) =
32prop_valueHeadersArentWrapped hs@(MissingHeaders rhs) =
32 actual `S.isSubsetOf` expected
33 actual `S.isSubsetOf` expected
33 where
34 where
34− actual = toJSON hs ^@.. members & fmap fst & S.fromList
35+ actual = S.fromList (keys $ toJSON hs)
35 expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
36 expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
36
37
37prop_encodingHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
38prop_encodingHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
38prop_encodingHeadersArentWrapped hs@(MissingHeaders rhs) =
39prop_encodingHeadersArentWrapped hs@(MissingHeaders rhs) =
39 actual `S.isSubsetOf` expected
40 actual `S.isSubsetOf` expected
40 where
41 where
41− actual = encode hs ^@.. members & fmap fst & S.fromList
42+ actual = S.fromList (foldMap keys $ decode' $ encode hs)
42 expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
43 expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
44+
45+keys :: Value -> [Text]
46+keys = \case
47+ Object o -> Data.HashMap.Strict.keys o
48+ _ -> mempty