2022-04-10 07:47:15 +03:00
|
|
|
module Main (main) where
|
|
|
|
|
2022-09-17 05:19:22 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-12-05 05:14:40 +03:00
|
|
|
import Command (AgentOptions (..), Command (..), SandwichArguments (..), TestOptions (..), parseCommandLine)
|
2022-04-10 07:47:15 +03:00
|
|
|
import Data.Aeson.Text (encodeToLazyText)
|
2022-12-05 05:14:40 +03:00
|
|
|
import Data.Foldable (for_)
|
2022-04-10 07:47:15 +03:00
|
|
|
import Data.Text.Lazy.IO qualified as Text
|
2022-12-05 05:14:40 +03:00
|
|
|
import Hasura.Backends.DataConnector.API (openApiSchema)
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.API qualified as API
|
2022-12-05 05:14:40 +03:00
|
|
|
import Servant.Client ((//))
|
|
|
|
import System.Environment (withArgs)
|
2023-01-11 05:36:03 +03:00
|
|
|
import Test.AgentClient (AgentIOClient (..), guardCapabilitiesResponse, guardSchemaResponse, introduceAgentClient, mkAgentClientConfig, mkAgentIOClient)
|
2022-12-05 05:14:40 +03:00
|
|
|
import Test.Data (TestData, mkTestData)
|
2022-10-24 05:09:16 +03:00
|
|
|
import Test.DataExport (exportData)
|
2022-12-05 05:14:40 +03:00
|
|
|
import Test.Sandwich (runSandwichWithCommandLineArgs)
|
|
|
|
import Test.Sandwich.Options qualified as Sandwich
|
|
|
|
import Test.Specs.CapabilitiesSpec qualified
|
|
|
|
import Test.Specs.ConfigSpec qualified
|
|
|
|
import Test.Specs.ErrorSpec qualified
|
|
|
|
import Test.Specs.ExplainSpec qualified
|
|
|
|
import Test.Specs.HealthSpec qualified
|
|
|
|
import Test.Specs.MetricsSpec qualified
|
|
|
|
import Test.Specs.QuerySpec qualified
|
|
|
|
import Test.Specs.SchemaSpec qualified
|
|
|
|
import Test.TestHelpers (AgentTestSpec)
|
2022-04-10 07:47:15 +03:00
|
|
|
import Prelude
|
|
|
|
|
2022-09-17 05:19:22 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-06-02 08:22:44 +03:00
|
|
|
testSourceName :: API.SourceName
|
|
|
|
testSourceName = "dc-api-tests"
|
|
|
|
|
2022-12-05 05:14:40 +03:00
|
|
|
tests :: TestData -> API.SourceName -> API.Config -> API.CapabilitiesResponse -> AgentTestSpec
|
|
|
|
tests testData sourceName agentConfig API.CapabilitiesResponse {..} = do
|
|
|
|
Test.Specs.HealthSpec.spec sourceName agentConfig
|
|
|
|
Test.Specs.ConfigSpec.spec agentConfig _crConfigSchemaResponse
|
|
|
|
Test.Specs.CapabilitiesSpec.spec agentConfig _crCapabilities
|
|
|
|
Test.Specs.SchemaSpec.spec testData sourceName agentConfig _crCapabilities
|
|
|
|
Test.Specs.QuerySpec.spec testData sourceName agentConfig _crCapabilities
|
|
|
|
Test.Specs.ErrorSpec.spec testData sourceName agentConfig _crCapabilities
|
|
|
|
for_ (API._cMetrics _crCapabilities) \m -> Test.Specs.MetricsSpec.spec m
|
|
|
|
for_ (API._cExplain _crCapabilities) \_ -> Test.Specs.ExplainSpec.spec testData sourceName agentConfig _crCapabilities
|
2022-04-10 07:47:15 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
command <- parseCommandLine
|
|
|
|
case command of
|
2022-12-05 05:14:40 +03:00
|
|
|
Test TestOptions {..} (SandwichArguments arguments) -> withArgs arguments $ do
|
|
|
|
(AgentIOClient agentClient) <- mkAgentIOClient _toSensitiveOutputHandling _toAgentOptions
|
|
|
|
agentCapabilities <- (agentClient // API._capabilities) >>= guardCapabilitiesResponse
|
2023-01-11 05:36:03 +03:00
|
|
|
schemaResponse <- (agentClient // API._schema) testSourceName (_aoAgentConfig _toAgentOptions) >>= guardSchemaResponse
|
2022-12-05 05:14:40 +03:00
|
|
|
|
|
|
|
agentClientConfig <- mkAgentClientConfig _toSensitiveOutputHandling _toAgentOptions
|
2023-01-11 05:36:03 +03:00
|
|
|
let testData = mkTestData schemaResponse _toTestConfig
|
2022-12-05 05:14:40 +03:00
|
|
|
runSandwichWithCommandLineArgs Sandwich.defaultOptions $
|
|
|
|
introduceAgentClient agentClientConfig $
|
|
|
|
tests testData testSourceName (_aoAgentConfig _toAgentOptions) agentCapabilities
|
|
|
|
pure ()
|
2022-04-10 07:47:15 +03:00
|
|
|
ExportOpenAPISpec ->
|
2022-06-29 10:42:51 +03:00
|
|
|
Text.putStrLn $ encodeToLazyText openApiSchema
|
2022-10-24 05:09:16 +03:00
|
|
|
ExportData config ->
|
|
|
|
exportData config
|
2022-04-10 07:47:15 +03:00
|
|
|
|
|
|
|
pure ()
|