| Copyright | 2018 Automattic Inc. | 
|---|---|
| License | BSD3 | 
| Maintainer | Nathan Bloomfield (nbloomf@gmail.com) | 
| Stability | experimental | 
| Portability | POSIX | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Data.MockIO
Description
A fake IO monad for testing.
Synopsis
- data MockIO s a = MockIO {}
 - getMockWorld :: MockIO s (MockWorld s)
 - putMockWorld :: MockWorld s -> MockIO s ()
 - modifyMockWorld :: (MockWorld s -> MockWorld s) -> MockIO s ()
 - incrementTimer :: Int -> MockIO s ()
 - data MockWorld s = MockWorld {
- _files :: FileSystem (Either FilePath Handle)
 - _time :: UTCTime
 - _httpGet :: String -> MockNetwork s HttpResponse
 - _httpPost :: String -> ByteString -> MockNetwork s HttpResponse
 - _httpDelete :: String -> MockNetwork s HttpResponse
 - _serverState :: MockServer s
 
 - newtype MockServer s = MockServer {
- unMockServer :: s
 
 - epoch :: UTCTime
 - basicMockWorld :: s -> MockWorld s
 - data MockNetwork s a = MockNetwork {
- unMockNetwork :: MockServer s -> (Either HttpException a, MockServer s)
 
 - errorMockNetwork :: HttpException -> MockNetwork s a
 - getMockServer :: MockNetwork s s
 - putMockServer :: s -> MockNetwork s ()
 - modifyMockServer :: (s -> s) -> MockNetwork s ()
 - _200ok :: ByteString -> HttpResponse
 - _400badRequest :: ByteString -> HttpResponse
 - _404notFound :: ByteString -> HttpResponse
 - _405methodNotAllowed :: ByteString -> HttpResponse
 - _408requestTimeout :: ByteString -> HttpResponse
 - _500internalServerError :: ByteString -> HttpResponse
 
MockIO
A state monad over MockWorld.
modifyMockWorld :: (MockWorld s -> MockWorld s) -> MockIO s () Source #
Mutate the current MockWorld strictly.
incrementTimer :: Int -> MockIO s () Source #
Bump the timer by a given number of microseconds.
MockWorld
Just enough state to mock out a basic filesystem and HTTP server.
Constructors
| MockWorld | |
Fields 
  | |
newtype MockServer s Source #
Type representing the internal state of an HTTP server.
Constructors
| MockServer | |
Fields 
  | |
Instances
| Eq s => Eq (MockServer s) Source # | |
Defined in Data.MockIO  | |
| Show s => Show (MockServer s) Source # | |
Defined in Data.MockIO Methods showsPrec :: Int -> MockServer s -> ShowS # show :: MockServer s -> String # showList :: [MockServer s] -> ShowS #  | |
basicMockWorld :: s -> MockWorld s Source #
Empty filesystem and trivial HTTP responses
MockNetwork
data MockNetwork s a Source #
State monad representing network interaction.
Constructors
| MockNetwork | |
Fields 
  | |
Instances
errorMockNetwork :: HttpException -> MockNetwork s a Source #
Throw an HttpException.
getMockServer :: MockNetwork s s Source #
Retrieve the internal state of the fake HTTP server.
putMockServer :: s -> MockNetwork s () Source #
Replace the internal state of the fake HTTP server.
modifyMockServer :: (s -> s) -> MockNetwork s () Source #
Mutate the internal state of the fake HTTP server (strictly).
Responses
_200ok :: ByteString -> HttpResponse Source #
Status 200; no headers
_400badRequest :: ByteString -> HttpResponse Source #
Status 400; no headers
_404notFound :: ByteString -> HttpResponse Source #
Status 404; no headers
_405methodNotAllowed :: ByteString -> HttpResponse Source #
Status 405; no headers
_408requestTimeout :: ByteString -> HttpResponse Source #
Status 408; no headers
_500internalServerError :: ByteString -> HttpResponse Source #
Status 500; no headers