further test setup with hie

This commit is contained in:
Lucy Cifferello
2020-04-16 11:39:26 -06:00
parent d3703a51af
commit 08654c3b2c
10 changed files with 97 additions and 85 deletions

1
.gitignore vendored
View File

@@ -27,3 +27,4 @@ stack.yaml.lock
agent_* agent_*
agent.* agent.*
version version
hie.yaml

View File

@@ -28,6 +28,15 @@ stack exec -- yesod devel
As your code changes, your site will be automatically recompiled and redeployed to localhost. As your code changes, your site will be automatically recompiled and redeployed to localhost.
### Development tools
`ghcid "-c=stack ghci --test"`
- Clone [HIE](https://github.com/haskell/haskell-ide-engine)
- Checkout latest reslease ie. `git checkout tags/1.3`
- Follow github instructions to install for specific GHC version ie. `stack ./install.hs hie`
- Install VSCode Haskell Language Server Extension
## Tests ## Tests
``` ```
@@ -36,6 +45,13 @@ stack test --flag start9-companion-server:library-only --flag start9-companion-s
(Because `yesod devel` passes the `library-only` and `dev` flags, matching those flags means you don't need to recompile between tests and development, and it disables optimization to speed up your test compile times). (Because `yesod devel` passes the `library-only` and `dev` flags, matching those flags means you don't need to recompile between tests and development, and it disables optimization to speed up your test compile times).
### Tests with HIE Setup
- install hspec-discover globally `cabal install hspec-discover` (requires cabal installation)
- Current [issue](https://github.com/haskell/haskell-ide-engine/issues/1564) open for error pertaining to obtaining flags for test files
- recommended to setup hie.yaml
- recommended to run `stack build --test --no-run-tests` *before* any test files are open and that test files compile without error
- helps to debug a specific file: `hie --debug test/Main.hs`
## Documentation ## Documentation
* Read the [Yesod Book](https://www.yesodweb.com/book) online for free * Read the [Yesod Book](https://www.yesodweb.com/book) online for free

View File

@@ -1,6 +0,0 @@
{
"0.1.0": "1.0.0",
"0.1.1": "1.0.0",
"0.1.2": "1.1.0",
"0.1.3": "1.1.0"
}

View File

@@ -1,40 +1,14 @@
flags: name: start9-registry
library-only: version: 0.0.0
manual: false
default: false default-extensions:
description: Build for use with "yesod devel" - NoImplicitPrelude
dev: - GeneralizedNewtypeDeriving
manual: false - LambdaCase
default: false - MultiWayIf
description: Turn on development settings, like auto-reload templates. - NamedFieldPuns
library: - NumericUnderscores
source-dirs: src - OverloadedStrings
when:
- then:
cpp-options: -DDEVELOPMENT
ghc-options:
- -Wall
- -fwarn-tabs
- -O0
- -fdefer-typed-holes
else:
ghc-options:
- -Wall
- -fwarn-tabs
- -O2
- -fdefer-typed-holes
condition: (flag(dev)) || (flag(library-only))
tests:
start9-registry-test:
source-dirs: test
main: Spec.hs
ghc-options:
- -Wall
- -fdefer-typed-holes
dependencies:
- start9-registry
- hspec >=2.0.0
- yesod-test
dependencies: dependencies:
- base >=4.9.1.0 && <5 - base >=4.9.1.0 && <5
@@ -88,16 +62,24 @@ dependencies:
- yesod-static - yesod-static
- yesod-persistent >= 1.6 && < 1.7 - yesod-persistent >= 1.6 && < 1.7
default-extensions: library:
- NoImplicitPrelude source-dirs: src
- GeneralizedNewtypeDeriving when:
- LambdaCase - condition: (flag(dev)) || (flag(library-only))
- MultiWayIf then:
- NamedFieldPuns cpp-options: -DDEVELOPMENT
- NumericUnderscores ghc-options:
- OverloadedStrings - -Wall
name: start9-registry - -fwarn-tabs
version: 0.0.0 - -O0
- -fdefer-typed-holes
else:
ghc-options:
- -Wall
- -fwarn-tabs
- -O2
- -fdefer-typed-holes
executables: executables:
start9-registry: start9-registry:
source-dirs: app source-dirs: app
@@ -110,5 +92,28 @@ executables:
dependencies: dependencies:
- start9-registry - start9-registry
when: when:
- buildable: false - condition: flag(library-only)
condition: flag(library-only) buildable: false
tests:
start9-registry-test:
source-dirs: test
main: Main.hs
ghc-options:
- -Wall
- -fdefer-typed-holes
dependencies:
- start9-registry
- hspec
- yesod-test
- hedgehog
flags:
library-only:
manual: false
default: false
description: Build for use with "yesod devel"
dev:
manual: false
default: false
description: Turn on development settings, like auto-reload templates.

View File

@@ -40,20 +40,17 @@ instance Show FileExtension where
getAppsManifestR :: Handler TypedContent getAppsManifestR :: Handler TypedContent
getAppsManifestR = do getAppsManifestR = do
AppSettings{..} <- appSettings <$> getYesod appResourceDir <- (</> "apps" </> "apps.yaml") . resourcesDir . appSettings <$> getYesod
let appResourceDir = (resourcesDir . appSettings <$> getYesod) </> "apps" </> "apps.yaml"
respondSource typePlain $ CB.sourceFile appResourceDir .| awaitForever sendChunkBS respondSource typePlain $ CB.sourceFile appResourceDir .| awaitForever sendChunkBS
getSysR :: Extension "" -> Handler TypedContent getSysR :: Extension "" -> Handler TypedContent
getSysR e = do getSysR e = do
AppSettings{..} <- appSettings <$> getYesod sysResourceDir <- (</> "sys") . resourcesDir . appSettings <$> getYesod
let sysResourceDir = resourcesDir </> "sys"
getApp sysResourceDir e getApp sysResourceDir e
getAppR :: Extension "s9pk" -> Handler TypedContent getAppR :: Extension "s9pk" -> Handler TypedContent
getAppR e = do getAppR e = do
AppSettings{..} <- appSettings <$> getYesod appResourceDir <- (</> "apps" </> "apps.yaml") . resourcesDir . appSettings <$> getYesod
let appResourceDir = resourcesDir </> "apps" </> "apps.yaml"
getApp appResourceDir e getApp appResourceDir e
getApp :: KnownSymbol a => FilePath -> Extension a -> Handler TypedContent getApp :: KnownSymbol a => FilePath -> Extension a -> Handler TypedContent

View File

@@ -26,20 +26,20 @@ import System.FilePath ((</>))
getVersionR :: Handler AppVersionRes getVersionR :: Handler AppVersionRes
getVersionR = do getVersionR = do
AppSettings{..} <- appSettings <$> getYesod rv <- AppVersionRes . registryVersion . appSettings <$> getYesod
pure . AppVersionRes registryVersion $ Nothing pure . rv $ Nothing
getVersionAppR :: Text -> Handler (Maybe AppVersionRes) getVersionAppR :: Text -> Handler (Maybe AppVersionRes)
getVersionAppR appId = do getVersionAppR appId = do
AppSettings{..} <- appSettings <$> getYesod appsDir <- (</> "apps") . resourcesDir . appSettings <$> getYesod
getVersionWSpec (resourcesDir </> "apps") appExt getVersionWSpec appsDir appExt
where where
appExt = Extension (toS appId) :: Extension "s9pk" appExt = Extension (toS appId) :: Extension "s9pk"
getVersionSysR :: Text -> Handler (Maybe AppVersionRes) getVersionSysR :: Text -> Handler (Maybe AppVersionRes)
getVersionSysR sysAppId = runMaybeT $ do getVersionSysR sysAppId = runMaybeT $ do
AppSettings{..} <- appSettings <$> getYesod sysDir <- (</> "sys") . resourcesDir . appSettings <$> getYesod
avr <- MaybeT $ getVersionWSpec (resourcesDir </> "sys") sysExt avr <- MaybeT $ getVersionWSpec sysDir sysExt
minComp <- lift $ case sysAppId of minComp <- lift $ case sysAppId of
"agent" -> Just <$> meshCompanionCompatibility (appVersionVersion avr) "agent" -> Just <$> meshCompanionCompatibility (appVersionVersion avr)
_ -> pure Nothing _ -> pure Nothing
@@ -58,7 +58,7 @@ getVersionWSpec rootDir ext = do
pure $ liftA2 AppVersionRes av (pure Nothing) pure $ liftA2 AppVersionRes av (pure Nothing)
meshCompanionCompatibility :: AppVersion -> Handler AppVersion meshCompanionCompatibility :: AppVersion -> Handler AppVersion
meshCompanionCompatibility av = getsYesod appCompatibilityMap >>= \hm -> do meshCompanionCompatibility av = getsYesod appCompatibilityMap >>= \hm ->
case HM.lookup av hm of case HM.lookup av hm of
Nothing -> do Nothing -> do
$logError [i|MESH DEPLOYMENT "#{av}" HAS NO COMPATIBILITY ENTRY! FIX IMMEDIATELY|] $logError [i|MESH DEPLOYMENT "#{av}" HAS NO COMPATIBILITY ENTRY! FIX IMMEDIATELY|]

View File

@@ -43,6 +43,7 @@ extra-deps:
- protolude-0.2.4 - protolude-0.2.4
- git: https://github.com/CaptJakk/jose-jwt.git - git: https://github.com/CaptJakk/jose-jwt.git
commit: 63210e8d05543dac932ddfe5c212450beb88374c commit: 63210e8d05543dac932ddfe5c212450beb88374c
- haskell-src-exts-1.21.1@sha256:11d18ec3f463185f81b7819376b532e3087f8192cffc629aac5c9eec88897b35,4541
# 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,15 +6,11 @@ import Startlude
import TestImport import TestImport
spec :: Spec spec :: Spec
spec = do spec = describe "GET /apps" $
describe "GET /apps" $ do
withApp $ it "returns list of apps" $ do withApp $ it "returns list of apps" $ do
request $ do request $ do
setMethod "GET" setMethod "GET"
setUrl ("/apps" :: Text) setUrl ("/apps" :: Text)
printBody bodyContains "bitcoind"
bodyContains "" bodyContains "version: 0.18.1"
statusIs 200 statusIs 200

View File

@@ -3,9 +3,11 @@ module Main where
import Test.Hspec.Runner import Test.Hspec.Runner
import qualified Spec import qualified Spec
import Test.Hspec.Formatters import Test.Hspec.Formatters
import qualified Handler.AppSpec as A import Startlude
import GHC.IO.Encoding
main :: IO () main :: IO ()
main = do main = do
_ <- A.spec setLocaleEncoding utf8
hspecWith defaultConfig { configFormatter = Just progress } Spec.spec hspecWith defaultConfig { configFormatter = Just progress } Spec.spec

View File

@@ -1 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-} {-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-}