diff --git a/server/lib/api-tests/src/Test/DataConnector/MetadataApiSpec.hs b/server/lib/api-tests/src/Test/DataConnector/MetadataApiSpec.hs index b0ec577785e..a632ce4cb90 100644 --- a/server/lib/api-tests/src/Test/DataConnector/MetadataApiSpec.hs +++ b/server/lib/api-tests/src/Test/DataConnector/MetadataApiSpec.hs @@ -22,7 +22,7 @@ import Data.Aeson.KeyMap qualified as KM import Data.Aeson.Lens import Data.List.NonEmpty qualified as NE import Data.Vector qualified as Vector -import Harness.Backend.DataConnector.Chinook (ChinookTestEnv, NameFormatting (..)) +import Harness.Backend.DataConnector.Chinook (ChinookTestEnv, NameFormatting (..), ScalarTypes (..)) import Harness.Backend.DataConnector.Chinook qualified as Chinook import Harness.Backend.DataConnector.Chinook.Reference qualified as Reference import Harness.Backend.DataConnector.Chinook.Sqlite qualified as Sqlite @@ -122,7 +122,7 @@ schemaInspectionTests opts = describe "Schema and Source Inspection" $ do |] describe "get_table_info" $ do - it "success" $ \(testEnvironment@TestEnvironment {}, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}}) -> do + it "success" $ \(testEnvironment@TestEnvironment {}, Chinook.ChinookTestEnv {nameFormatting = NameFormatting {..}, scalarTypes = ScalarTypes {..}}) -> do let removeDescriptions (J.Object o) = J.Object (KM.delete "description" (removeDescriptions <$> o)) removeDescriptions (J.Array a) = J.Array (removeDescriptions <$> a) removeDescriptions x = x @@ -167,17 +167,17 @@ schemaInspectionTests opts = describe "Schema and Source Inspection" $ do columns: - name: *albumId nullable: false - type: number + type: *_stIntegerType insertable: *supportsInserts updatable: false - name: *artistId nullable: false - type: number + type: *_stIntegerType insertable: *supportsInserts updatable: *supportsUpdates - name: *title nullable: false - type: string + type: *_stStringType insertable: *supportsInserts updatable: *supportsUpdates name: *album diff --git a/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook.hs b/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook.hs index 8ad73144431..aa3adbe2e79 100644 --- a/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook.hs +++ b/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook.hs @@ -5,6 +5,7 @@ module Harness.Backend.DataConnector.Chinook ( ChinookTestEnv (..), NameFormatting (..), + ScalarTypes (..), mkChinookCloneTestEnvironment, mkChinookStaticTestEnvironment, setupChinookSourceAction, @@ -34,7 +35,9 @@ data ChinookTestEnv = ChinookTestEnv -- | Default configuration for the backend config that sets the agent configuration backendAgentConfig :: Aeson.Value, -- | Name formatting functions to correct for backend-specific naming rules - nameFormatting :: NameFormatting + nameFormatting :: NameFormatting, + -- | Backend-specific expected scalar types + scalarTypes :: ScalarTypes } data NameFormatting = NameFormatting @@ -47,13 +50,19 @@ data NameFormatting = NameFormatting _nfFormatForeignKeyName :: Text -> Text } +data ScalarTypes = ScalarTypes + { _stFloatType :: Text, + _stIntegerType :: Text, + _stStringType :: Text + } + -------------------------------------------------------------------------------- -- | Create a test environment that uses agent dataset cloning to clone a copy of the Chinook -- DB for the test and use that as the source config configured in HGE. -- This should be used with agents that support datasets. -mkChinookCloneTestEnvironment :: NameFormatting -> TestEnvironment -> Managed ChinookTestEnv -mkChinookCloneTestEnvironment nameFormatting testEnv = do +mkChinookCloneTestEnvironment :: NameFormatting -> ScalarTypes -> TestEnvironment -> Managed ChinookTestEnv +mkChinookCloneTestEnvironment nameFormatting scalarTypes testEnv = do backendTypeConfig <- getBackendTypeConfig testEnv `onNothing` fail "Unable to find backend type config in this test environment" agentUrl <- Fixture.backendServerUrl backendTypeConfig `onNothing` fail ("Backend " <> show (Fixture.backendType backendTypeConfig) <> " does not have a server url") cloneConfig <- API._dccrConfig <$> createManagedClone agentUrl testEnv (API.DatasetTemplateName "Chinook") @@ -65,16 +74,16 @@ mkChinookCloneTestEnvironment nameFormatting testEnv = do template: timeout: |] - pure $ ChinookTestEnv sourceConfig agentBackendConfig nameFormatting + pure $ ChinookTestEnv sourceConfig agentBackendConfig nameFormatting scalarTypes -- | Create a test environment that uses the source config specified to connect to a specific DB on the agent -- that contains the Chinook dataset. -- This should be used with agents that do not support datasets. -mkChinookStaticTestEnvironment :: NameFormatting -> Aeson.Value -> TestEnvironment -> Managed ChinookTestEnv -mkChinookStaticTestEnvironment nameFormatting sourceConfig testEnv = do +mkChinookStaticTestEnvironment :: NameFormatting -> ScalarTypes -> Aeson.Value -> TestEnvironment -> Managed ChinookTestEnv +mkChinookStaticTestEnvironment nameFormatting scalarTypes sourceConfig testEnv = do backendTypeConfig <- getBackendTypeConfig testEnv `onNothing` fail "Unable to find backend type config in this test environment" let agentBackendConfig = mkAgentBackendConfig backendTypeConfig - pure $ ChinookTestEnv sourceConfig agentBackendConfig nameFormatting + pure $ ChinookTestEnv sourceConfig agentBackendConfig nameFormatting scalarTypes -------------------------------------------------------------------------------- diff --git a/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook/Reference.hs b/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook/Reference.hs index e4c4980d925..e885ee5f347 100644 --- a/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook/Reference.hs +++ b/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook/Reference.hs @@ -14,7 +14,7 @@ where import Control.Monad.Managed (Managed) import Data.Aeson qualified as Aeson -import Harness.Backend.DataConnector.Chinook (ChinookTestEnv, NameFormatting (..)) +import Harness.Backend.DataConnector.Chinook (ChinookTestEnv, NameFormatting (..), ScalarTypes (..)) import Harness.Backend.DataConnector.Chinook qualified as Chinook import Harness.Quoter.Yaml (yaml) import Harness.Test.BackendType qualified as BackendType @@ -83,11 +83,19 @@ backendTypeConfig = -------------------------------------------------------------------------------- mkChinookStaticTestEnvironment :: TestEnvironment -> Managed ChinookTestEnv -mkChinookStaticTestEnvironment = Chinook.mkChinookStaticTestEnvironment nameFormatting sourceConfiguration +mkChinookStaticTestEnvironment = Chinook.mkChinookStaticTestEnvironment nameFormatting scalarTypes sourceConfiguration nameFormatting :: NameFormatting nameFormatting = NameFormatting id id id +scalarTypes :: ScalarTypes +scalarTypes = + ScalarTypes + { _stFloatType = "number", + _stIntegerType = "number", + _stStringType = "string" + } + -- | Reference Agent specific @sources@ entry @configuration@ field. sourceConfiguration :: Aeson.Value sourceConfiguration = diff --git a/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook/Sqlite.hs b/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook/Sqlite.hs index 72bff312a80..2e9bef7c165 100644 --- a/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook/Sqlite.hs +++ b/server/lib/test-harness/src/Harness/Backend/DataConnector/Chinook/Sqlite.hs @@ -13,7 +13,7 @@ where -------------------------------------------------------------------------------- import Control.Monad.Managed (Managed) -import Harness.Backend.DataConnector.Chinook (ChinookTestEnv, NameFormatting (..)) +import Harness.Backend.DataConnector.Chinook (ChinookTestEnv, NameFormatting (..), ScalarTypes (..)) import Harness.Backend.DataConnector.Chinook qualified as Chinook import Harness.Quoter.Yaml (yaml) import Harness.Test.BackendType qualified as BackendType @@ -107,7 +107,7 @@ backendTypeConfig = -------------------------------------------------------------------------------- mkChinookCloneTestEnvironment :: TestEnvironment -> Managed ChinookTestEnv -mkChinookCloneTestEnvironment = Chinook.mkChinookCloneTestEnvironment nameFormatting +mkChinookCloneTestEnvironment = Chinook.mkChinookCloneTestEnvironment nameFormatting scalarTypes nameFormatting :: NameFormatting nameFormatting = NameFormatting id id formatForeignKeyName @@ -118,6 +118,14 @@ formatForeignKeyName = \case "Artist" -> "Album.ArtistId->Artist.ArtistId" x -> x +scalarTypes :: ScalarTypes +scalarTypes = + ScalarTypes + { _stFloatType = "number", + _stIntegerType = "number", + _stStringType = "string" + } + chinookFixture :: Fixture ChinookTestEnv chinookFixture = Fixture