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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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