git.iko.soy/typeable/rollbar-hs
on master help sign in
Drop `lens` and `lens-aeson`

We can do without these two things. It should make maintaining constraints easier and scratch builds quicker.

commita797a338668b6d6011ef805ad836d49f726dd53b authorjoneshf <jones3.hardy@gmail.com> dateSun 29 Jul 2018, 18:58 (8 years ago) parenta78cb83
4 files changed+42−24
package.yaml+1−2 test/Rollbar/Item/Data/Test.hs+13−6 test/Rollbar/Item/MissingHeaders/Test.hs+16−10 test/Rollbar/Item/Request/Test.hs+12−6
package.yaml+1−2
@@ -39,10 +39,9 @@ tests:
3939 - containers >= 0.5
4040 - hspec >= 2.4
4141 - hspec-golden-aeson >= 0.2
42− - lens >= 4.15
43− - lens-aeson >= 1.0
4442 - rollbar-hs
4543 - text >= 1.2
44+ - unordered-containers >= 0.2
4645 main: Main.hs
4746 source-dirs: test
4847version: '0.3.0.1'
test/Rollbar/Item/Data/Test.hs+13−6
@@ -1,11 +1,9 @@
11{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE LambdaCase #-}
23{-# LANGUAGE OverloadedStrings #-}
34module Rollbar.Item.Data.Test where
45
5−import Control.Lens ((^@..))
6−
7−import Data.Aeson (encode, toJSON)
8−import Data.Aeson.Lens (key, members)
6+import Data.Aeson (Value(Null, Object), decode', encode, toJSON)
97import Data.Text (Text)
108
119import Rollbar.Item
@@ -13,6 +11,8 @@ import Rollbar.QuickCheck ()
1311
1412import Test.QuickCheck (conjoin, quickCheck)
1513
14+import qualified Data.HashMap.Strict
15+
1616props :: IO ()
1717props =
1818 quickCheck $ conjoin
@@ -24,13 +24,20 @@ prop_valueDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
2424prop_valueDataBodyHasRequiredKey x =
2525 length ms == 1 && fst (head ms) `elem` requiredBodyKeys
2626 where
27− ms = toJSON x ^@.. key "body" . members
27+ ms = key "body" (toJSON x)
2828
2929prop_encodingDataBodyHasRequiredKey :: Data () '["Authorization"] -> Bool
3030prop_encodingDataBodyHasRequiredKey x =
3131 length ms == 1 && fst (head ms) `elem` requiredBodyKeys
3232 where
33− ms = encode x ^@.. key "body" . members
33+ ms = foldMap (key "body") (decode' $ encode x)
3434
3535requiredBodyKeys :: [Text]
3636requiredBodyKeys = ["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 @@
11{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE FlexibleContexts #-}
33{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE LambdaCase #-}
45{-# LANGUAGE OverloadedStrings #-}
56{-# LANGUAGE TypeOperators #-}
67module Rollbar.Item.MissingHeaders.Test where
78
8−import Control.Lens ((&), (^@..))
9−
10−import Data.Aeson (encode, toJSON)
11−import Data.Aeson.Lens (members)
9+import Data.Aeson (Value(Object), decode', encode, toJSON)
10+import Data.Text (Text)
1211
1312import Prelude hiding (error)
1413
@@ -19,6 +18,8 @@ import Test.QuickCheck (conjoin, quickCheck)
1918
2019import Data.Set as S
2120
21+import qualified Data.HashMap.Strict
22+
2223props :: IO ()
2324props = do
2425 quickCheck $ conjoin
@@ -40,25 +41,25 @@ prop_valueAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
4041prop_valueAuthorizationIsRemoved hs =
4142 "Authorization" `S.notMember` actual
4243 where
43− actual = toJSON hs ^@.. members & fmap fst & S.fromList
44+ actual = S.fromList (keys $ toJSON hs)
4445
4546prop_encodingAuthorizationIsRemoved :: MissingHeaders '["Authorization"] -> Bool
4647prop_encodingAuthorizationIsRemoved hs =
4748 "Authorization" `S.notMember` actual
4849 where
49− actual = encode hs ^@.. members & fmap fst & S.fromList
50+ actual = S.fromList (foldMap keys $ decode' $ encode hs)
5051
5152prop_valueX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
5253prop_valueX_AccessTokenIsRemoved hs =
5354 "X-AccessToken" `S.notMember` actual
5455 where
55− actual = toJSON hs ^@.. members & fmap fst & S.fromList
56+ actual = S.fromList (keys $ toJSON hs)
5657
5758prop_encodingX_AccessTokenIsRemoved :: MissingHeaders '["X-AccessToken"] -> Bool
5859prop_encodingX_AccessTokenIsRemoved hs =
5960 "X-AccessToken" `S.notMember` actual
6061 where
61− actual = encode hs ^@.. members & fmap fst & S.fromList
62+ actual = S.fromList (foldMap keys $ decode' $ encode hs)
6263
6364prop_valueAllHeadersAreRemoved
6465 :: MissingHeaders
@@ -70,7 +71,7 @@ prop_valueAllHeadersAreRemoved hs =
7071 && "Server" `S.notMember` actual
7172 && "X-AccessToken" `S.notMember` actual
7273 where
73− actual = toJSON hs ^@.. members & fmap fst & S.fromList
74+ actual = S.fromList (keys $ toJSON hs)
7475
7576prop_encodingAllHeadersAreRemoved
7677 :: MissingHeaders
@@ -82,4 +83,9 @@ prop_encodingAllHeadersAreRemoved hs =
8283 && "Server" `S.notMember` actual
8384 && "X-AccessToken" `S.notMember` actual
8485 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 @@
11{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE FlexibleInstances #-}
3+{-# LANGUAGE LambdaCase #-}
34{-# LANGUAGE OverloadedStrings #-}
45{-# LANGUAGE TypeOperators #-}
56module Rollbar.Item.Request.Test where
67
7−import Control.Lens ((&), (^@..))
8−
9−import Data.Aeson (encode, toJSON)
10−import Data.Aeson.Lens (members)
8+import Data.Aeson (Value(Object), decode', encode, toJSON)
119import Data.CaseInsensitive (original)
10+import Data.Text (Text)
1211
1312import Prelude hiding (error)
1413
@@ -20,6 +19,8 @@ import Test.QuickCheck (conjoin, quickCheck)
2019import Data.Set as S
2120import Data.Text.Encoding as TE
2221
22+import qualified Data.HashMap.Strict
23+
2324props :: IO ()
2425props =
2526 quickCheck $ conjoin
@@ -31,12 +32,17 @@ prop_valueHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
3132prop_valueHeadersArentWrapped hs@(MissingHeaders rhs) =
3233 actual `S.isSubsetOf` expected
3334 where
34− actual = toJSON hs ^@.. members & fmap fst & S.fromList
35+ actual = S.fromList (keys $ toJSON hs)
3536 expected = S.fromList $ either (const "") id . TE.decodeUtf8' . original . fst <$> rhs
3637
3738prop_encodingHeadersArentWrapped :: MissingHeaders '["Authorization"] -> Bool
3839prop_encodingHeadersArentWrapped hs@(MissingHeaders rhs) =
3940 actual `S.isSubsetOf` expected
4041 where
41− actual = encode hs ^@.. members & fmap fst & S.fromList
42+ actual = S.fromList (foldMap keys $ decode' $ encode hs)
4243 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