From f42f1111ccf36a98403bd1455ffdfec042dd055e Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Mon, 8 May 2023 16:45:04 +0200 Subject: [PATCH] CLI: Add test coverage for stored procedures. This asserts that reading and writing metadata does not modify the stored procedures. We do not provide any support for working with them; this just ensures we do not accidentally corrupt them. [NDAT-640]: https://hasurahq.atlassian.net/browse/NDAT-640?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9081 GitOrigin-RevId: 7c9b31f060325cbdffd8803ea085d4957dc1c680 --- .../t1/metadata/databases/databases.yaml | 23 +++++++ .../testdata/build_test/t1/want.golden.json | 36 +++++++++++ .../testdata/export_test/t1/metadata.json | 64 +++++++++++++++---- .../t1/want/databases/databases.yaml | 23 +++++++ 4 files changed, 132 insertions(+), 14 deletions(-) diff --git a/cli/internal/metadataobject/sources/testdata/build_test/t1/metadata/databases/databases.yaml b/cli/internal/metadataobject/sources/testdata/build_test/t1/metadata/databases/databases.yaml index d2a6bd1f999..a9bb990f92a 100644 --- a/cli/internal/metadataobject/sources/testdata/build_test/t1/metadata/databases/databases.yaml +++ b/cli/internal/metadataobject/sources/testdata/build_test/t1/metadata/databases/databases.yaml @@ -51,6 +51,14 @@ - question filter: {} role: user + - name: nonsense + fields: + something: + nullable: false + type: integer + something_else: + nullable: false + type: text native_queries: - arguments: unused: @@ -60,6 +68,21 @@ code: select question, answer, added_by_user_id from questions returns: quiz_answer root_field_name: quiz_answers + stored_procedures: + - stored_procedure: + schema: public + name: swap + configuration: + custom_name: swap_it + exposed_as: query + arguments: + one: + nullable: false + type: text + two: + nullable: false + type: integer + returns: nonsense tables: !include "s1/tables/tables.yaml" functions: !include "s1/functions/functions.yaml" - name: s2 diff --git a/cli/internal/metadataobject/sources/testdata/build_test/t1/want.golden.json b/cli/internal/metadataobject/sources/testdata/build_test/t1/want.golden.json index d77c82beffc..9e4a272cd3a 100644 --- a/cli/internal/metadataobject/sources/testdata/build_test/t1/want.golden.json +++ b/cli/internal/metadataobject/sources/testdata/build_test/t1/want.golden.json @@ -79,6 +79,19 @@ "role": "user" } ] + }, + { + "name": "nonsense", + "fields": { + "something": { + "nullable": false, + "type": "integer" + }, + "something_else": { + "nullable": false, + "type": "text" + } + } } ], "native_queries": [ @@ -95,6 +108,29 @@ "root_field_name": "quiz_answers" } ], + "stored_procedures": [ + { + "stored_procedure": { + "schema": "public", + "name": "swap" + }, + "configuration": { + "custom_name": "swap_it", + "exposed_as": "query" + }, + "arguments": { + "one": { + "nullable": false, + "type": "text" + }, + "two": { + "nullable": false, + "type": "integer" + } + }, + "returns": "nonsense" + } + ], "tables": [ { "table": { diff --git a/cli/internal/metadataobject/sources/testdata/export_test/t1/metadata.json b/cli/internal/metadataobject/sources/testdata/export_test/t1/metadata.json index 68612895a14..1d28470b4dd 100644 --- a/cli/internal/metadataobject/sources/testdata/export_test/t1/metadata.json +++ b/cli/internal/metadataobject/sources/testdata/export_test/t1/metadata.json @@ -81,20 +81,6 @@ } } ], - "native_queries": [ - { - "arguments": { - "unused": { - "description": "An integer argument that we completely ignore", - "nullable": true, - "type": "integer" - } - }, - "code": "select question, answer, added_by_user_id from questions", - "returns": "quiz_answer", - "root_field_name": "quiz_answers" - } - ], "logical_models": [ { "name": "quiz_answer", @@ -137,6 +123,56 @@ "role": "user" } ] + }, + { + "name": "nonsense", + "fields": { + "something": { + "nullable": false, + "type": "integer" + }, + "something_else": { + "nullable": false, + "type": "text" + } + } + } + ], + "native_queries": [ + { + "arguments": { + "unused": { + "description": "An integer argument that we completely ignore", + "nullable": true, + "type": "integer" + } + }, + "code": "select question, answer, added_by_user_id from questions", + "returns": "quiz_answer", + "root_field_name": "quiz_answers" + } + ], + "stored_procedures": [ + { + "stored_procedure": { + "schema": "public", + "name": "swap" + }, + "configuration": { + "custom_name": "swap_it", + "exposed_as": "query" + }, + "arguments": { + "one": { + "nullable": false, + "type": "text" + }, + "two": { + "nullable": false, + "type": "integer" + } + }, + "returns": "nonsense" } ], "configuration": { diff --git a/cli/internal/metadataobject/sources/testdata/export_test/t1/want/databases/databases.yaml b/cli/internal/metadataobject/sources/testdata/export_test/t1/want/databases/databases.yaml index b952bc9d221..ff60cb82f30 100644 --- a/cli/internal/metadataobject/sources/testdata/export_test/t1/want/databases/databases.yaml +++ b/cli/internal/metadataobject/sources/testdata/export_test/t1/want/databases/databases.yaml @@ -51,6 +51,14 @@ - question filter: {} role: user + - name: nonsense + fields: + something: + nullable: false + type: integer + something_else: + nullable: false + type: text native_queries: - arguments: unused: @@ -60,6 +68,21 @@ code: select question, answer, added_by_user_id from questions returns: quiz_answer root_field_name: quiz_answers + stored_procedures: + - stored_procedure: + schema: public + name: swap + configuration: + custom_name: swap_it + exposed_as: query + arguments: + one: + nullable: false + type: text + two: + nullable: false + type: integer + returns: nonsense tables: "!include default/tables/tables.yaml" functions: "!include default/functions/functions.yaml" - name: bg