mirror of
https://github.com/haskell-servant/servant-ekg.git
synced 2024-11-23 03:29:43 +01:00
Start more extensive tests
This commit is contained in:
parent
afeab8dd11
commit
28df5baf6c
4 changed files with 47 additions and 26 deletions
|
@ -1,25 +1,25 @@
|
|||
name: servant-ekg
|
||||
version: 0.1.0.0
|
||||
version: 0.2.0.0
|
||||
synopsis: Helpers for using ekg with servant
|
||||
description: Helpers for using ekg with servant
|
||||
license: BSD3
|
||||
license-file: LICENSE
|
||||
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
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
|
||||
source-repository HEAD
|
||||
type: git
|
||||
location: https://github.com/anchor/servant-ekg.git
|
||||
location: https://github.com/servant/servant-ekg.git
|
||||
|
||||
library
|
||||
exposed-modules: Servant.Ekg
|
||||
hs-source-dirs: lib
|
||||
build-depends: base >=4.7 && <4.9
|
||||
, ekg-core
|
||||
, servant == 0.7.*
|
||||
, servant > 0.5 && < 0.8
|
||||
, http-types
|
||||
, text
|
||||
, time
|
||||
|
@ -32,13 +32,18 @@ test-suite spec
|
|||
ghc-options: -Wall
|
||||
default-language: Haskell2010
|
||||
hs-source-dirs: test
|
||||
main-is: test.hs
|
||||
main-is: Spec.hs
|
||||
build-depends: base == 4.*
|
||||
, aeson
|
||||
, ekg
|
||||
, ekg-core
|
||||
, servant-ekg
|
||||
, servant-server
|
||||
, servant-client
|
||||
, http-client
|
||||
, text
|
||||
, wai
|
||||
, warp
|
||||
, warp >= 3.2.4 && < 3.3
|
||||
, hspec == 2.*
|
||||
, unordered-containers
|
||||
, transformers
|
||||
|
|
16
stack.yaml
16
stack.yaml
|
@ -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.
|
||||
# A snapshot resolver dictates the compiler version and the set of packages
|
||||
|
@ -50,6 +37,9 @@ packages:
|
|||
extra-deps:
|
||||
- servant-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
|
||||
flags: {}
|
||||
|
|
|
@ -6,19 +6,46 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
|
||||
module Servant.EkgSpec (spec) where
|
||||
|
||||
import Control.Concurrent
|
||||
import Control.Monad.Trans.Except
|
||||
import Data.Aeson
|
||||
import Data.Monoid
|
||||
import Data.Proxy
|
||||
import qualified Data.HashMap.Strict as H
|
||||
import Data.Text
|
||||
import GHC.Generics
|
||||
import Network.HTTP.Client (defaultManagerSettings, newManager)
|
||||
import Network.Wai
|
||||
import Network.Wai.Handler.Warp
|
||||
import Servant
|
||||
import Servant.Client
|
||||
import System.Metrics
|
||||
import qualified System.Metrics.Counter as Counter
|
||||
import Test.Hspec
|
||||
|
||||
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
|
||||
|
||||
-- | A greet message data type
|
||||
|
@ -65,10 +92,8 @@ server = helloH :<|> postGreetH :<|> deleteGreetH
|
|||
test :: Application
|
||||
test = serve testApi server
|
||||
|
||||
-- Put this all to work!
|
||||
main :: IO ()
|
||||
main = do
|
||||
withApp :: (Port -> MVar (H.HashMap Text Meters) -> IO a) -> IO a
|
||||
withApp a = do
|
||||
ekg <- newStore
|
||||
ms <- newMVar mempty
|
||||
_ <- forkIO $ run 8001 $ monitorEndpoints testApi ekg ms test
|
||||
return ()
|
||||
withApplication (return $ monitorEndpoints testApi ekg ms test) $ \p -> a p ms
|
1
test/Spec.hs
Normal file
1
test/Spec.hs
Normal file
|
@ -0,0 +1 @@
|
|||
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
|
Loading…
Reference in a new issue