tests: convert DataConnector hspec tests from Context -> Fixture

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5388
GitOrigin-RevId: d645b360cd6f471c4bcaa18842cb2de2dc7a04d8
This commit is contained in:
Daniel Harvey 2022-08-10 08:52:57 +01:00 committed by hasura-bot
parent 4b86dfa4ad
commit 7bb5c2760a
8 changed files with 88 additions and 91 deletions

View File

@ -19,6 +19,8 @@ module Harness.Backend.DataConnector
mkLocalTestEnvironmentMock,
setupMock,
teardownMock,
setupFixtureAction,
setupMockAction,
)
where
@ -32,7 +34,7 @@ import Harness.Backend.DataConnector.MockAgent
import Harness.GraphqlEngine qualified as GraphqlEngine
import Harness.Http (healthCheck)
import Harness.Quoter.Yaml (yaml)
import Harness.Test.Fixture (BackendType (DataConnector), Options, defaultBackendTypeString)
import Harness.Test.Fixture (BackendType (DataConnector), Options, SetupAction (..), defaultBackendTypeString)
import Harness.TestEnvironment (TestEnvironment)
import Harness.Yaml (shouldReturnYaml)
import Hasura.Backends.DataConnector.API qualified as API
@ -63,6 +65,12 @@ dataconnector:
--------------------------------------------------------------------------------
-- Chinook Agent
setupFixtureAction :: Aeson.Value -> Aeson.Value -> TestEnvironment -> SetupAction
setupFixtureAction sourceMetadata backendConfig testEnv =
SetupAction
(setupFixture sourceMetadata backendConfig (testEnv, ()))
(const $ teardown (testEnv, ()))
-- | Setup the schema given source metadata and backend config.
setupFixture :: Aeson.Value -> Aeson.Value -> (TestEnvironment, ()) -> IO ()
setupFixture sourceMetadata backendConfig (testEnvironment, _) = do
@ -125,6 +133,12 @@ mkLocalTestEnvironmentMock _ = do
healthCheck $ "http://127.0.0.1:" <> show mockAgentPort <> "/health"
pure $ MockAgentEnvironment {..}
setupMockAction :: Aeson.Value -> Aeson.Value -> (TestEnvironment, MockAgentEnvironment) -> SetupAction
setupMockAction sourceMetadata backendConfig testEnv =
SetupAction
(setupMock sourceMetadata backendConfig testEnv)
(const $ teardownMock testEnv)
-- | Load the agent schema into HGE.
setupMock :: Aeson.Value -> Aeson.Value -> (TestEnvironment, MockAgentEnvironment) -> IO ()
setupMock sourceMetadata backendConfig (testEnvironment, _mockAgentEnvironment) = do

View File

@ -6,13 +6,12 @@ module Test.DataConnector.AggregateQuerySpec
where
import Data.Aeson qualified as Aeson
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector qualified as DataConnector
import Harness.GraphqlEngine qualified as GraphqlEngine
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
import Harness.Test.BackendType (BackendType (..), defaultBackendTypeString, defaultSource)
import Harness.Test.Context qualified as Context
import Harness.Test.Fixture qualified as Fixture
import Harness.TestEnvironment (TestEnvironment)
import Harness.Yaml (shouldReturnYaml)
import Hasura.Prelude
@ -20,16 +19,16 @@ import Test.Hspec (SpecWith, describe, it)
spec :: SpecWith TestEnvironment
spec =
Context.runWithLocalTestEnvironment
( NE.fromList
[ Context.Context
{ name = Context.Backend Context.DataConnector,
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
setup = DataConnector.setupFixture sourceMetadata DataConnector.defaultBackendConfig,
teardown = DataConnector.teardown,
customOptions = Nothing
}
]
Fixture.runWithLocalTestEnvironment
( [ (Fixture.fixture $ Fixture.Backend Fixture.DataConnector)
{ Fixture.setupTeardown = \(testEnv, _) ->
[ DataConnector.setupFixtureAction
sourceMetadata
DataConnector.defaultBackendConfig
testEnv
]
}
]
)
tests
@ -78,7 +77,7 @@ sourceMetadata =
--------------------------------------------------------------------------------
tests :: Context.Options -> SpecWith (TestEnvironment, a)
tests :: Fixture.Options -> SpecWith (TestEnvironment, a)
tests opts = describe "Aggregate Query Tests" $ do
describe "Nodes Tests" $ do
it "works with simple query" $ \(testEnvironment, _) ->

View File

@ -8,13 +8,12 @@ where
import Data.Aeson qualified as Aeson
import Data.Aeson.KeyMap qualified as KM
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector (TestCase (..))
import Harness.Backend.DataConnector qualified as DataConnector
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
import Harness.Test.BackendType (BackendType (..), defaultBackendTypeString, defaultSource)
import Harness.Test.Context qualified as Context
import Harness.Test.Fixture qualified as Fixture
import Harness.TestEnvironment (TestEnvironment)
import Hasura.Backends.DataConnector.API qualified as API
import Hasura.Prelude
@ -22,16 +21,14 @@ import Test.Hspec (SpecWith, describe, it)
spec :: SpecWith TestEnvironment
spec =
Context.runWithLocalTestEnvironment
( NE.fromList
[ Context.Context
{ name = Context.Backend Context.DataConnector,
mkLocalTestEnvironment = DataConnector.mkLocalTestEnvironmentMock,
setup = DataConnector.setupMock sourceMetadata DataConnector.mockBackendConfig,
teardown = DataConnector.teardownMock,
customOptions = Nothing
}
]
Fixture.runWithLocalTestEnvironment
( [ (Fixture.fixture $ Fixture.Backend Fixture.DataConnector)
{ Fixture.mkLocalTestEnvironment =
DataConnector.mkLocalTestEnvironmentMock,
Fixture.setupTeardown = \(testEnv, mockEnv) ->
[DataConnector.setupMockAction sourceMetadata DataConnector.mockBackendConfig (testEnv, mockEnv)]
}
]
)
tests
@ -80,7 +77,7 @@ sourceMetadata =
--------------------------------------------------------------------------------
tests :: Context.Options -> SpecWith (TestEnvironment, DataConnector.MockAgentEnvironment)
tests :: Fixture.Options -> SpecWith (TestEnvironment, DataConnector.MockAgentEnvironment)
tests opts = describe "Aggregate Query Tests" $ do
it "works with multiple nodes fields and through array relations" $
DataConnector.runMockedTest opts $

View File

@ -16,7 +16,7 @@ import Harness.Backend.DataConnector qualified as DataConnector
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
import Harness.Test.BackendType (BackendType (..), defaultBackendTypeString, defaultSource)
import Harness.Test.Context qualified as Context
import Harness.Test.Fixture qualified as Fixture
import Harness.TestEnvironment (TestEnvironment)
import Hasura.Backends.DataConnector.API qualified as API
import Hasura.Prelude
@ -26,16 +26,13 @@ import Test.Hspec (SpecWith, describe, it)
spec :: SpecWith TestEnvironment
spec =
Context.runWithLocalTestEnvironment
( NE.fromList
[ Context.Context
{ name = Context.Backend Context.DataConnector,
mkLocalTestEnvironment = DataConnector.mkLocalTestEnvironmentMock,
setup = DataConnector.setupMock sourceMetadata DataConnector.mockBackendConfig,
teardown = DataConnector.teardownMock,
customOptions = Nothing
}
]
Fixture.runWithLocalTestEnvironment
( [ (Fixture.fixture $ Fixture.Backend Fixture.DataConnector)
{ Fixture.mkLocalTestEnvironment = DataConnector.mkLocalTestEnvironmentMock,
Fixture.setupTeardown = \(testEnv, mockEnv) ->
[DataConnector.setupMockAction sourceMetadata DataConnector.mockBackendConfig (testEnv, mockEnv)]
}
]
)
tests
@ -88,7 +85,7 @@ sourceMetadata =
--------------------------------------------------------------------------------
tests :: Context.Options -> SpecWith (TestEnvironment, DataConnector.MockAgentEnvironment)
tests :: Fixture.Options -> SpecWith (TestEnvironment, DataConnector.MockAgentEnvironment)
tests opts = do
describe "Basic Tests" $ do
it "works with simple object query" $

View File

@ -8,13 +8,12 @@ where
import Data.Aeson qualified as Aeson
import Data.Aeson.KeyMap qualified as KM
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector (TestCase (..))
import Harness.Backend.DataConnector qualified as DataConnector
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
import Harness.Test.BackendType (BackendType (..), defaultBackendTypeString, defaultSource)
import Harness.Test.Context qualified as Context
import Harness.Test.Fixture qualified as Fixture
import Harness.TestEnvironment (TestEnvironment)
import Hasura.Backends.DataConnector.API qualified as API
import Hasura.Prelude
@ -22,16 +21,13 @@ import Test.Hspec (SpecWith, describe, it)
spec :: SpecWith TestEnvironment
spec =
Context.runWithLocalTestEnvironment
( NE.fromList
[ Context.Context
{ name = Context.Backend Context.DataConnector,
mkLocalTestEnvironment = DataConnector.mkLocalTestEnvironmentMock,
setup = DataConnector.setupMock sourceMetadata DataConnector.mockBackendConfig,
teardown = DataConnector.teardownMock,
customOptions = Nothing
}
]
Fixture.runWithLocalTestEnvironment
( [ (Fixture.fixture $ Fixture.Backend Fixture.DataConnector)
{ Fixture.mkLocalTestEnvironment = DataConnector.mkLocalTestEnvironmentMock,
Fixture.setupTeardown = \(testEnv, mockEnv) ->
[DataConnector.setupMockAction sourceMetadata DataConnector.mockBackendConfig (testEnv, mockEnv)]
}
]
)
tests
@ -64,7 +60,7 @@ sourceMetadata =
--------------------------------------------------------------------------------
tests :: Context.Options -> SpecWith (TestEnvironment, DataConnector.MockAgentEnvironment)
tests :: Fixture.Options -> SpecWith (TestEnvironment, DataConnector.MockAgentEnvironment)
tests opts = do
describe "Object Relationships Tests" $ do
it "works with multiple object relationships" $

View File

@ -10,13 +10,12 @@ where
import Data.Aeson qualified as Aeson
import Data.Aeson.KeyMap qualified as KM
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector (TestCase (..))
import Harness.Backend.DataConnector qualified as DataConnector
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
import Harness.Test.BackendType (BackendType (..), defaultBackendTypeString, defaultSource)
import Harness.Test.Context qualified as Context
import Harness.Test.Fixture qualified as Fixture
import Harness.TestEnvironment (TestEnvironment)
import Hasura.Backends.DataConnector.API qualified as API
import Hasura.Prelude
@ -26,16 +25,17 @@ import Test.Hspec (SpecWith, describe, it)
spec :: SpecWith TestEnvironment
spec =
Context.runWithLocalTestEnvironment
( NE.fromList
[ Context.Context
{ name = Context.Backend Context.DataConnector,
mkLocalTestEnvironment = DataConnector.mkLocalTestEnvironmentMock,
setup = DataConnector.setupMock sourceMetadata DataConnector.mockBackendConfig,
teardown = DataConnector.teardownMock,
customOptions = Nothing
}
]
Fixture.runWithLocalTestEnvironment
( [ (Fixture.fixture $ Fixture.Backend Fixture.DataConnector)
{ Fixture.mkLocalTestEnvironment = DataConnector.mkLocalTestEnvironmentMock,
Fixture.setupTeardown = \(testEnv, mockEnv) ->
[ DataConnector.setupMockAction
sourceMetadata
DataConnector.mockBackendConfig
(testEnv, mockEnv)
]
}
]
)
tests
@ -97,7 +97,7 @@ sourceMetadata =
--------------------------------------------------------------------------------
tests :: Context.Options -> SpecWith (TestEnvironment, DataConnector.MockAgentEnvironment)
tests :: Fixture.Options -> SpecWith (TestEnvironment, DataConnector.MockAgentEnvironment)
tests opts = do
describe "Basic Tests" $ do
it "works with configuration transformation Kriti template" $

View File

@ -9,13 +9,12 @@ where
--------------------------------------------------------------------------------
import Data.Aeson qualified as Aeson
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector qualified as DataConnector
import Harness.GraphqlEngine qualified as GraphqlEngine
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
import Harness.Test.BackendType (BackendType (DataConnector), defaultBackendTypeString, defaultSource)
import Harness.Test.Context qualified as Context
import Harness.Test.Fixture qualified as Fixture
import Harness.TestEnvironment (TestEnvironment)
import Harness.Yaml (shouldReturnYaml)
import Hasura.Prelude
@ -26,16 +25,16 @@ import Test.Hspec (SpecWith, describe, it)
spec :: SpecWith TestEnvironment
spec =
Context.runWithLocalTestEnvironment
( NE.fromList
[ Context.Context
{ name = Context.Backend Context.DataConnector,
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
setup = DataConnector.setupFixture sourceMetadata DataConnector.defaultBackendConfig,
teardown = DataConnector.teardown,
customOptions = Nothing
}
]
Fixture.runWithLocalTestEnvironment
( [ (Fixture.fixture $ Fixture.Backend Fixture.DataConnector)
{ Fixture.setupTeardown = \(testEnv, _) ->
[ DataConnector.setupFixtureAction
sourceMetadata
DataConnector.defaultBackendConfig
testEnv
]
}
]
)
tests
@ -104,7 +103,7 @@ configuration: {}
--------------------------------------------------------------------------------
tests :: Context.Options -> SpecWith (TestEnvironment, a)
tests :: Fixture.Options -> SpecWith (TestEnvironment, a)
tests opts = describe "Queries" $ do
describe "Basic Tests" $ do
it "works with simple object query" $ \(testEnvironment, _) ->

View File

@ -8,14 +8,13 @@ where
import Data.Aeson (Value)
import Data.ByteString (ByteString)
import Data.List.NonEmpty qualified as NE
import Harness.Backend.DataConnector (defaultBackendConfig)
import Harness.Backend.DataConnector qualified as DataConnector
import Harness.GraphqlEngine qualified as GraphqlEngine
import Harness.Quoter.Graphql (graphql)
import Harness.Quoter.Yaml (yaml)
import Harness.Test.BackendType (BackendType (..), defaultBackendTypeString, defaultSource)
import Harness.Test.Context qualified as Context
import Harness.Test.Fixture qualified as Fixture
import Harness.TestEnvironment (TestEnvironment)
import Harness.Yaml (shouldReturnYaml)
import Hasura.Prelude
@ -26,16 +25,12 @@ import Test.Hspec (SpecWith, describe, it)
spec :: SpecWith TestEnvironment
spec =
Context.runWithLocalTestEnvironment
( NE.fromList
[ Context.Context
{ name = Context.Backend Context.DataConnector,
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
setup = DataConnector.setupFixture sourceMetadata defaultBackendConfig,
teardown = DataConnector.teardown,
customOptions = Nothing
}
]
Fixture.runWithLocalTestEnvironment
( [ (Fixture.fixture $ Fixture.Backend Fixture.DataConnector)
{ Fixture.setupTeardown = \(testEnv, _) ->
[DataConnector.setupFixtureAction sourceMetadata defaultBackendConfig testEnv]
}
]
)
tests
@ -94,7 +89,7 @@ sourceMetadata =
configuration: {}
|]
tests :: Context.Options -> SpecWith (TestEnvironment, a)
tests :: Fixture.Options -> SpecWith (TestEnvironment, a)
tests opts = describe "SelectPermissionsSpec" $ do
it "permissions filter using _ceq that traverses an object relationship" $ \(testEnvironment, _) ->
shouldReturnYaml