From 495c7176485a6bcb4865b745bc2ec966bf5479aa Mon Sep 17 00:00:00 2001 From: Ashley Stacey Date: Mon, 15 Jul 2019 16:11:47 +1000 Subject: [PATCH] [#500] Start some basic work on trails service. --- projects/trails/app/Trails.hs | 4 +- projects/trails/src/Lib.hs | 6 --- .../trails/src/Mirza/Trails/Client/Servant.hs | 1 + projects/trails/src/Mirza/Trails/Main.hs | 6 +++ projects/trails/stack.yaml | 4 +- projects/trails/test/Mirza/Trails/Spec.hs | 19 ++++++++++ .../trails/test/Mirza/Trails/Tests/Client.hs | 37 +++++++++++++++++++ projects/trails/test/Spec.hs | 2 - projects/trails/trails.cabal | 24 +++++++++--- 9 files changed, 87 insertions(+), 16 deletions(-) delete mode 100644 projects/trails/src/Lib.hs create mode 100644 projects/trails/src/Mirza/Trails/Client/Servant.hs create mode 100644 projects/trails/src/Mirza/Trails/Main.hs create mode 100644 projects/trails/test/Mirza/Trails/Spec.hs create mode 100644 projects/trails/test/Mirza/Trails/Tests/Client.hs delete mode 100644 projects/trails/test/Spec.hs diff --git a/projects/trails/app/Trails.hs b/projects/trails/app/Trails.hs index de1c1ab3..661c9e6e 100644 --- a/projects/trails/app/Trails.hs +++ b/projects/trails/app/Trails.hs @@ -1,6 +1,6 @@ module Main where -import Lib +import qualified Mirza.Trails.Main as T (main) main :: IO () -main = someFunc +main = T.main diff --git a/projects/trails/src/Lib.hs b/projects/trails/src/Lib.hs deleted file mode 100644 index d36ff271..00000000 --- a/projects/trails/src/Lib.hs +++ /dev/null @@ -1,6 +0,0 @@ -module Lib - ( someFunc - ) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/projects/trails/src/Mirza/Trails/Client/Servant.hs b/projects/trails/src/Mirza/Trails/Client/Servant.hs new file mode 100644 index 00000000..3652b504 --- /dev/null +++ b/projects/trails/src/Mirza/Trails/Client/Servant.hs @@ -0,0 +1 @@ +module Mirza.Trails.Client.Servant where diff --git a/projects/trails/src/Mirza/Trails/Main.hs b/projects/trails/src/Mirza/Trails/Main.hs new file mode 100644 index 00000000..73751d17 --- /dev/null +++ b/projects/trails/src/Mirza/Trails/Main.hs @@ -0,0 +1,6 @@ +module Mirza.Trails.Main where +main :: IO () +main = putStrLn "Trails..." + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/projects/trails/stack.yaml b/projects/trails/stack.yaml index 5ed1fb34..a692c96f 100644 --- a/projects/trails/stack.yaml +++ b/projects/trails/stack.yaml @@ -30,6 +30,8 @@ resolver: lts-13.28 # - wai packages: - . +- '../mirza-common-haskell' +- '../mirza-test-utils-haskell' # Dependency packages to be pulled from upstream that are not in the resolver. # These entries can reference officially published versions as well as # forks / in-progress versions pinned to a git hash. For example: @@ -76,6 +78,6 @@ extra-deps: ghc-options: - $locals: -Wall + $locals: -Wall -Werror local-bin-path: dist diff --git a/projects/trails/test/Mirza/Trails/Spec.hs b/projects/trails/test/Mirza/Trails/Spec.hs new file mode 100644 index 00000000..77f7ab13 --- /dev/null +++ b/projects/trails/test/Mirza/Trails/Spec.hs @@ -0,0 +1,19 @@ +module Main where + +import Mirza.Trails.Tests.Client + +import Test.Tasty hiding (withResource) +import Test.Tasty.Runners (NumThreads (..)) + +import Control.Exception (bracket) +import Control.Monad.Except (liftIO, runExceptT) + +main :: IO () +main = do + either (error . show) pure =<< (liftIO $ runExceptT $ makeDatabase testDbNameTrails) + + clientTests <- clientSpec + + defaultMain $ localOption (NumThreads 1) $ testGroup "tests" + [ clientTests + ] diff --git a/projects/trails/test/Mirza/Trails/Tests/Client.hs b/projects/trails/test/Mirza/Trails/Tests/Client.hs new file mode 100644 index 00000000..90da557c --- /dev/null +++ b/projects/trails/test/Mirza/Trails/Tests/Client.hs @@ -0,0 +1,37 @@ +module Mirza.Trails.Tests.Client where + + +import Mirza.Trails.Client.Servant + +import Mirza.Trails.Tests.InitClient + +import Mirza.Common.Tests.ServantUtils + +import Test.Hspec.Expectations +import Test.Tasty +import Test.Tasty.HUnit + +import Control.Exception (bracket) + + +-- === OR Servant Client tests +clientSpec :: IO TestTree +clientSpec = do + + + + + let healthTests = testCaseSteps "Provides health status" $ \step -> + bracket runTrailsApp (\(a,b,_) -> endWaiApp (a,b)) $ \(_tid, baseurl) -> do + let http = runClient baseurl + + step "Status results in 200" + -- healthResult <- http health + -- healthResult `shouldSatisfy` isRight + -- healthResult `shouldBe` (Right HealthResponse) + + + pure $ testGroup "Trails HTTP Client tests" + [ + healthTests + ] diff --git a/projects/trails/test/Spec.hs b/projects/trails/test/Spec.hs deleted file mode 100644 index cd4753fc..00000000 --- a/projects/trails/test/Spec.hs +++ /dev/null @@ -1,2 +0,0 @@ -main :: IO () -main = putStrLn "Test suite not yet implemented" diff --git a/projects/trails/trails.cabal b/projects/trails/trails.cabal index c6f6dc1e..0609f9a7 100644 --- a/projects/trails/trails.cabal +++ b/projects/trails/trails.cabal @@ -26,22 +26,24 @@ source-repository head library exposed-modules: - Lib + Mirza.Trails.Main + Mirza.Trails.Client.Servant other-modules: Paths_trails hs-source-dirs: src build-depends: base >=4.7 && <5 + , mirza-test-utils-haskell default-language: Haskell2010 -executable trails-exe - main-is: Main.hs +executable trails + main-is: Trails.hs other-modules: Paths_trails hs-source-dirs: app - ghc-options: -threaded -rtsopts -with-rtsopts=-N + ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Werror build-depends: base >=4.7 && <5 , trails @@ -49,13 +51,25 @@ executable trails-exe test-suite trails-test type: exitcode-stdio-1.0 - main-is: Spec.hs + main-is: Mirza/Trails/Spec.hs other-modules: Paths_trails + , Mirza.Trails.Tests.Client + , Mirza.Trails.Tests.InitClient hs-source-dirs: test ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Werror build-depends: base >=4.7 && <5 , trails + , mirza-common-haskell + , mirza-test-utils-haskell + , hspec-expectations + , mtl + , tasty + , tasty-hunit default-language: Haskell2010 + +source-repository head + type: git + location: https://github.com/data61/Mirza