packages feed

swagger-test 0.2.2 → 0.2.3

raw patch · 3 files changed

+27/−17 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Test.Swagger.Report: TestReport :: Seed -> Operation -> HttpRequest -> HttpResponse -> ValidationResult -> TestReport
+ Test.Swagger.Report: TestReport :: Seed -> Operation -> HttpRequest -> Maybe HttpResponse -> ValidationResult -> TestReport
- Test.Swagger.Report: [reportResponse] :: TestReport -> HttpResponse
+ Test.Swagger.Report: [reportResponse] :: TestReport -> Maybe HttpResponse

Files

src/Test/Swagger/Report.hs view
@@ -1,5 +1,6 @@-{-# LANGUAGE LambdaCase        #-}-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE LambdaCase          #-}+{-# LANGUAGE OverloadedStrings   #-}+{-# LANGUAGE ScopedTypeVariables #-} {-| Module      : Test.Swagger.Report Description : Exposes@@ -16,15 +17,18 @@                            , runTests) where  import           Control.Concurrent.Async+import           Control.Exception import           Control.Lens                  ((^.)) import           Control.Monad import           Data.Aeson                    as J import qualified Data.ByteString.Lazy          as LBS import           Data.List import           Data.Maybe+import           Data.Monoid import qualified Data.Set                      as S import           Data.Swagger                  as W import qualified Data.Text                     as T+import           Network.HTTP.Client import           System.Random import           Test.Swagger.Gen import           Test.Swagger.Print@@ -34,14 +38,13 @@ import           Text.Blaze.Html.Renderer.Utf8 import           Text.Blaze.Html5              as H import           Text.Blaze.Html5.Attributes   as A-import Data.Monoid   -- |A description of a particular test run. data TestReport = TestReport { reportSeed      :: Seed                              , reportOperation :: Operation                              , reportRequest   :: HttpRequest-                             , reportResponse  :: HttpResponse+                             , reportResponse  :: Maybe HttpResponse                              , reportResult    :: ValidationResult }                      deriving Eq @@ -51,7 +54,7 @@           TestReport { reportSeed=s2, reportOperation=op2} =     case (op1 ^. operationId, op2 ^. operationId) of       (Nothing, Nothing) -> compare s1 s2-      (x, y) -> compare x y+      (x, y)             -> compare x y  -- |Predicate that tells whether or not a report is of a successful validation isSuccessful :: TestReport -> Bool@@ -74,9 +77,10 @@     replicateConcurrently n $       do seed <- abs <$> randomIO          let (op, req) = generateRequest seed siz model Nothing-         res <- doHttpRequest req-         let vr = validateResponseWithOperation res model op-         pure $ TestReport seed op req res vr+         catch (do res <- doHttpRequest req+                   let vr = validateResponseWithOperation res model op+                   pure $ TestReport seed op req (Just res) vr)+               (\(ex :: HttpException) -> pure $ TestReport seed op req Nothing (Left $ show ex))  -- |Write a report file containing just a single error message. This is to be -- used if we find an error before being able to run any test (parsing schema,@@ -163,7 +167,9 @@                          h5 ! A.id thisId' $                            a ! href ("#" <> thisId')                            $ "HTTP Response"-                         code $ pre $ toHtml $ printResponse FormatHttp $ reportResponse r+                         code $ pre $ case reportResponse r of+                                       Just res -> toHtml $ printResponse FormatHttp res+                                       Nothing -> "No Response"                        let thisId' = toValue opid <> toValue (reportSeed r) <> "-err"                        h5 ! A.id thisId' $                          a ! href ("#" <> thisId')
src/Test/Swagger/Types.hs view
@@ -24,18 +24,19 @@                           , refToMaybe) where  import           Control.Arrow+import           Control.Lens               hiding ((.=)) import           Data.Aeson-import qualified Data.ByteString.Lazy as LBS+import qualified Data.ByteString.Lazy       as LBS import           Data.CaseInsensitive-import qualified Data.HashMap.Lazy    as HM-import qualified Data.Text            as T-import           Data.Text.Encoding-import           Network.HTTP.Types-import           Control.Lens hiding ((.=)) import           Data.Generics+import qualified Data.HashMap.Lazy          as HM import qualified Data.HashMap.Strict.InsOrd as M import           Data.Monoid                ((<>))-import           Data.Swagger+import           Data.Swagger               hiding (prependPath)+import qualified Data.Text                  as T+import           Data.Text.Encoding+import           Network.HTTP.Types+import           System.FilePath.Posix  -- |The FullyQualifiedHost contains the scheme (i.e. http://), hostname and port. type FullyQualifiedHost = String@@ -106,6 +107,9 @@           resolveSchema i@Inline {} = i           resolveSchema (Ref (Reference r)) = maybe (error $ "undefied schema: " <> T.unpack r) Inline                                             $ M.lookup r $ s ^. definitions++prependPath :: FilePath -> Swagger -> Swagger+prependPath path = paths %~ M.mapKeys (\x -> path </> dropWhile (== '/') x)  -- |Transform a reference into a Just value if is inline, Nothing, otherwise refToMaybe :: Referenced a -> Maybe a
swagger-test.cabal view
@@ -1,5 +1,5 @@ name:                swagger-test-version:             0.2.2+version:             0.2.3 synopsis:            Testing of Swagger APIs description:         This package provides a library and executable tool                      that supports testing APIs specified with Swagger. It