Skip to content

Commit

Permalink
REFACTOR: Gundeck tests refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Mar 21, 2019
1 parent e171466 commit ff18847
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
17 changes: 4 additions & 13 deletions services/gundeck/test/integration/API.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}

module API (TestSetup(..), tests) where
module API (tests) where

import Bilge
import Bilge.Assert
Expand All @@ -24,7 +24,7 @@ import System.Random (randomIO)
import System.Timeout (timeout)
import Test.Tasty
import Test.Tasty.HUnit
import Types
import TestSetup

import qualified Cassandra as Cql
import qualified Data.Aeson.Types as Aeson
Expand All @@ -45,15 +45,6 @@ import qualified Prelude
appName :: AppName
appName = AppName "test"

data TestSetup = TestSetup
{ manager :: Manager
, gundeck :: Gundeck
, cannon :: Cannon
, cannon2 :: Cannon
, brig :: Brig
, cass :: Cql.ClientState
}

type TestSignature a = Gundeck -> Cannon -> Brig -> Cql.ClientState -> Http a
type TestSignature2 a = Gundeck -> Cannon -> Cannon -> Brig -> Cql.ClientState -> Http a

Expand All @@ -62,14 +53,14 @@ test setup n h = testCase n runTest
where
runTest = do
s <- setup
void $ runHttpT (manager s) (h (gundeck s) (cannon s) (brig s) (cass s))
void $ runHttpT (s ^. tsManager) (h (s ^. tsGundeck) (s ^. tsCannon) (s ^. tsBrig) (s ^. tsCass))

test2 :: IO TestSetup -> TestName -> (TestSignature2 a) -> TestTree
test2 setup n h = testCase n runTest
where
runTest = do
s <- setup
void $ runHttpT (manager s) (h (gundeck s) (cannon s) (cannon2 s) (brig s) (cass s))
void $ runHttpT (s ^. tsManager) (h (s ^. tsGundeck) (s ^. tsCannon) (s ^. tsCannon2) (s ^. tsBrig) (s ^. tsCass))

tests :: IO TestSetup -> TestTree
tests s = testGroup "Gundeck integration tests" [
Expand Down
22 changes: 11 additions & 11 deletions services/gundeck/test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ import OpenSSL (withOpenSSL)
import Options.Applicative
import Test.Tasty
import Test.Tasty.Options
import Types
import Util.Options
import Util.Options.Common
import Util.Test
import TestSetup

import qualified API
import qualified System.Logger as Logger

data IntegrationConfig = IntegrationConfig
-- internal endpoints
{ gundeck :: Endpoint
, cannon :: Endpoint
, cannon2 :: Endpoint
, brig :: Endpoint
{ gundeckEndpoint :: Endpoint
, cannonEndpoint :: Endpoint
, cannon2Endpoint :: Endpoint
, brigEndpoint :: Endpoint
} deriving (Show, Generic)

instance FromJSON IntegrationConfig
Expand All @@ -39,7 +39,7 @@ newtype ServiceConfigFile = ServiceConfigFile String
deriving (Eq, Ord, Typeable)

instance IsOption ServiceConfigFile where
defaultValue = ServiceConfigFile "/etc/wire/gundeck/conf/gundeck.yaml"
defaultValue = ServiceConfigFile "/etc/wire/gundeckEndpoint/conf/gundeckEndpoint.yaml"
parseValue = fmap ServiceConfigFile . safeRead
optionName = return "service-config"
optionHelp = return "Service config file to read from"
Expand Down Expand Up @@ -74,18 +74,18 @@ main = withOpenSSL $ runTests go
let local p = Endpoint { _epHost = "127.0.0.1", _epPort = p }
gConf <- handleParseError =<< decodeFileEither gFile
iConf <- handleParseError =<< decodeFileEither iFile
g <- Gundeck . mkRequest <$> optOrEnv gundeck iConf (local . read) "GUNDECK_WEB_PORT"
c <- Cannon . mkRequest <$> optOrEnv cannon iConf (local . read) "CANNON_WEB_PORT"
c2 <- Cannon . mkRequest <$> optOrEnv cannon2 iConf (local . read) "CANNON2_WEB_PORT"
b <- Brig . mkRequest <$> optOrEnv brig iConf (local . read) "BRIG_WEB_PORT"
g <- Gundeck . mkRequest <$> optOrEnv gundeckEndpoint iConf (local . read) "GUNDECK_WEB_PORT"
c <- Cannon . mkRequest <$> optOrEnv cannonEndpoint iConf (local . read) "CANNON_WEB_PORT"
c2 <- Cannon . mkRequest <$> optOrEnv cannon2Endpoint iConf (local . read) "CANNON2_WEB_PORT"
b <- Brig . mkRequest <$> optOrEnv brigEndpoint iConf (local . read) "BRIG_WEB_PORT"
ch <- optOrEnv (\v -> v^.optCassandra.casEndpoint.epHost) gConf pack "GUNDECK_CASSANDRA_HOST"
cp <- optOrEnv (\v -> v^.optCassandra.casEndpoint.epPort) gConf read "GUNDECK_CASSANDRA_PORT"
ck <- optOrEnv (\v -> v^.optCassandra.casKeyspace) gConf pack "GUNDECK_CASSANDRA_KEYSPACE"

lg <- Logger.new Logger.defSettings
db <- defInitCassandra ck ch cp lg

return $ API.TestSetup m g c c2 b db
return $ TestSetup m g c c2 b db

releaseOpts _ = return ()

Expand Down
22 changes: 22 additions & 0 deletions services/gundeck/test/integration/TestSetup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module TestSetup where

import Imports
import Util.Options
import Bilge
import Control.Lens (makeLenses)
import qualified Cassandra as Cql

newtype Brig = Brig { runBrig :: Request -> Request }
newtype Cannon = Cannon { runCannon :: Request -> Request }
newtype Gundeck = Gundeck { runGundeck :: Request -> Request }

data TestSetup = TestSetup
{ _tsManager :: Manager
, _tsGundeck :: Gundeck
, _tsCannon :: Cannon
, _tsCannon2 :: Cannon
, _tsBrig :: Brig
, _tsCass :: Cql.ClientState
}

makeLenses ''TestSetup
7 changes: 0 additions & 7 deletions services/gundeck/test/integration/Types.hs

This file was deleted.

0 comments on commit ff18847

Please sign in to comment.