| License | Apache-2.0 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
Singular.Provider.Koios.Recorded
Contents
Description
A Transport that answers each request from a fixture directory
recorded from a live Koios service by the koios-http recorder. The
answers are raw — status, headers and body — so the client pages and
decodes them exactly as it does live answers.
Each fixture is one JSON file holding the request, the Koios schema
revision, the time of recording, the SHA-256 of the answer body and the
answer. Loading a directory refuses a fixture whose body does not match
its hash, a set whose fixtures disagree on the schema revision, two
fixtures for one request, and an empty directory. A request with no
fixture is answered by NoRecording, which the client reports as
NotRecorded.
Synopsis
- data Fixture = Fixture {
- fixtureRequest :: FixtureRequest
- fixtureRevision :: Text
- fixtureRecordedAt :: UTCTime
- fixtureSha256 :: Text
- fixtureAnswer :: Answer
- data FixtureRequest = FixtureRequest {
- fixtureCall :: Call
- fixtureMethod :: Method
- fixturePath :: Text
- fixtureQuery :: [(Text, Text)]
- fixtureBody :: Body
- fixtureRequestOf :: RawRequest -> FixtureRequest
- fixtureFileName :: FixtureRequest -> FilePath
- encodeFixture :: Fixture -> ByteString
- decodeFixture :: ByteString -> Either Text Fixture
- bodySha256 :: ByteString -> Text
- data FixtureSet = FixtureSet {
- setRevision :: Text
- setFixtures :: [Fixture]
- data FixtureFailure
- = FixtureUnreadable FilePath Text
- | FixtureHashMismatch FilePath
- | RevisionMismatch [(FilePath, Text)]
- | DuplicateRequest FilePath FilePath
- | NoFixtures FilePath
- loadFixtureSet :: FilePath -> IO (Either FixtureFailure FixtureSet)
- recordedTransport :: forall (m :: Type -> Type). Applicative m => FixtureSet -> Transport m
Fixtures
One recorded answer.
Constructors
| Fixture | |
Fields
| |
Instances
| Show Fixture Source # | |
Defined in Singular.Provider.Koios.Recorded | |
| Eq Fixture Source # | |
Defined in Singular.Provider.Koios.Recorded | |
data FixtureRequest Source #
The part of a request a fixture is keyed by: call, method, path, query in sorted order, and body. Headers, such as a bearer token, are never part of it.
Constructors
| FixtureRequest | |
Fields
| |
Instances
| Show FixtureRequest Source # | |
Defined in Singular.Provider.Koios.Recorded Methods showsPrec :: Int -> FixtureRequest -> ShowS Source # show :: FixtureRequest -> String Source # showList :: [FixtureRequest] -> ShowS Source # | |
| Eq FixtureRequest Source # | |
Defined in Singular.Provider.Koios.Recorded Methods (==) :: FixtureRequest -> FixtureRequest -> Bool Source # (/=) :: FixtureRequest -> FixtureRequest -> Bool Source # | |
fixtureRequestOf :: RawRequest -> FixtureRequest Source #
The fixture key of a raw request.
fixtureFileName :: FixtureRequest -> FilePath Source #
A file name derived from the request alone.
encodeFixture :: Fixture -> ByteString Source #
The JSON text of a fixture.
decodeFixture :: ByteString -> Either Text Fixture Source #
Read a fixture's JSON text.
bodySha256 :: ByteString -> Text Source #
Hex SHA-256 of an answer body.
Fixture sets
data FixtureSet Source #
A loaded fixture directory, all under one schema revision.
Constructors
| FixtureSet | |
Fields
| |
Instances
| Show FixtureSet Source # | |
Defined in Singular.Provider.Koios.Recorded Methods showsPrec :: Int -> FixtureSet -> ShowS Source # show :: FixtureSet -> String Source # showList :: [FixtureSet] -> ShowS Source # | |
| Eq FixtureSet Source # | |
Defined in Singular.Provider.Koios.Recorded Methods (==) :: FixtureSet -> FixtureSet -> Bool Source # (/=) :: FixtureSet -> FixtureSet -> Bool Source # | |
data FixtureFailure Source #
Why a fixture directory cannot be used.
Constructors
| FixtureUnreadable FilePath Text | A file that is not a fixture, or a directory that cannot be read |
| FixtureHashMismatch FilePath | A fixture whose body does not hash to its recorded SHA-256 |
| RevisionMismatch [(FilePath, Text)] | Fixtures recorded under different schema revisions |
| DuplicateRequest FilePath FilePath | Two fixtures for one request |
| NoFixtures FilePath | A directory with no fixture |
Instances
| Show FixtureFailure Source # | |
Defined in Singular.Provider.Koios.Recorded Methods showsPrec :: Int -> FixtureFailure -> ShowS Source # show :: FixtureFailure -> String Source # showList :: [FixtureFailure] -> ShowS Source # | |
| Eq FixtureFailure Source # | |
Defined in Singular.Provider.Koios.Recorded Methods (==) :: FixtureFailure -> FixtureFailure -> Bool Source # (/=) :: FixtureFailure -> FixtureFailure -> Bool Source # | |
loadFixtureSet :: FilePath -> IO (Either FixtureFailure FixtureSet) Source #
Load every .json fixture of a directory.
Transport
recordedTransport :: forall (m :: Type -> Type). Applicative m => FixtureSet -> Transport m Source #
Answer each request from the set; one attempt per request.