Start more extensive tests

This commit is contained in:
Julian K. Arni 2016-05-13 14:56:09 +02:00
parent afeab8dd11
commit 28df5baf6c
4 changed files with 47 additions and 26 deletions

View file

@ -1,25 +1,25 @@
name: servant-ekg name: servant-ekg
version: 0.1.0.0 version: 0.2.0.0
synopsis: Helpers for using ekg with servant synopsis: Helpers for using ekg with servant
description: Helpers for using ekg with servant description: Helpers for using ekg with servant
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Anchor Engineering <engineering@lists.anchor.net.au> author: Anchor Engineering <engineering@lists.anchor.net.au>
maintainer: Anchor Engineering <engineering@lists.anchor.net.au> maintainer: Servant Contributors <haskell-servant-maintainers@googlegroups.com>
category: System category: System
build-type: Simple build-type: Simple
cabal-version: >=1.10 cabal-version: >=1.10
source-repository HEAD source-repository HEAD
type: git type: git
location: https://github.com/anchor/servant-ekg.git location: https://github.com/servant/servant-ekg.git
library library
exposed-modules: Servant.Ekg exposed-modules: Servant.Ekg
hs-source-dirs: lib hs-source-dirs: lib
build-depends: base >=4.7 && <4.9 build-depends: base >=4.7 && <4.9
, ekg-core , ekg-core
, servant == 0.7.* , servant > 0.5 && < 0.8
, http-types , http-types
, text , text
, time , time
@ -32,13 +32,18 @@ test-suite spec
ghc-options: -Wall ghc-options: -Wall
default-language: Haskell2010 default-language: Haskell2010
hs-source-dirs: test hs-source-dirs: test
main-is: test.hs main-is: Spec.hs
build-depends: base == 4.* build-depends: base == 4.*
, aeson , aeson
, ekg , ekg
, ekg-core , ekg-core
, servant-ekg , servant-ekg
, servant-server , servant-server
, servant-client
, http-client
, text , text
, wai , wai
, warp , warp >= 3.2.4 && < 3.3
, hspec == 2.*
, unordered-containers
, transformers

View file

@ -1,16 +1,3 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# http://docs.haskellstack.org/en/stable/yaml_configuration/
# A warning or info to be displayed to the user on config load.
user-message: ! 'Warning (added by new or init): Specified resolver could not satisfy
all dependencies. Some external packages have been added as dependencies.
You can suppress this message by removing it from stack.yaml
'
# Resolver to choose a 'specific' stackage snapshot or a compiler version. # Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages # A snapshot resolver dictates the compiler version and the set of packages
@ -50,6 +37,9 @@ packages:
extra-deps: extra-deps:
- servant-0.7.1 - servant-0.7.1
- servant-server-0.7.1 - servant-server-0.7.1
- servant-client-0.7.1
- warp-3.2.6
- http2-1.6.0
# Override default flag values for local packages and extra-deps # Override default flag values for local packages and extra-deps
flags: {} flags: {}

View file

@ -6,19 +6,46 @@
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeOperators #-}
module Servant.EkgSpec (spec) where
import Control.Concurrent import Control.Concurrent
import Control.Monad.Trans.Except
import Data.Aeson import Data.Aeson
import Data.Monoid import Data.Monoid
import Data.Proxy import Data.Proxy
import qualified Data.HashMap.Strict as H
import Data.Text import Data.Text
import GHC.Generics import GHC.Generics
import Network.HTTP.Client (defaultManagerSettings, newManager)
import Network.Wai import Network.Wai
import Network.Wai.Handler.Warp import Network.Wai.Handler.Warp
import Servant import Servant
import Servant.Client
import System.Metrics import System.Metrics
import qualified System.Metrics.Counter as Counter
import Test.Hspec
import Servant.Ekg import Servant.Ekg
-- * Spec
spec :: Spec
spec = describe "servant-ekg" $ do
let getEp :<|> postEp :<|> deleteEp = client testApi
it "collects GET data" $ do
withApp $ \port mvar -> do
mgr <- newManager defaultManagerSettings
result <- runExceptT $ getEp "name" Nothing mgr (BaseUrl Http "localhost" port "")
m <- readMVar mvar
print $ H.keys m
case H.lookup "hello.:name.GET" m of
Nothing -> fail "Expected some value"
Just v -> Counter.read (metersC2XX v) `shouldReturn` 1
-- * Example -- * Example
-- | A greet message data type -- | A greet message data type
@ -65,10 +92,8 @@ server = helloH :<|> postGreetH :<|> deleteGreetH
test :: Application test :: Application
test = serve testApi server test = serve testApi server
-- Put this all to work! withApp :: (Port -> MVar (H.HashMap Text Meters) -> IO a) -> IO a
main :: IO () withApp a = do
main = do ekg <- newStore
ekg <- newStore ms <- newMVar mempty
ms <- newMVar mempty withApplication (return $ monitorEndpoints testApi ekg ms test) $ \p -> a p ms
_ <- forkIO $ run 8001 $ monitorEndpoints testApi ekg ms test
return ()

1
test/Spec.hs Normal file
View file

@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}