http-test 0.1.1 → 0.1.2
raw patch · 3 files changed
+29/−14 lines, 3 files
Files
- Test/HTTP.hs +11/−6
- http-test.cabal +15/−2
- test.hs +3/−6
Test/HTTP.hs view
@@ -1,4 +1,4 @@-module Test.HTTP (httpTest, session, get, getJSON, postForm, assert, Program, Session) where+module Test.HTTP (httpTest, session, get, getJSON, postForm, assert, debug, Program, Session) where import Network.Curl hiding (curlGetString) @@ -17,11 +17,8 @@ import GHC.Conc import qualified Data.Aeson as Ae import Safe (readMay)-import System.Console.GetOpt import System.Environment import System.Exit-import System.IO-import System.IO.Error import qualified Data.Text as T import Data.Text.Encoding (encodeUtf8) import Data.ByteString.Lazy (fromStrict)@@ -117,6 +114,16 @@ assert assName False = failTest assName "fail" +-- | Output a string to stdout if @--verbose@ is in command line arguments+debug :: String -> Session ()+debug s = do+ args <- liftIO $ getArgs+ if "--verbose" `elem` args+ then liftIO $ putStrLn s+ else return ()++ + addTestResult p = State.modify $ \s -> s { sessionResults = p : sessionResults s } @@ -124,8 +131,6 @@ failTest tstNm reason = addTestResult (tstNm, Just reason) -- {------------------------------------------------------- CURL AUXILIARY FUNCTIONS -------------------------------------------------------}
http-test.cabal view
@@ -1,8 +1,21 @@ Name: http-test-Version: 0.1.1+Version: 0.1.2 synopsis: Test framework for HTTP APIs Description: A simple framework for making assertions about the - responses of HTTP servers. See test.hs for an example+ responses of HTTP servers.+ .+ > import Test.HTTP+ > import Data.List (isInfixOf)+ >+ > main = httpTest $ do+ > session "BayesHive landing page" "https://bayeshive.com" $ do+ > landing <- get "/"+ > assert "Correct blog link" $ + > "href=\"https://bayeshive.com/blog\"" `isInfixOf` landing+ > loginResult <- postForm "/auth/page/email/login" + > [("email", "foo"), ("password", "bar")]+ > debug loginResult+ License: BSD3 Author: OpenBrain Ltd Maintainer: tomn@openbrain.org
test.hs view
@@ -1,14 +1,11 @@-module Main where- import Test.HTTP-import Data.List-import Control.Monad.Trans+import Data.List (isInfixOf) main = httpTest $ do session "BayesHive landing page" "https://bayeshive.com" $ do landing <- get "/" assert "Correct blog link" $ "href=\"https://bayeshive.com/blog\"" `isInfixOf` landing- postForm "/auth/page/email/login" + loginResult <- postForm "/auth/page/email/login" [("email", "foo"), ("password", "bar")]- return ()+ debug loginResult