aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-02-17 01:05:57 +0000
committerGregor Kleen <gkleen@yggdrasil.li>2016-02-17 01:05:57 +0000
commitfff9cbfc9e7919723349e18c4b9aea89bcc48c1a (patch)
tree8256a7c6a8e77d01446e70c5692c868c24a18b1f /server
parente3068de72434d6152c40df691f26943c88327406 (diff)
downloadthermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.tar
thermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.tar.gz
thermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.tar.bz2
thermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.tar.xz
thermoprint-fff9cbfc9e7919723349e18c4b9aea89bcc48c1a.zip
Harness for tests of Thermoprint.Server
Diffstat (limited to 'server')
-rw-r--r--server/test/Thermoprint/ServerSpec.hs59
-rw-r--r--server/thermoprint-server.cabal14
-rw-r--r--server/thermoprint-server.nix11
3 files changed, 77 insertions, 7 deletions
diff --git a/server/test/Thermoprint/ServerSpec.hs b/server/test/Thermoprint/ServerSpec.hs
new file mode 100644
index 0000000..aa654b1
--- /dev/null
+++ b/server/test/Thermoprint/ServerSpec.hs
@@ -0,0 +1,59 @@
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE ImpredicativeTypes #-}
3
4module Thermoprint.ServerSpec (spec) where
5
6import Test.HUnit
7import Test.Hspec
8import Test.Hspec.Contrib.HUnit
9
10import Thermoprint.API
11import Thermoprint.Server
12
13import Control.Monad
14import Control.Monad.Logger
15import Control.Monad.Reader
16import Control.Monad.Trans.Identity
17import Control.Monad.Trans.Resource
18
19import Database.Persist.Sqlite
20
21import Control.Concurrent
22import Control.Concurrent.STM
23
24import System.IO
25import System.IO.Temp
26
27import qualified Data.Text as T
28
29data TestPrinter = TestPrinter
30 { outputChan :: TChan Printout
31 , failSwitch :: TMVar PrintingError
32 }
33
34data TestManager = TestManager
35 { manage :: TMVar (QueueManager IdentityT)
36 }
37
38setup :: IO (ThreadId, TestPrinter, TestManager)
39setup = withSystemTempFile "thermoprint.sqlite" $ \fp h -> hClose h >> do
40 tPrinter <- TestPrinter <$> newTChanIO <*> newEmptyTMVarIO
41 tManager <- TestManager <$> newEmptyTMVarIO
42 let
43 runSqlite :: ReaderT ConnectionPool (LoggingT IO) a -> IO a
44 runSqlite = runStderrLoggingT . withSqlitePool (T.pack fp) 1 . runReaderT
45
46 printers = [ ( pure $ PM tPM
47 , QMConfig (join . lift $ takeTMVar (manage tManager)) (Nat $ liftIO . runIdentityT)
48 )
49 ]
50
51 tPM :: MonadIO m => Printout -> m (Maybe PrintingError)
52 tPM printout = liftIO . atomically $ writeTChan (outputChan tPrinter) printout >> tryTakeTMVar (failSwitch tPrinter)
53 (,,) <$> forkIO (thermoprintServer (Nat runSqlite) $ def `withPrinters` printers) <*> pure tPrinter <*> pure tManager
54
55spec :: Spec
56spec = do
57 fromHUnitTest . test . ("blub" ~:) $ do
58 putStrLn "Blub."
59 return True
diff --git a/server/thermoprint-server.cabal b/server/thermoprint-server.cabal
index 1ad4d4d..849d35a 100644
--- a/server/thermoprint-server.cabal
+++ b/server/thermoprint-server.cabal
@@ -36,16 +36,16 @@ library
36 , exceptions >=0.8.0 && <1 36 , exceptions >=0.8.0 && <1
37 , monad-control >=1.0.0 && <2 37 , monad-control >=1.0.0 && <2
38 , monad-logger >=0.3.13 && <1 38 , monad-logger >=0.3.13 && <1
39 , resourcet >=1.1.7 && <2
39 , mtl >=2.2.1 && <3 40 , mtl >=2.2.1 && <3
41 , transformers >=0.3.0 && <1
40 , persistent >=2.2 && <3 42 , persistent >=2.2 && <3
41 , persistent-template >=2.1.4 && <3 43 , persistent-template >=2.1.4 && <3
42 , resourcet >=1.1.7 && <2
43 , servant-server >=0.4.4 && <1 44 , servant-server >=0.4.4 && <1
44 , stm >=2.4.4 && <3 45 , stm >=2.4.4 && <3
45 , text >=1.2.1 && <2 46 , text >=1.2.1 && <2
46 , thermoprint-spec ==3.0.* 47 , thermoprint-spec ==3.0.*
47 , time >=1.5.0 && <2 48 , time >=1.5.0 && <2
48 , transformers >=0.3.0 && <1
49 , wai >=3.0.4 && <4 49 , wai >=3.0.4 && <4
50 , warp >=3.1.9 && <4 50 , warp >=3.1.9 && <4
51 , mmorph >=1.0.4 && <2 51 , mmorph >=1.0.4 && <2
@@ -65,8 +65,18 @@ Test-Suite tests
65 , thermoprint-server -any 65 , thermoprint-server -any
66 , thermoprint-spec -any 66 , thermoprint-spec -any
67 , hspec >=2.2.1 && <3 67 , hspec >=2.2.1 && <3
68 , hspec-contrib >=0.3.0 && <1
69 , HUnit >=1.2.5 && <2
68 , QuickCheck >=2.8.1 && <3 70 , QuickCheck >=2.8.1 && <3
69 , quickcheck-instances >=0.3.11 && <4 71 , quickcheck-instances >=0.3.11 && <4
72 , temporary >=1.2.0 && <2
73 , monad-logger >=0.3.13 && <1
74 , resourcet >=1.1.7 && <2
75 , mtl >=2.2.1 && <3
76 , transformers >=0.3.0 && <1
77 , persistent-sqlite >=2.2 && <3
78 , text >=1.2.1 && <2
79 , stm >=2.4.4 && <3
70 80
71executable thermoprint-server 81executable thermoprint-server
72 main-is: Main.hs 82 main-is: Main.hs
diff --git a/server/thermoprint-server.nix b/server/thermoprint-server.nix
index 77911a8..737f571 100644
--- a/server/thermoprint-server.nix
+++ b/server/thermoprint-server.nix
@@ -1,10 +1,10 @@
1{ mkDerivation, base, binary, bytestring, conduit, containers 1{ mkDerivation, base, binary, bytestring, conduit, containers
2, data-default-class, deepseq, dyre, either, encoding, exceptions 2, data-default-class, deepseq, dyre, either, encoding, exceptions
3, extended-reals, filelock, hspec, mmorph, monad-control 3, extended-reals, filelock, hspec, hspec-contrib, HUnit, mmorph
4, monad-logger, mtl, persistent, persistent-sqlite 4, monad-control, monad-logger, mtl, persistent, persistent-sqlite
5, persistent-template, QuickCheck, quickcheck-instances, resourcet 5, persistent-template, QuickCheck, quickcheck-instances, resourcet
6, servant-server, stdenv, stm, text, thermoprint-spec, time 6, servant-server, stdenv, stm, temporary, text, thermoprint-spec
7, transformers, wai, warp 7, time, transformers, wai, warp
8}: 8}:
9mkDerivation { 9mkDerivation {
10 pname = "thermoprint-server"; 10 pname = "thermoprint-server";
@@ -23,7 +23,8 @@ mkDerivation {
23 base monad-logger mtl persistent-sqlite resourcet 23 base monad-logger mtl persistent-sqlite resourcet
24 ]; 24 ];
25 testHaskellDepends = [ 25 testHaskellDepends = [
26 base hspec QuickCheck quickcheck-instances thermoprint-spec 26 base hspec hspec-contrib HUnit QuickCheck quickcheck-instances
27 temporary thermoprint-spec
27 ]; 28 ];
28 homepage = "http://dirty-haskell.org/tags/thermoprint.html"; 29 homepage = "http://dirty-haskell.org/tags/thermoprint.html";
29 description = "Server for thermoprint-spec"; 30 description = "Server for thermoprint-spec";