Skip to content

Commit f6b51d0

Browse files
committed
Use mtl's MonadReader
1 parent eb237e9 commit f6b51d0

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

integration/default.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@
99
, async
1010
, base
1111
, bytestring
12+
, bytestring-conversion
1213
, Cabal
1314
, case-insensitive
1415
, containers
1516
, data-default
1617
, directory
18+
, exceptions
1719
, filepath
1820
, gitignoreSource
1921
, http-client
2022
, http-types
2123
, imports
2224
, lib
25+
, mtl
2326
, network
2427
, network-uri
2528
, process
@@ -32,6 +35,8 @@
3235
, tasty
3336
, text
3437
, transformers
38+
, unliftio
39+
, websockets
3540
, yaml
3641
}:
3742
mkDerivation {
@@ -48,13 +53,16 @@ mkDerivation {
4853
async
4954
base
5055
bytestring
56+
bytestring-conversion
5157
case-insensitive
5258
containers
5359
data-default
60+
exceptions
5461
filepath
5562
http-client
5663
http-types
5764
imports
65+
mtl
5866
network
5967
network-uri
6068
process
@@ -67,6 +75,8 @@ mkDerivation {
6775
tasty
6876
text
6977
transformers
78+
unliftio
79+
websockets
7080
yaml
7181
];
7282
license = lib.licenses.agpl3Only;

integration/integration.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ library
104104
, http-client
105105
, http-types
106106
, imports
107+
, mtl
107108
, network
108109
, network-uri
109110
, process

integration/test/TestLib/App.hs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import Control.Exception (finally)
1616
import qualified Control.Exception as E
1717
import Control.Monad.Catch (MonadMask, MonadThrow)
1818
import Control.Monad.Catch.Pure (MonadCatch)
19+
import Control.Monad.Reader
1920
import Control.Monad.Trans.Maybe (MaybeT (..))
20-
import Control.Monad.Trans.Reader
2121
import Control.Retry (fibonacciBackoff, limitRetriesByCumulativeDelay, retrying)
2222
import Data.Aeson hiding ((.=))
2323
import qualified Data.Aeson as Aeson
@@ -64,7 +64,16 @@ import Test.Tasty.Providers.ConsoleFormat
6464
-------------------------------------------------------------------------------
6565

6666
newtype App a = App {unApp :: ReaderT Env IO a}
67-
deriving (Functor, Applicative, Monad, MonadIO, MonadMask, MonadCatch, MonadThrow)
67+
deriving
68+
( Functor,
69+
Applicative,
70+
Monad,
71+
MonadIO,
72+
MonadMask,
73+
MonadCatch,
74+
MonadThrow,
75+
MonadReader Env
76+
)
6877

6978
data AppFailure = AppFailure String
7079

@@ -80,12 +89,6 @@ failApp msg = throw (AppFailure msg)
8089
runAppWithEnv :: Env -> App a -> IO a
8190
runAppWithEnv e m = runReaderT (unApp m) e
8291

83-
getContext :: App Context
84-
getContext = App $ asks (.context)
85-
86-
getManager :: App HTTP.Manager
87-
getManager = App $ asks (.manager)
88-
8992
getPrekey :: App Value
9093
getPrekey = App $ do
9194
pks <- asks (.prekeys)
@@ -616,10 +619,10 @@ data Versioned = Versioned | Unversioned | ExplicitVersion Int
616619

617620
baseRequest :: Service -> Versioned -> String -> App HTTP.Request
618621
baseRequest service versioned path = do
619-
ctx <- getContext
622+
ctx <- asks (.context)
620623
pathSegsPrefix <- case versioned of
621624
Versioned -> do
622-
v <- App $ asks (.context.version)
625+
v <- asks (.context.version)
623626
pure ["v" <> show v]
624627
Unversioned -> pure []
625628
ExplicitVersion v -> do
@@ -632,7 +635,7 @@ baseRequest service versioned path = do
632635
submit :: String -> HTTP.Request -> App Response
633636
submit method req0 = do
634637
let req = req0 {HTTP.method = toByteString' method}
635-
manager <- getManager
638+
manager <- asks (.manager)
636639
res <- liftIO $ HTTP.httpLbs req manager
637640
pure $
638641
Response
@@ -813,7 +816,7 @@ withModifiedServices services k = do
813816
(Map.assocs ports)
814817

815818
instances <- for (Map.assocs services) $ \(srv, modifyConfig) -> do
816-
basedir <- App $ asks (.serviceConfigsDir)
819+
basedir <- asks (.serviceConfigsDir)
817820
let srvName = serviceName srv
818821
cfgFile = basedir </> srvName </> "conf" </> (srvName <> ".yaml")
819822
config <- do
@@ -827,11 +830,10 @@ withModifiedServices services k = do
827830
hClose fh
828831

829832
(cwd, exe) <-
830-
App $
831-
asks (.servicesCwdBase) <&> \case
832-
Nothing -> (Nothing, srvName)
833-
Just dir ->
834-
(Just (dir </> srvName), "./dist" </> srvName)
833+
asks (.servicesCwdBase) <&> \case
834+
Nothing -> (Nothing, srvName)
835+
Just dir ->
836+
(Just (dir </> srvName), "./dist" </> srvName)
835837

836838
(port, socket) <- maybe (failApp "the impossible in withServices happened") pure (Map.lookup srv ports)
837839
liftIO $ N.close socket

integration/test/TestLib/Cannon.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ clientApp wsChan latch conn = do
9898
-- for the connection to register with Gundeck, and return the 'Async' thread.
9999
run :: HasCallStack => WSConnect -> WS.ClientApp () -> App (Async ())
100100
run wsConnect app = do
101-
ctx <- getContext
101+
ctx <- asks (.context)
102102
let HostPort caHost caPort = serviceHostPort ctx.serviceMap Cannon
103103
latch <- newEmptyMVar
104104

0 commit comments

Comments
 (0)