diff --git a/server/tests-hspec/Harness/Backend/DataConnector.hs b/server/tests-hspec/Harness/Backend/DataConnector.hs index 16a13a34df3..8aec3c020a6 100644 --- a/server/tests-hspec/Harness/Backend/DataConnector.hs +++ b/server/tests-hspec/Harness/Backend/DataConnector.hs @@ -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 diff --git a/server/tests-hspec/Test/DataConnector/AggregateQuerySpec.hs b/server/tests-hspec/Test/DataConnector/AggregateQuerySpec.hs index 7b6a4ab6563..6cebd90867b 100644 --- a/server/tests-hspec/Test/DataConnector/AggregateQuerySpec.hs +++ b/server/tests-hspec/Test/DataConnector/AggregateQuerySpec.hs @@ -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, _) -> diff --git a/server/tests-hspec/Test/DataConnector/MockAgent/AggregateQuerySpec.hs b/server/tests-hspec/Test/DataConnector/MockAgent/AggregateQuerySpec.hs index af163010ce4..f2bc633db39 100644 --- a/server/tests-hspec/Test/DataConnector/MockAgent/AggregateQuerySpec.hs +++ b/server/tests-hspec/Test/DataConnector/MockAgent/AggregateQuerySpec.hs @@ -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 $ diff --git a/server/tests-hspec/Test/DataConnector/MockAgent/BasicQuerySpec.hs b/server/tests-hspec/Test/DataConnector/MockAgent/BasicQuerySpec.hs index d9f2454d52a..feb48d6d505 100644 --- a/server/tests-hspec/Test/DataConnector/MockAgent/BasicQuerySpec.hs +++ b/server/tests-hspec/Test/DataConnector/MockAgent/BasicQuerySpec.hs @@ -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" $ diff --git a/server/tests-hspec/Test/DataConnector/MockAgent/QueryRelationshipsSpec.hs b/server/tests-hspec/Test/DataConnector/MockAgent/QueryRelationshipsSpec.hs index d0958ea7ce8..8212f3fa404 100644 --- a/server/tests-hspec/Test/DataConnector/MockAgent/QueryRelationshipsSpec.hs +++ b/server/tests-hspec/Test/DataConnector/MockAgent/QueryRelationshipsSpec.hs @@ -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" $ diff --git a/server/tests-hspec/Test/DataConnector/MockAgent/TransformedConfigurationSpec.hs b/server/tests-hspec/Test/DataConnector/MockAgent/TransformedConfigurationSpec.hs index 5538738b252..8a6a53e94b6 100644 --- a/server/tests-hspec/Test/DataConnector/MockAgent/TransformedConfigurationSpec.hs +++ b/server/tests-hspec/Test/DataConnector/MockAgent/TransformedConfigurationSpec.hs @@ -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" $ diff --git a/server/tests-hspec/Test/DataConnector/QuerySpec.hs b/server/tests-hspec/Test/DataConnector/QuerySpec.hs index 511784ee4ab..0e0d6458926 100644 --- a/server/tests-hspec/Test/DataConnector/QuerySpec.hs +++ b/server/tests-hspec/Test/DataConnector/QuerySpec.hs @@ -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, _) -> diff --git a/server/tests-hspec/Test/DataConnector/SelectPermissionsSpec.hs b/server/tests-hspec/Test/DataConnector/SelectPermissionsSpec.hs index e9c4b20c453..b5e23f6a1b6 100644 --- a/server/tests-hspec/Test/DataConnector/SelectPermissionsSpec.hs +++ b/server/tests-hspec/Test/DataConnector/SelectPermissionsSpec.hs @@ -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