mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
server/tests-hspec: porting more tests to fixture
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5404 GitOrigin-RevId: 0be4f50b17765a8f0b1fb37944777ead7ec6bfc9
This commit is contained in:
parent
3855efa9a5
commit
c08bb5377f
@ -3,14 +3,12 @@
|
||||
-- | All tests related to computed fields in a BigQuery source
|
||||
module Test.BigQuery.ComputedFieldSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Data.Text qualified as T
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.Exceptions (finally)
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (interpolateYaml, yaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (SchemaName (..), Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -22,162 +20,21 @@ import Test.Hspec (SpecWith, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = bigquerySetup,
|
||||
teardown = bigqueryTeardown,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ BigQuery.setupTablesAction schema testEnv
|
||||
]
|
||||
<> setupFunctions testEnv
|
||||
<> setupMetadata testEnv
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
-- ** Setup and teardown
|
||||
-- ** Schema
|
||||
|
||||
bigquerySetup :: (TestEnvironment, ()) -> IO ()
|
||||
bigquerySetup (testEnv, ()) = do
|
||||
BigQuery.setup [authorTable, articleTable] (testEnv, ())
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
|
||||
-- Create functions in BigQuery
|
||||
BigQuery.runSql_ (createFunctionsSQL schemaName)
|
||||
|
||||
-- Add computed fields and define select permissions
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bulk
|
||||
args:
|
||||
- type: bigquery_add_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: search_articles_1
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
definition:
|
||||
function:
|
||||
dataset: *schemaName
|
||||
name: fetch_articles_returns_table
|
||||
argument_mapping:
|
||||
a_id: id
|
||||
|
||||
- type: bigquery_add_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: search_articles_2
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
definition:
|
||||
function:
|
||||
dataset: *schemaName
|
||||
name: fetch_articles
|
||||
argument_mapping:
|
||||
a_id: id
|
||||
return_table:
|
||||
name: article
|
||||
dataset: *schemaName
|
||||
|
||||
# Role user_1 has select permissions on author and article tables.
|
||||
# user_1 can query search_articles_1 computed field.
|
||||
- type: bigquery_create_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
role: user_1
|
||||
permission:
|
||||
columns: '*'
|
||||
filter: {}
|
||||
computed_fields:
|
||||
- search_articles_1
|
||||
|
||||
- type: bigquery_create_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: article
|
||||
role: user_1
|
||||
permission:
|
||||
columns: '*'
|
||||
filter: {}
|
||||
|
||||
# Role user_2 has select permissions only on author table.
|
||||
- type: bigquery_create_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
role: user_2
|
||||
permission:
|
||||
columns: '*'
|
||||
filter: {}
|
||||
|]
|
||||
|
||||
bigqueryTeardown :: (TestEnvironment, ()) -> IO ()
|
||||
bigqueryTeardown (testEnv, ()) = do
|
||||
-- Drop permissions and computed fields metadata
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
|
||||
let dropComputedFieldsYaml =
|
||||
[yaml|
|
||||
type: bulk
|
||||
args:
|
||||
- type: bigquery_drop_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
role: user_1
|
||||
|
||||
- type: bigquery_drop_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: article
|
||||
role: user_1
|
||||
|
||||
- type: bigquery_drop_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
role: user_2
|
||||
|
||||
- type: bigquery_drop_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: search_articles_1
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
|
||||
- type: bigquery_drop_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: search_articles_2
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
|]
|
||||
finally
|
||||
(GraphqlEngine.postMetadata_ testEnv dropComputedFieldsYaml)
|
||||
( finally
|
||||
-- Drop functions in BigQuery database
|
||||
(BigQuery.runSql_ (dropFunctionsSQL schemaName))
|
||||
-- Teardown schema
|
||||
(BigQuery.teardown [authorTable, articleTable] (testEnv, ()))
|
||||
)
|
||||
schema :: [Table]
|
||||
schema = [authorTable, articleTable]
|
||||
|
||||
authorTable :: Table
|
||||
authorTable =
|
||||
@ -226,6 +83,53 @@ articleTable =
|
||||
]
|
||||
}
|
||||
|
||||
-- ** Setup and teardown
|
||||
|
||||
setupFunctions :: TestEnvironment -> [Fixture.SetupAction]
|
||||
setupFunctions testEnv =
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
articleTableSQL = unSchemaName schemaName <> ".article"
|
||||
in [ Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "CREATE TABLE FUNCTION ",
|
||||
fetch_articles_returns_table schemaName,
|
||||
"(a_id INT64, search STRING)",
|
||||
"RETURNS TABLE<id INT64, title STRING, content STRING>",
|
||||
"AS (",
|
||||
"SELECT t.id, t.title, t.content FROM",
|
||||
articleTableSQL,
|
||||
"AS t WHERE t.author_id = a_id and (t.title LIKE `search` OR t.content LIKE `search`)",
|
||||
");"
|
||||
],
|
||||
Fixture.teardownAction = \_ ->
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
"DROP TABLE FUNCTION " <> fetch_articles_returns_table schemaName <> ";"
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "CREATE TABLE FUNCTION ",
|
||||
fetch_articles schemaName,
|
||||
"(a_id INT64, search STRING)",
|
||||
"AS (",
|
||||
"SELECT t.* FROM",
|
||||
articleTableSQL,
|
||||
"AS t WHERE t.author_id = a_id and (t.title LIKE `search` OR t.content LIKE `search`)",
|
||||
");"
|
||||
],
|
||||
Fixture.teardownAction = \_ ->
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
"DROP TABLE FUNCTION " <> fetch_articles schemaName <> ";"
|
||||
}
|
||||
]
|
||||
|
||||
fetch_articles_returns_table :: SchemaName -> T.Text
|
||||
fetch_articles_returns_table schemaName =
|
||||
unSchemaName schemaName <> ".fetch_articles_returns_table"
|
||||
@ -234,43 +138,175 @@ fetch_articles :: SchemaName -> T.Text
|
||||
fetch_articles schemaName =
|
||||
unSchemaName schemaName <> ".fetch_articles"
|
||||
|
||||
createFunctionsSQL :: SchemaName -> String
|
||||
createFunctionsSQL schemaName =
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "CREATE TABLE FUNCTION ",
|
||||
fetch_articles_returns_table schemaName,
|
||||
"(a_id INT64, search STRING)",
|
||||
"RETURNS TABLE<id INT64, title STRING, content STRING>",
|
||||
"AS (",
|
||||
"SELECT t.id, t.title, t.content FROM",
|
||||
articleTableSQL,
|
||||
"AS t WHERE t.author_id = a_id and (t.title LIKE `search` OR t.content LIKE `search`)",
|
||||
");"
|
||||
]
|
||||
<> [ "CREATE TABLE FUNCTION ",
|
||||
fetch_articles schemaName,
|
||||
"(a_id INT64, search STRING)",
|
||||
"AS (",
|
||||
"SELECT t.* FROM",
|
||||
articleTableSQL,
|
||||
"AS t WHERE t.author_id = a_id and (t.title LIKE `search` OR t.content LIKE `search`)",
|
||||
");"
|
||||
]
|
||||
where
|
||||
articleTableSQL = unSchemaName schemaName <> ".article"
|
||||
|
||||
dropFunctionsSQL :: SchemaName -> String
|
||||
dropFunctionsSQL schemaName =
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "DROP TABLE FUNCTION " <> fetch_articles_returns_table schemaName <> ";",
|
||||
"DROP TABLE FUNCTION " <> fetch_articles schemaName <> ";"
|
||||
setupMetadata :: TestEnvironment -> [Fixture.SetupAction]
|
||||
setupMetadata testEnv =
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
in -- Add computed fields and define select permissions
|
||||
[ Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bigquery_add_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: search_articles_1
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
definition:
|
||||
function:
|
||||
dataset: *schemaName
|
||||
name: fetch_articles_returns_table
|
||||
argument_mapping:
|
||||
a_id: id
|
||||
|],
|
||||
Fixture.teardownAction = \_ ->
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bigquery_drop_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: search_articles_1
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
|]
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bigquery_add_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: search_articles_2
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
definition:
|
||||
function:
|
||||
dataset: *schemaName
|
||||
name: fetch_articles
|
||||
argument_mapping:
|
||||
a_id: id
|
||||
return_table:
|
||||
name: article
|
||||
dataset: *schemaName
|
||||
|],
|
||||
Fixture.teardownAction = \_ ->
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bigquery_drop_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: search_articles_2
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
|]
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
# Role user_1 has select permissions on author and article tables.
|
||||
# user_1 can query search_articles_1 computed field.
|
||||
type: bigquery_create_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
role: user_1
|
||||
permission:
|
||||
columns: '*'
|
||||
filter: {}
|
||||
computed_fields:
|
||||
- search_articles_1
|
||||
|],
|
||||
Fixture.teardownAction = \_ ->
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
args:
|
||||
type: bigquery_drop_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
role: user_1
|
||||
|]
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bigquery_create_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: article
|
||||
role: user_1
|
||||
permission:
|
||||
columns: '*'
|
||||
filter: {}
|
||||
|],
|
||||
Fixture.teardownAction = \_ ->
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bigquery_drop_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: article
|
||||
role: user_1
|
||||
|]
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
# Role user_2 has select permissions only on author table.
|
||||
type: bigquery_create_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
role: user_2
|
||||
permission:
|
||||
columns: '*'
|
||||
filter: {}
|
||||
|],
|
||||
Fixture.teardownAction = \_ ->
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bigquery_drop_select_permission
|
||||
args:
|
||||
source: bigquery
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
role: user_2
|
||||
|]
|
||||
}
|
||||
]
|
||||
|
||||
-- * Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
it "Query with computed fields" $ \testEnv -> do
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
|
@ -3,12 +3,11 @@
|
||||
-- | All tests related to metadata API for computed fields in a BigQuery source
|
||||
module Test.BigQuery.Metadata.ComputedFieldSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Data.Text qualified as T
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Yaml (interpolateYaml, yaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (SchemaName (..), Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -20,39 +19,20 @@ import Test.Hspec (SpecWith, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = bigquerySetup,
|
||||
teardown = bigqueryTeardown,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ BigQuery.setupTablesAction schema testEnv
|
||||
]
|
||||
<> setupFunctions testEnv
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
-- ** Setup and teardown
|
||||
-- ** Schema
|
||||
|
||||
bigquerySetup :: (TestEnvironment, ()) -> IO ()
|
||||
bigquerySetup (testEnv, ()) = do
|
||||
BigQuery.setup [authorTable, articleTable] (testEnv, ())
|
||||
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
|
||||
-- Create functions in BigQuery
|
||||
BigQuery.runSql_ (createFunctionsSQL schemaName)
|
||||
|
||||
bigqueryTeardown :: (TestEnvironment, ()) -> IO ()
|
||||
bigqueryTeardown (testEnv, ()) = do
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
|
||||
-- Drop functions in BigQuery database
|
||||
BigQuery.runSql_ (dropFunctionsSQL schemaName)
|
||||
|
||||
-- Teardown schema
|
||||
BigQuery.teardown [authorTable, articleTable] (testEnv, ())
|
||||
schema :: [Table]
|
||||
schema = [authorTable, articleTable]
|
||||
|
||||
authorTable :: Schema.Table
|
||||
authorTable =
|
||||
@ -76,6 +56,84 @@ articleTable =
|
||||
tablePrimaryKey = ["id"]
|
||||
}
|
||||
|
||||
-- ** Setup and teardown
|
||||
|
||||
setupFunctions :: TestEnvironment -> [Fixture.SetupAction]
|
||||
setupFunctions testEnv =
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
articleTableSQL = unSchemaName schemaName <> ".article"
|
||||
in [ Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "CREATE TABLE FUNCTION ",
|
||||
fetch_articles_returns_table schemaName,
|
||||
"(a_id INT64, search STRING)",
|
||||
"RETURNS TABLE<id INT64, title STRING, content STRING>",
|
||||
"AS (",
|
||||
"SELECT t.id, t.title, t.content FROM",
|
||||
articleTableSQL,
|
||||
"AS t WHERE t.author_id = a_id and (t.title LIKE `search` OR t.content LIKE `search`)",
|
||||
");"
|
||||
],
|
||||
Fixture.teardownAction = \_ ->
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
"DROP TABLE FUNCTION " <> fetch_articles_returns_table schemaName <> ";"
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "CREATE TABLE FUNCTION ",
|
||||
fetch_articles schemaName,
|
||||
"(a_id INT64, search STRING)",
|
||||
"AS (",
|
||||
"SELECT t.* FROM",
|
||||
articleTableSQL,
|
||||
"AS t WHERE t.author_id = a_id and (t.title LIKE `search` OR t.content LIKE `search`)",
|
||||
");"
|
||||
],
|
||||
Fixture.teardownAction = \_ ->
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
"DROP TABLE FUNCTION " <> fetch_articles schemaName <> ";"
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "CREATE TABLE FUNCTION ",
|
||||
function_no_args schemaName <> "()",
|
||||
"AS (",
|
||||
"SELECT t.* FROM",
|
||||
articleTableSQL,
|
||||
"AS t);"
|
||||
],
|
||||
Fixture.teardownAction = \_ ->
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
"DROP TABLE FUNCTION " <> function_no_args schemaName <> ";"
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "CREATE FUNCTION ",
|
||||
add_int schemaName <> "(a INT64, b INT64)",
|
||||
"RETURNS INT64 AS (a + b);"
|
||||
],
|
||||
Fixture.teardownAction = \_ ->
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
"DROP FUNCTION " <> add_int schemaName <> ";"
|
||||
}
|
||||
]
|
||||
|
||||
fetch_articles_returns_table :: SchemaName -> T.Text
|
||||
fetch_articles_returns_table schemaName =
|
||||
unSchemaName schemaName <> ".fetch_articles_returns_table"
|
||||
@ -92,57 +150,9 @@ add_int :: SchemaName -> T.Text
|
||||
add_int schemaName =
|
||||
unSchemaName schemaName <> ".add_int"
|
||||
|
||||
createFunctionsSQL :: SchemaName -> String
|
||||
createFunctionsSQL schemaName =
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "CREATE TABLE FUNCTION ",
|
||||
fetch_articles_returns_table schemaName,
|
||||
"(a_id INT64, search STRING)",
|
||||
"RETURNS TABLE<id INT64, title STRING, content STRING>",
|
||||
"AS (",
|
||||
"SELECT t.id, t.title, t.content FROM",
|
||||
articleTableSQL,
|
||||
"AS t WHERE t.author_id = a_id and (t.title LIKE `search` OR t.content LIKE `search`)",
|
||||
");"
|
||||
]
|
||||
<> [ "CREATE TABLE FUNCTION ",
|
||||
fetch_articles schemaName,
|
||||
"(a_id INT64, search STRING)",
|
||||
"AS (",
|
||||
"SELECT t.* FROM",
|
||||
articleTableSQL,
|
||||
"AS t WHERE t.author_id = a_id and (t.title LIKE `search` OR t.content LIKE `search`)",
|
||||
");"
|
||||
]
|
||||
<> [ "CREATE TABLE FUNCTION ",
|
||||
function_no_args schemaName <> "()",
|
||||
"AS (",
|
||||
"SELECT t.* FROM",
|
||||
articleTableSQL,
|
||||
"AS t);"
|
||||
]
|
||||
-- A scalar function
|
||||
<> [ "CREATE FUNCTION ",
|
||||
add_int schemaName <> "(a INT64, b INT64)",
|
||||
"RETURNS INT64 AS (a + b);"
|
||||
]
|
||||
where
|
||||
articleTableSQL = unSchemaName schemaName <> ".article"
|
||||
|
||||
dropFunctionsSQL :: SchemaName -> String
|
||||
dropFunctionsSQL schemaName =
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "DROP TABLE FUNCTION " <> fetch_articles_returns_table schemaName <> ";",
|
||||
"DROP TABLE FUNCTION " <> fetch_articles schemaName <> ";",
|
||||
"DROP TABLE FUNCTION " <> function_no_args schemaName <> ";",
|
||||
"DROP FUNCTION " <> add_int schemaName <> ";"
|
||||
]
|
||||
|
||||
-- * Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
it "Add computed field with non exist function - exception" $ \testEnv -> do
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
|
@ -6,12 +6,11 @@
|
||||
module Test.BigQuery.TypeInterpretationSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.GraphqlEngine (postGraphql)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (interpolateYaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -21,17 +20,13 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = BigQuery.setup schema,
|
||||
teardown = BigQuery.teardown schema,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ BigQuery.setupTablesAction schema testEnv
|
||||
]
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -113,7 +108,7 @@ schema =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
let shouldBe :: IO Value -> Value -> IO ()
|
||||
shouldBe = shouldReturnYaml opts
|
||||
|
@ -6,12 +6,11 @@
|
||||
-- - Postgres: https://hasura.io/docs/latest/graphql/core/databases/postgres/schema/custom-field-names/#expose-table-root-fields-with-a-different-name-in-the-graphql-api
|
||||
module Test.CustomRootFieldsSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (yaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -25,24 +24,21 @@ import Test.Hspec (SpecWith, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = postgresSetup,
|
||||
teardown = Postgres.teardown schema,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnv
|
||||
]
|
||||
<> postgresCreateCustomNames testEnv
|
||||
}
|
||||
]
|
||||
streamingSubscriptionCustomRootFieldTests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- * Tests
|
||||
|
||||
streamingSubscriptionCustomRootFieldTests :: Context.Options -> SpecWith TestEnvironment
|
||||
streamingSubscriptionCustomRootFieldTests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
streamingSubscriptionCustomRootFieldTests opts = do
|
||||
-- TODO: At the time of writing this, there's no easy way to make a subscription
|
||||
-- request in the tests-hspec. When we do support that, we can add a new test that tests
|
||||
@ -94,37 +90,54 @@ schema =
|
||||
|
||||
-- ** Postgres backend
|
||||
|
||||
postgresSetup :: (TestEnvironment, ()) -> IO ()
|
||||
postgresSetup (testEnvironment, localTestEnvironment) = do
|
||||
Postgres.setup schema (testEnvironment, localTestEnvironment)
|
||||
postgresCreateCustomNames testEnvironment
|
||||
|
||||
postgresCreateCustomNames :: TestEnvironment -> IO ()
|
||||
postgresCreateCustomNames testEnvironment = do
|
||||
let source = Context.defaultBackendTypeString Context.Postgres
|
||||
in GraphqlEngine.postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: bulk
|
||||
args:
|
||||
- type: pg_set_table_customization
|
||||
args:
|
||||
source: *source
|
||||
table:
|
||||
schema: hasura
|
||||
name: logs
|
||||
configuration:
|
||||
custom_root_fields:
|
||||
"select_stream": "LogsStream"
|
||||
- type: pg_create_select_permission
|
||||
args:
|
||||
source: *source
|
||||
table:
|
||||
schema: hasura
|
||||
name: logs
|
||||
role: user
|
||||
permission:
|
||||
columns: "*"
|
||||
filter: {}
|
||||
subscription_root_fields: ["select_stream"]
|
||||
|]
|
||||
postgresCreateCustomNames :: TestEnvironment -> [Fixture.SetupAction]
|
||||
postgresCreateCustomNames testEnv = do
|
||||
let source = Fixture.defaultBackendTypeString Fixture.Postgres
|
||||
in [ Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: pg_set_table_customization
|
||||
args:
|
||||
source: *source
|
||||
table:
|
||||
schema: hasura
|
||||
name: logs
|
||||
configuration:
|
||||
custom_root_fields:
|
||||
"select_stream": "LogsStream"
|
||||
|],
|
||||
Fixture.teardownAction = \_ -> pure ()
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: pg_create_select_permission
|
||||
args:
|
||||
source: *source
|
||||
table:
|
||||
schema: hasura
|
||||
name: logs
|
||||
role: user
|
||||
permission:
|
||||
columns: "*"
|
||||
filter: {}
|
||||
subscription_root_fields: ["select_stream"]
|
||||
|],
|
||||
Fixture.teardownAction = \_ ->
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: pg_drop_select_permission
|
||||
args:
|
||||
source: *source
|
||||
table:
|
||||
schema: hasura
|
||||
name: logs
|
||||
role: user
|
||||
|]
|
||||
}
|
||||
]
|
||||
|
@ -5,14 +5,13 @@
|
||||
-- See "Hasura.Backend.Postgres.SQL.RenameIdentifiers" for more details.
|
||||
module Test.LongIdentifiersSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.BigQuery qualified as Bigquery
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (interpolateYaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -24,56 +23,45 @@ import Test.Hspec (SpecWith, it)
|
||||
-- Preamble
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ -- Create table fails currently becasuse we postfix table names for some reason
|
||||
-- which makes the valid table name go over the limit
|
||||
--
|
||||
-- Context.Context
|
||||
-- { name = Context.Backend Context.MySQL,
|
||||
-- mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
-- setup = Mysql.setup schema,
|
||||
-- teardown = Mysql.teardown schema,
|
||||
-- customOptions = Nothing
|
||||
-- },
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Postgres.setup schema,
|
||||
teardown = Postgres.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
-- Create table fails currently on a weird error:
|
||||
-- > relation "i_need_a_table_with_a_long_na_i_need_a_column_with_a_long_n_seq" already exists
|
||||
--
|
||||
-- Context.Context
|
||||
-- { name = Context.Backend Context.Citus,
|
||||
-- mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
-- setup = Citus.setup schema,
|
||||
-- teardown = Citus.teardown schema,
|
||||
-- customOptions = Nothing
|
||||
-- },
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.SQLServer,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Sqlserver.setup schema,
|
||||
teardown = Sqlserver.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Bigquery.setup schema,
|
||||
teardown = Bigquery.teardown schema,
|
||||
customOptions =
|
||||
Just $
|
||||
Context.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
spec = do
|
||||
Fixture.run
|
||||
[ -- Create table fails currently becasuse we postfix table names for some reason
|
||||
-- which makes the valid table name go over the limit
|
||||
--
|
||||
-- (Fixture.fixture $ Fixture.Backend Fixture.MySQL)
|
||||
-- { Fixture.setupTeardown = \(testEnv, _) ->
|
||||
-- [ Mysql.setupTablesAction schema testEnv
|
||||
-- ]
|
||||
-- },
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
-- Create table fails currently on a weird error:
|
||||
-- > relation "i_need_a_table_with_a_long_na_i_need_a_column_with_a_long_n_seq" already exists
|
||||
--
|
||||
-- (Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
||||
-- { Fixture.setupTeardown = \(testEnv, _) ->
|
||||
-- [ Citus.setupTablesAction schema testEnv
|
||||
-- ]
|
||||
-- },
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Sqlserver.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ BigQuery.setupTablesAction schema testEnv
|
||||
],
|
||||
Fixture.customOptions =
|
||||
Just $
|
||||
Fixture.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -122,7 +110,7 @@ longtable =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
it "select long table" $ \testEnvironment -> do
|
||||
let schemaName = Schema.getSchemaName testEnvironment
|
||||
|
@ -6,13 +6,12 @@
|
||||
module Test.Postgres.TimestampSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Citus qualified as Citus
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.GraphqlEngine (postGraphql)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (yaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -25,24 +24,18 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Postgres.setup schema,
|
||||
teardown = Postgres.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.Citus,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Citus.setup schema,
|
||||
teardown = Citus.teardown schema,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Citus.setupTablesAction schema testEnv
|
||||
]
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -60,7 +53,7 @@ schema =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
let shouldBe :: IO Value -> Value -> IO ()
|
||||
shouldBe = shouldReturnYaml opts
|
||||
|
@ -9,7 +9,6 @@
|
||||
module Test.Queries.NestedObjectSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.Backend.Citus qualified as Citus
|
||||
import Harness.Backend.Mysql qualified as Mysql
|
||||
@ -18,8 +17,7 @@ import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.GraphqlEngine (postGraphql)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (interpolateYaml)
|
||||
import Harness.Test.Context (Options (..))
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -32,49 +30,38 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec = do
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.MySQL,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Mysql.setup schema,
|
||||
teardown = Mysql.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Postgres.setup schema,
|
||||
teardown = Postgres.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.Citus,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Citus.setup schema,
|
||||
teardown = Citus.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.SQLServer,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Sqlserver.setup schema,
|
||||
teardown = Sqlserver.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = BigQuery.setup schema,
|
||||
teardown = BigQuery.teardown schema,
|
||||
customOptions =
|
||||
Just $
|
||||
Context.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.MySQL)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Mysql.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Citus.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Sqlserver.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ BigQuery.setupTablesAction schema testEnv
|
||||
],
|
||||
Fixture.customOptions =
|
||||
Just $
|
||||
Fixture.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -113,7 +100,7 @@ schema =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
let shouldBe :: IO Value -> Value -> IO ()
|
||||
shouldBe = shouldReturnYaml opts
|
||||
|
@ -9,7 +9,6 @@
|
||||
module Test.Queries.Simple.ObjectQueriesSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.Backend.Citus qualified as Citus
|
||||
import Harness.Backend.Mysql qualified as Mysql
|
||||
@ -18,8 +17,7 @@ import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.GraphqlEngine (postGraphql)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (interpolateYaml, yaml)
|
||||
import Harness.Test.Context (Options (..))
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -29,49 +27,38 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec = do
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.MySQL,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Mysql.setup schema,
|
||||
teardown = Mysql.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Postgres.setup schema,
|
||||
teardown = Postgres.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.Citus,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Citus.setup schema,
|
||||
teardown = Citus.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.SQLServer,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Sqlserver.setup schema,
|
||||
teardown = Sqlserver.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = BigQuery.setup schema,
|
||||
teardown = BigQuery.teardown schema,
|
||||
customOptions =
|
||||
Just $
|
||||
Context.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.MySQL)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Mysql.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Citus.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Sqlserver.setupTablesAction schema testEnv
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ BigQuery.setupTablesAction schema testEnv
|
||||
],
|
||||
Fixture.customOptions =
|
||||
Just $
|
||||
Fixture.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -99,7 +86,7 @@ schema =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
let shouldBe :: IO Value -> Value -> IO ()
|
||||
shouldBe = shouldReturnYaml opts
|
||||
|
@ -3,12 +3,11 @@
|
||||
-- | Tests related to request headers
|
||||
module Test.RequestHeadersSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (yaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema
|
||||
( BackendScalarType (..),
|
||||
Table (..),
|
||||
@ -26,18 +25,15 @@ import Test.Hspec (SpecWith, it)
|
||||
-- * Preamble
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.SQLServer,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = sqlserverSetup,
|
||||
teardown = sqlserverTeardown,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
spec = do
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Sqlserver.setupTablesAction schema testEnv,
|
||||
sqlserverPermissionsSetup testEnv
|
||||
]
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -69,47 +65,43 @@ author =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Setup and teardown override
|
||||
|
||||
sqlserverSetup :: (TestEnvironment, ()) -> IO ()
|
||||
sqlserverSetup (testEnvironment, _) = do
|
||||
Sqlserver.setup schema (testEnvironment, ())
|
||||
-- create permissions
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: mssql_create_select_permission
|
||||
args:
|
||||
source: mssql
|
||||
table:
|
||||
schema: hasura
|
||||
name: author
|
||||
role: user
|
||||
permission:
|
||||
filter:
|
||||
uuid: X-Hasura-User-Id
|
||||
columns: '*'
|
||||
|]
|
||||
|
||||
sqlserverTeardown :: (TestEnvironment, ()) -> IO ()
|
||||
sqlserverTeardown (testEnvironment, _) = do
|
||||
-- drop permissions
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: mssql_drop_select_permission
|
||||
args:
|
||||
source: mssql
|
||||
table:
|
||||
schema: hasura
|
||||
name: author
|
||||
role: user
|
||||
|]
|
||||
-- rest of the teardown
|
||||
Sqlserver.teardown schema (testEnvironment, ())
|
||||
sqlserverPermissionsSetup :: TestEnvironment -> Fixture.SetupAction
|
||||
sqlserverPermissionsSetup testEnvironment =
|
||||
Fixture.SetupAction
|
||||
{ setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: mssql_create_select_permission
|
||||
args:
|
||||
source: mssql
|
||||
table:
|
||||
schema: hasura
|
||||
name: author
|
||||
role: user
|
||||
permission:
|
||||
filter:
|
||||
uuid: X-Hasura-User-Id
|
||||
columns: '*'
|
||||
|],
|
||||
teardownAction = \_ ->
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: mssql_drop_select_permission
|
||||
args:
|
||||
source: mssql
|
||||
table:
|
||||
schema: hasura
|
||||
name: author
|
||||
role: user
|
||||
|]
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
-- See https://github.com/hasura/graphql-engine/issues/8158
|
||||
it "session variable string values are not truncated to default (30) length" $ \testEnvironment ->
|
||||
@ -121,17 +113,17 @@ tests opts = do
|
||||
("X-Hasura-User-Id", "36a6257b-08bb-45ef-a5cf-c1b7a7997087")
|
||||
]
|
||||
[graphql|
|
||||
query {
|
||||
hasura_author {
|
||||
name
|
||||
uuid
|
||||
}
|
||||
}
|
||||
|]
|
||||
query {
|
||||
hasura_author {
|
||||
name
|
||||
uuid
|
||||
}
|
||||
}
|
||||
|]
|
||||
)
|
||||
[yaml|
|
||||
data:
|
||||
hasura_author:
|
||||
- name: 'Author 1'
|
||||
uuid: '36a6257b-08bb-45ef-a5cf-c1b7a7997087'
|
||||
|]
|
||||
data:
|
||||
hasura_author:
|
||||
- name: 'Author 1'
|
||||
uuid: '36a6257b-08bb-45ef-a5cf-c1b7a7997087'
|
||||
|]
|
||||
|
@ -3,13 +3,12 @@
|
||||
-- | Test *_run_sql query API
|
||||
module Test.RunSQLSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.Constants qualified as Constants
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Yaml (yaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Permissions qualified as Permissions
|
||||
import Harness.Test.Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -19,56 +18,35 @@ import Test.Hspec
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Preamble
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec = do
|
||||
-- BigQuery
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = BigQuery.setup [],
|
||||
teardown = BigQuery.teardown [],
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
bigqueryTests
|
||||
-- Postgres
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = postgresSetup,
|
||||
teardown = postgresTeardown,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnv,
|
||||
Postgres.setupPermissionsAction [updatePermission] testEnv
|
||||
]
|
||||
}
|
||||
]
|
||||
postgresTests
|
||||
|
||||
-- BigQuery
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ BigQuery.setupTablesAction [] testEnv
|
||||
]
|
||||
}
|
||||
]
|
||||
bigqueryTests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Setup & Teardown
|
||||
-- Schema
|
||||
|
||||
postgresSetup :: (TestEnvironment, ()) -> IO ()
|
||||
postgresSetup (env, ()) = do
|
||||
Postgres.setup [testTable] (env, ())
|
||||
Postgres.setupPermissions [updatePermission] env
|
||||
|
||||
postgresTeardown :: (TestEnvironment, ()) -> IO ()
|
||||
postgresTeardown (env, ()) = do
|
||||
Postgres.teardownPermissions [updatePermission] env
|
||||
Postgres.teardown [testTable] (env, ())
|
||||
|
||||
updatePermission :: Permissions.Permission
|
||||
updatePermission =
|
||||
Permissions.UpdatePermission
|
||||
{ Permissions.permissionTable = "test",
|
||||
Permissions.permissionSource = "postgres",
|
||||
Permissions.permissionRole = "user",
|
||||
Permissions.permissionColumns = ["age"]
|
||||
}
|
||||
schema :: [Table]
|
||||
schema = [testTable]
|
||||
|
||||
testTable :: Table
|
||||
testTable =
|
||||
@ -85,10 +63,22 @@ testTable =
|
||||
]
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Permission
|
||||
|
||||
updatePermission :: Permissions.Permission
|
||||
updatePermission =
|
||||
Permissions.UpdatePermission
|
||||
{ Permissions.permissionTable = "test",
|
||||
Permissions.permissionSource = "postgres",
|
||||
Permissions.permissionRole = "user",
|
||||
Permissions.permissionColumns = ["age"]
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
bigqueryTests :: Context.Options -> SpecWith TestEnvironment
|
||||
bigqueryTests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
bigqueryTests opts = do
|
||||
it "BigQuery - running invalid SQL" \testEnvironment ->
|
||||
shouldReturnYaml
|
||||
@ -97,31 +87,31 @@ bigqueryTests opts = do
|
||||
400
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: bigquery_run_sql
|
||||
args:
|
||||
source: bigquery
|
||||
sql: 'some invalid SQL'
|
||||
|]
|
||||
type: bigquery_run_sql
|
||||
args:
|
||||
source: bigquery
|
||||
sql: 'some invalid SQL'
|
||||
|]
|
||||
)
|
||||
[yaml|
|
||||
internal:
|
||||
rest_request_non_ok:
|
||||
error:
|
||||
status: INVALID_ARGUMENT
|
||||
code: 400
|
||||
message: 'Syntax error: Expected end of input but got keyword SOME at [1:1]'
|
||||
errors:
|
||||
- location: q
|
||||
domain: global
|
||||
reason: invalidQuery
|
||||
locationType: parameter
|
||||
message: 'Syntax error: Expected end of input but got keyword SOME at [1:1]'
|
||||
path: "$"
|
||||
error: BigQuery HTTP request failed with status 400 "Bad Request"
|
||||
code: bigquery-error
|
||||
|]
|
||||
internal:
|
||||
rest_request_non_ok:
|
||||
error:
|
||||
status: INVALID_ARGUMENT
|
||||
code: 400
|
||||
message: 'Syntax error: Expected end of input but got keyword SOME at [1:1]'
|
||||
errors:
|
||||
- location: q
|
||||
domain: global
|
||||
reason: invalidQuery
|
||||
locationType: parameter
|
||||
message: 'Syntax error: Expected end of input but got keyword SOME at [1:1]'
|
||||
path: "$"
|
||||
error: BigQuery HTTP request failed with status 400 "Bad Request"
|
||||
code: bigquery-error
|
||||
|]
|
||||
|
||||
postgresTests :: Context.Options -> SpecWith TestEnvironment
|
||||
postgresTests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
postgresTests opts = do
|
||||
-- Testing regression reported at https://github.com/hasura/graphql-engine/issues/8415
|
||||
it "Drop column which is not referred in update permission" \testEnvironment -> do
|
||||
@ -132,16 +122,16 @@ postgresTests opts = do
|
||||
200
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: run_sql
|
||||
args:
|
||||
source: postgres
|
||||
sql: *runSQL
|
||||
|]
|
||||
type: run_sql
|
||||
args:
|
||||
source: postgres
|
||||
sql: *runSQL
|
||||
|]
|
||||
)
|
||||
[yaml|
|
||||
result: null
|
||||
result_type: CommandOk
|
||||
|]
|
||||
result: null
|
||||
result_type: CommandOk
|
||||
|]
|
||||
|
||||
it "Drop column which is referred in update permission" \testEnvironment -> do
|
||||
let runSQL = "alter table " <> Constants.postgresDb <> ".test drop column age;"
|
||||
@ -151,15 +141,15 @@ result_type: CommandOk
|
||||
400
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: run_sql
|
||||
args:
|
||||
source: postgres
|
||||
sql: *runSQL
|
||||
|]
|
||||
type: run_sql
|
||||
args:
|
||||
source: postgres
|
||||
sql: *runSQL
|
||||
|]
|
||||
)
|
||||
[yaml|
|
||||
code: dependency-error
|
||||
error: 'cannot drop due to the following dependent objects : permission hasura.test.user.update
|
||||
in source "postgres"'
|
||||
path: "$"
|
||||
|]
|
||||
code: dependency-error
|
||||
error: 'cannot drop due to the following dependent objects : permission hasura.test.user.update
|
||||
in source "postgres"'
|
||||
path: "$"
|
||||
|]
|
||||
|
@ -8,14 +8,13 @@
|
||||
module Test.Schema.DefaultValuesSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Data.Text qualified as T
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.GraphqlEngine (postGraphql, postGraphqlWithHeaders, postMetadata_)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (yaml)
|
||||
import Harness.Test.Context (Options (..))
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -25,24 +24,20 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Postgres.setup schema <> setupMetadata "postgres",
|
||||
teardown = Postgres.teardown schema,
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.SQLServer,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Sqlserver.setup schema <> setupMetadata "mssql",
|
||||
teardown = Sqlserver.teardown schema,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnvironment
|
||||
]
|
||||
<> setupMetadata Fixture.Postgres testEnvironment
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Sqlserver.setupTablesAction schema testEnvironment
|
||||
]
|
||||
<> setupMetadata Fixture.SQLServer testEnvironment
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -64,7 +59,7 @@ schema =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
let shouldBe :: IO Value -> Value -> IO ()
|
||||
shouldBe = shouldReturnYaml opts
|
||||
@ -212,41 +207,74 @@ tests opts = do
|
||||
--------------------------------------------------------------------------------
|
||||
-- Metadata
|
||||
|
||||
setupMetadata :: Text -> (TestEnvironment, ()) -> IO ()
|
||||
setupMetadata backend (testEnvironment, _) = do
|
||||
let select = backend <> "_create_select_permission"
|
||||
insert = backend <> "_create_insert_permission"
|
||||
|
||||
postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: *select
|
||||
args:
|
||||
source: *backend
|
||||
table:
|
||||
schema: hasura
|
||||
name: author
|
||||
role: user
|
||||
permission:
|
||||
filter:
|
||||
uuid: X-Hasura-User-Id
|
||||
columns: '*'
|
||||
|]
|
||||
|
||||
postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: *insert
|
||||
args:
|
||||
source: *backend
|
||||
table:
|
||||
schema: hasura
|
||||
name: author
|
||||
role: user
|
||||
permission:
|
||||
check: {}
|
||||
set:
|
||||
uuid: X-Hasura-User-Id
|
||||
company: hasura
|
||||
columns: '*'
|
||||
|]
|
||||
setupMetadata :: Fixture.BackendType -> TestEnvironment -> [Fixture.SetupAction]
|
||||
setupMetadata backendType testEnvironment =
|
||||
let backend = T.pack $ Fixture.defaultBackendTypeString backendType
|
||||
schemaName = Schema.getSchemaName testEnvironment
|
||||
createSelect = backend <> "_create_select_permission"
|
||||
dropSelect = backend <> "_drop_select_permission"
|
||||
createInsert = backend <> "_create_insert_permission"
|
||||
dropInsert = backend <> "_drop_insert_permission"
|
||||
in [ Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: *createSelect
|
||||
args:
|
||||
source: *backend
|
||||
table:
|
||||
schema: *schemaName
|
||||
name: author
|
||||
role: user
|
||||
permission:
|
||||
filter:
|
||||
uuid: X-Hasura-User-Id
|
||||
columns: '*'
|
||||
|],
|
||||
Fixture.teardownAction = \_ ->
|
||||
postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: *dropSelect
|
||||
args:
|
||||
source: *backend
|
||||
table:
|
||||
schema: *schemaName
|
||||
name: author
|
||||
role: user
|
||||
|]
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: *createInsert
|
||||
args:
|
||||
source: *backend
|
||||
table:
|
||||
schema: *schemaName
|
||||
name: author
|
||||
role: user
|
||||
permission:
|
||||
check: {}
|
||||
set:
|
||||
uuid: X-Hasura-User-Id
|
||||
company: hasura
|
||||
columns: '*'
|
||||
|],
|
||||
Fixture.teardownAction = \_ ->
|
||||
postMetadata_
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: *dropInsert
|
||||
args:
|
||||
source: *backend
|
||||
table:
|
||||
schema: *schemaName
|
||||
name: author
|
||||
role: user
|
||||
|]
|
||||
}
|
||||
]
|
||||
|
@ -7,13 +7,12 @@
|
||||
module Test.Schema.EnumSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Citus qualified as Citus
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.GraphqlEngine (postGraphql)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (yaml)
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -23,24 +22,30 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = const (Postgres.run_ setup) <> Postgres.setup schema,
|
||||
teardown = Postgres.teardown schema <> const (Postgres.run_ teardown),
|
||||
customOptions = Nothing
|
||||
},
|
||||
Context.Context
|
||||
{ name = Context.Backend Context.Citus,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = const (Citus.run_ setup) <> Citus.setup schema,
|
||||
teardown = Citus.teardown schema <> const (Citus.run_ teardown),
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
Postgres.run_ setup,
|
||||
Fixture.teardownAction = \_ ->
|
||||
Postgres.run_ teardown
|
||||
},
|
||||
Postgres.setupTablesAction schema testEnvironment
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
Citus.run_ setup,
|
||||
Fixture.teardownAction = \_ ->
|
||||
Citus.run_ teardown
|
||||
},
|
||||
Citus.setupTablesAction schema testEnvironment
|
||||
]
|
||||
}
|
||||
]
|
||||
tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -73,7 +78,7 @@ teardown = "drop type \"role\""
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests :: Fixture.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
let shouldBe :: IO Value -> Value -> IO ()
|
||||
shouldBe = shouldReturnYaml opts
|
||||
|
@ -10,7 +10,6 @@
|
||||
module Test.Schema.TableRelationships.ObjectRelationshipsSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.Backend.Mysql qualified as Mysql
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
@ -18,8 +17,7 @@ import Harness.GraphqlEngine (postGraphql)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (interpolateYaml)
|
||||
import Harness.Test.BackendType (BackendType (..))
|
||||
import Harness.Test.Context (Options (..))
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
import Harness.Test.Schema qualified as Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
@ -29,69 +27,49 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec = do
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.MySQL,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Mysql.setup schema,
|
||||
teardown = Mysql.teardown schema,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.MySQL)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[Mysql.setupTablesAction schema testEnv]
|
||||
}
|
||||
]
|
||||
$ tests MySQL
|
||||
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = Postgres.setup schema,
|
||||
teardown = Postgres.teardown schema,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[Postgres.setupTablesAction schema testEnv]
|
||||
}
|
||||
]
|
||||
$ tests Postgres
|
||||
|
||||
-- Context.run
|
||||
-- [ Context.Context
|
||||
-- { name = Context.Backend Context.Citus,
|
||||
-- mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
-- setup = Citus.setup schema,
|
||||
-- teardown = Citus.teardown schema,
|
||||
-- customOptions = Nothing
|
||||
-- }
|
||||
-- ]
|
||||
-- $ tests Citus
|
||||
-- Fixture.run
|
||||
-- [ (Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
||||
-- { Fixture.setupTeardown = \(testEnv, _) ->
|
||||
-- [Citus.setupTablesAction schema testEnv]
|
||||
-- }
|
||||
-- ]
|
||||
-- $ tests Citus
|
||||
|
||||
-- Context.run
|
||||
-- [ Context.Context
|
||||
-- { name = Context.Backend Context.SQLServer,
|
||||
-- mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
-- setup = Sqlserver.setup schema,
|
||||
-- teardown = Sqlserver.teardown schema,
|
||||
-- customOptions = Nothing
|
||||
-- }
|
||||
-- ]
|
||||
-- $ tests SQLServer
|
||||
-- Fixture.run
|
||||
-- [ (Fixture.fixture $ Fixture.Backend Fixture.SQLServer)
|
||||
-- { Fixture.setupTeardown = \(testEnv, _) ->
|
||||
-- [Sqlserver.setupTablesAction schema testEnv]
|
||||
-- }
|
||||
-- ]
|
||||
-- $ tests SQLServer
|
||||
|
||||
Context.run
|
||||
( NE.fromList
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = BigQuery.setup schema,
|
||||
teardown = BigQuery.teardown schema,
|
||||
customOptions =
|
||||
Just $
|
||||
Context.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
Fixture.run
|
||||
[ (Fixture.fixture $ Fixture.Backend Fixture.BigQuery)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[BigQuery.setupTablesAction schema testEnv],
|
||||
Fixture.customOptions =
|
||||
Just $
|
||||
Fixture.Options
|
||||
{ stringifyNumbers = True
|
||||
}
|
||||
}
|
||||
]
|
||||
$ tests BigQuery
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -145,7 +123,7 @@ schema =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: BackendType -> Context.Options -> SpecWith TestEnvironment
|
||||
tests :: BackendType -> Fixture.Options -> SpecWith TestEnvironment
|
||||
tests backend opts = describe "Object relationships" do
|
||||
let shouldBe :: IO Value -> Value -> IO ()
|
||||
shouldBe = shouldReturnYaml opts
|
||||
|
Loading…
Reference in New Issue
Block a user