1) Add Reverse Engineered and Modified SQL tests for Foreign Servers. Fixes #4617

2) Add Reverse Engineered and Modified SQL tests for User Mappings. Fixes #4627
pull/26/head
Akshay Joshi 2019-09-03 16:27:41 +05:30
parent 04357b7a55
commit 4745ad56e9
45 changed files with 790 additions and 18 deletions

View File

@ -20,7 +20,9 @@ Housekeeping
| `Issue #4575 <https://redmine.postgresql.org/issues/4575>`_ - Add Reverse Engineered SQL tests for Schemas.
| `Issue #4576 <https://redmine.postgresql.org/issues/4576>`_ - Add Reverse Engineered SQL tests for Views.
| `Issue #4600 <https://redmine.postgresql.org/issues/4600>`_ - Add Reverse Engineered SQL tests for Rules.
| `Issue #4617 <https://redmine.postgresql.org/issues/4617>`_ - Add Reverse Engineered and Modified SQL tests for Foreign Servers.
| `Issue #4619 <https://redmine.postgresql.org/issues/4619>`_ - Add Reverse Engineered and Modified SQL tests for FTS Templates.
| `Issue #4627 <https://redmine.postgresql.org/issues/4627>`_ - Add Reverse Engineered and Modified SQL tests for User Mappings.
| `Issue #4690 <https://redmine.postgresql.org/issues/4690>`_ - Add Modified SQL tests for Resource Group.
Bug fixes

View File

@ -19,3 +19,4 @@ FROM
LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
GROUP BY g.rolname, gt.rolname
ORDER BY grantee

View File

@ -15,7 +15,6 @@ CREATE SERVER {{ conn|qtIdent(data.name) }}{% if data.fsrvtype %}
{# ============= Set the owner for foreign server ============= #}
{% if data.fsrvowner %}
ALTER SERVER {{ conn|qtIdent(data.name) }}
OWNER TO {{ conn|qtIdent(data.fsrvowner) }};
{% endif %}

View File

@ -31,4 +31,4 @@ COMMENT ON SERVER {{ conn|qtIdent(data.name) }}
{% for priv in data.fsrvacl %}
{{ PRIVILEGE.APPLY(conn, 'FOREIGN SERVER', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %}
{% endif %}
{% endif %}

View File

@ -0,0 +1,13 @@
-- Foreign Server: FS_$%{}[]()&*^!@"'`\/#
-- DROP SERVER FS_$%{}[]()&*^!@"'`\/#
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
VERSION '1.1'
FOREIGN DATA WRAPPER test_fdw_for_fs;
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';

View File

@ -0,0 +1,5 @@
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
VERSION 1.1;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';

View File

@ -0,0 +1,18 @@
-- Foreign Server: FS_$%{}[]()&*^!@"'`\/#
-- DROP SERVER FS_$%{}[]()&*^!@"'`\/#
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
VERSION '1.1'
FOREIGN DATA WRAPPER test_fdw_for_fs
OPTIONS (host '192.168.1.1', dbname 'edb', port '5450');
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO postgres;

View File

@ -0,0 +1,4 @@
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OPTIONS (ADD host '192.168.1.1', ADD dbname 'edb', ADD port '5450');
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO PUBLIC;

View File

@ -0,0 +1,15 @@
-- Foreign Server: FS_$%{}[]()&*^!@"'`\/#
-- DROP SERVER FS_$%{}[]()&*^!@"'`\/#
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
VERSION '1.1'
FOREIGN DATA WRAPPER test_fdw_for_fs;
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO postgres;

View File

@ -0,0 +1,4 @@
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OPTIONS (DROP host, DROP dbname, DROP port);
REVOKE ALL ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" FROM PUBLIC;

View File

@ -0,0 +1,18 @@
-- Foreign Server: FS_$%{}[]()&*^!@"'`\/#
-- DROP SERVER FS_$%{}[]()&*^!@"'`\/#
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
TYPE 'oracle'
VERSION '1.1'
FOREIGN DATA WRAPPER test_fdw_for_fs
OPTIONS (host '192.168.1.1', dbname 'edb', port '5450');
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO postgres;

View File

@ -0,0 +1,13 @@
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
TYPE 'oracle'
VERSION 1.1
FOREIGN DATA WRAPPER test_fdw_for_fs
OPTIONS (host '192.168.1.1', dbname 'edb', port '5450');
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO PUBLIC;

View File

@ -0,0 +1,159 @@
{
"scenarios": [
{
"type": "create",
"name": "Create FDW for foreign server",
"endpoint": "NODE-foreign_data_wrapper.obj",
"sql_endpoint": "NODE-foreign_data_wrapper.sql_id",
"data": {
"name": "test_fdw_for_fs",
"fdwacl": [],
"fdwoptions": []
},
"store_object_id": "True"
}, {
"type": "create",
"name": "Create foreign server with all options",
"endpoint": "NODE-foreign_server.obj",
"sql_endpoint": "NODE-foreign_server.sql_id",
"msql_endpoint": "NODE-foreign_server.msql",
"data": {
"name":"FS_$%{}[]()&*^!@\"'`\\/#",
"fsrvtype":"oracle",
"fsrvversion":"1.1",
"fsrvoptions":[
{
"fsrvoption":"host",
"fsrvvalue":"192.168.1.1"
},{
"fsrvoption":"dbname",
"fsrvvalue":"edb"
},{
"fsrvoption":"port",
"fsrvvalue":"5450"
}],
"fsrvowner":"postgres",
"description":"Test comment",
"fsrvacl":[{
"grantee":"PUBLIC",
"grantor":"postgres",
"privileges":[{
"privilege_type":"U",
"privilege":true,
"with_grant":false
}]
}]
},
"expected_sql_file": "create_fs_all_options.sql",
"expected_msql_file": "create_fs_all_options_msql.sql"
}, {
"type": "delete",
"name": "Drop foreign server",
"endpoint": "NODE-foreign_server.delete_id",
"data": {
"name": "FS_$%{}[]()&*^!@\"'`\\/#"
}
}, {
"type": "create",
"name": "Create foreign server",
"endpoint": "NODE-foreign_server.obj",
"sql_endpoint": "NODE-foreign_server.sql_id",
"data": {
"name":"FS_$%{}[]()&*^!@\"'`\\/#",
"fsrvowner":"postgres"
}
}, {
"type": "alter",
"name": "Alter foreign server comment and version",
"endpoint": "NODE-foreign_server.obj_id",
"sql_endpoint": "NODE-foreign_server.sql_id",
"msql_endpoint": "NODE-foreign_server.msql_id",
"data": {
"fsrvversion":"1.1",
"description":"Test comment"
},
"expected_sql_file": "alter_comment_version.sql",
"expected_msql_file": "alter_comment_version_msql.sql"
}, {
"type": "alter",
"name": "Alter foreign server add options and privileges",
"endpoint": "NODE-foreign_server.obj_id",
"sql_endpoint": "NODE-foreign_server.sql_id",
"msql_endpoint": "NODE-foreign_server.msql_id",
"data": {
"fsrvoptions":{
"added": [{
"fsrvoption":"host",
"fsrvvalue":"192.168.1.1"
},{
"fsrvoption":"dbname",
"fsrvvalue":"edb"
},{
"fsrvoption":"port",
"fsrvvalue":"5450"
}]
},
"fsrvacl":{
"added": [{
"grantee":"PUBLIC",
"grantor":"postgres",
"privileges":[{
"privilege_type":"U",
"privilege":true,
"with_grant":false
}]
}]
}
},
"expected_sql_file": "alter_options_privileges.sql",
"expected_msql_file": "alter_options_privileges_msql.sql"
}, {
"type": "alter",
"name": "Alter foreign server add options and privileges",
"endpoint": "NODE-foreign_server.obj_id",
"sql_endpoint": "NODE-foreign_server.sql_id",
"msql_endpoint": "NODE-foreign_server.msql_id",
"data": {
"fsrvoptions":{
"deleted": [{
"fsrvoption":"host",
"fsrvvalue":"192.168.1.1"
},{
"fsrvoption":"dbname",
"fsrvvalue":"edb"
},{
"fsrvoption":"port",
"fsrvvalue":"5450"
}]
},
"fsrvacl":{
"deleted": [{
"grantee":"PUBLIC",
"grantor":"postgres",
"privileges":[{
"privilege_type":"U",
"privilege":true,
"with_grant":false
}]
}]
}
},
"expected_sql_file": "alter_remove_options_priv.sql",
"expected_msql_file": "alter_remove_options_priv_msql.sql"
}, {
"type": "delete",
"name": "Drop foreign server",
"endpoint": "NODE-foreign_server.delete_id",
"data": {
"name": "FS_$%{}[]()&*^!@\"'`\\/#"
}
}, {
"type": "delete",
"name": "Drop FDW",
"endpoint": "NODE-foreign_data_wrapper.delete_id",
"data": {
"name": "test_fdw_for_fs"
}
}
]
}

View File

@ -0,0 +1,13 @@
-- Foreign Server: FS_$%{}[]()&*^!@"'`\/#
-- DROP SERVER FS_$%{}[]()&*^!@"'`\/#
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
VERSION '1.1'
FOREIGN DATA WRAPPER test_fdw_for_fs;
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';

View File

@ -0,0 +1,5 @@
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
VERSION 1.1;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';

View File

@ -0,0 +1,18 @@
-- Foreign Server: FS_$%{}[]()&*^!@"'`\/#
-- DROP SERVER FS_$%{}[]()&*^!@"'`\/#
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
VERSION '1.1'
FOREIGN DATA WRAPPER test_fdw_for_fs
OPTIONS (host '192.168.1.1', dbname 'edb', port '5450');
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO enterprisedb;

View File

@ -0,0 +1,4 @@
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OPTIONS (ADD host '192.168.1.1', ADD dbname 'edb', ADD port '5450');
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO PUBLIC;

View File

@ -0,0 +1,15 @@
-- Foreign Server: FS_$%{}[]()&*^!@"'`\/#
-- DROP SERVER FS_$%{}[]()&*^!@"'`\/#
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
VERSION '1.1'
FOREIGN DATA WRAPPER test_fdw_for_fs;
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO enterprisedb;

View File

@ -0,0 +1,4 @@
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OPTIONS (DROP host, DROP dbname, DROP port);
REVOKE ALL ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" FROM PUBLIC;

View File

@ -0,0 +1,18 @@
-- Foreign Server: FS_$%{}[]()&*^!@"'`\/#
-- DROP SERVER FS_$%{}[]()&*^!@"'`\/#
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
TYPE 'oracle'
VERSION '1.1'
FOREIGN DATA WRAPPER test_fdw_for_fs
OPTIONS (host '192.168.1.1', dbname 'edb', port '5450');
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO enterprisedb;

View File

@ -0,0 +1,13 @@
CREATE SERVER "FS_$%{}[]()&*^!@""'`\/#"
TYPE 'oracle'
VERSION 1.1
FOREIGN DATA WRAPPER test_fdw_for_fs
OPTIONS (host '192.168.1.1', dbname 'edb', port '5450');
ALTER SERVER "FS_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;
COMMENT ON SERVER "FS_$%{}[]()&*^!@""'`\/#"
IS 'Test comment';
GRANT USAGE ON FOREIGN SERVER "FS_$%{}[]()&*^!@""'`\/#" TO PUBLIC;

View File

@ -0,0 +1,159 @@
{
"scenarios": [
{
"type": "create",
"name": "Create FDW for foreign server",
"endpoint": "NODE-foreign_data_wrapper.obj",
"sql_endpoint": "NODE-foreign_data_wrapper.sql_id",
"data": {
"name": "test_fdw_for_fs",
"fdwacl": [],
"fdwoptions": []
},
"store_object_id": "True"
}, {
"type": "create",
"name": "Create foreign server with all options",
"endpoint": "NODE-foreign_server.obj",
"sql_endpoint": "NODE-foreign_server.sql_id",
"msql_endpoint": "NODE-foreign_server.msql",
"data": {
"name":"FS_$%{}[]()&*^!@\"'`\\/#",
"fsrvtype":"oracle",
"fsrvversion":"1.1",
"fsrvoptions":[
{
"fsrvoption":"host",
"fsrvvalue":"192.168.1.1"
},{
"fsrvoption":"dbname",
"fsrvvalue":"edb"
},{
"fsrvoption":"port",
"fsrvvalue":"5450"
}],
"fsrvowner":"enterprisedb",
"description":"Test comment",
"fsrvacl":[{
"grantee":"PUBLIC",
"grantor":"enterprisedb",
"privileges":[{
"privilege_type":"U",
"privilege":true,
"with_grant":false
}]
}]
},
"expected_sql_file": "create_fs_all_options.sql",
"expected_msql_file": "create_fs_all_options_msql.sql"
}, {
"type": "delete",
"name": "Drop foreign server",
"endpoint": "NODE-foreign_server.delete_id",
"data": {
"name": "FS_$%{}[]()&*^!@\"'`\\/#"
}
}, {
"type": "create",
"name": "Create foreign server",
"endpoint": "NODE-foreign_server.obj",
"sql_endpoint": "NODE-foreign_server.sql_id",
"data": {
"name":"FS_$%{}[]()&*^!@\"'`\\/#",
"fsrvowner":"enterprisedb"
}
}, {
"type": "alter",
"name": "Alter foreign server comment and version",
"endpoint": "NODE-foreign_server.obj_id",
"sql_endpoint": "NODE-foreign_server.sql_id",
"msql_endpoint": "NODE-foreign_server.msql_id",
"data": {
"fsrvversion":"1.1",
"description":"Test comment"
},
"expected_sql_file": "alter_comment_version.sql",
"expected_msql_file": "alter_comment_version_msql.sql"
}, {
"type": "alter",
"name": "Alter foreign server add options and privileges",
"endpoint": "NODE-foreign_server.obj_id",
"sql_endpoint": "NODE-foreign_server.sql_id",
"msql_endpoint": "NODE-foreign_server.msql_id",
"data": {
"fsrvoptions":{
"added": [{
"fsrvoption":"host",
"fsrvvalue":"192.168.1.1"
},{
"fsrvoption":"dbname",
"fsrvvalue":"edb"
},{
"fsrvoption":"port",
"fsrvvalue":"5450"
}]
},
"fsrvacl":{
"added": [{
"grantee":"PUBLIC",
"grantor":"enterprisedb",
"privileges":[{
"privilege_type":"U",
"privilege":true,
"with_grant":false
}]
}]
}
},
"expected_sql_file": "alter_options_privileges.sql",
"expected_msql_file": "alter_options_privileges_msql.sql"
}, {
"type": "alter",
"name": "Alter foreign server add options and privileges",
"endpoint": "NODE-foreign_server.obj_id",
"sql_endpoint": "NODE-foreign_server.sql_id",
"msql_endpoint": "NODE-foreign_server.msql_id",
"data": {
"fsrvoptions":{
"deleted": [{
"fsrvoption":"host",
"fsrvvalue":"192.168.1.1"
},{
"fsrvoption":"dbname",
"fsrvvalue":"edb"
},{
"fsrvoption":"port",
"fsrvvalue":"5450"
}]
},
"fsrvacl":{
"deleted": [{
"grantee":"PUBLIC",
"grantor":"enterprisedb",
"privileges":[{
"privilege_type":"U",
"privilege":true,
"with_grant":false
}]
}]
}
},
"expected_sql_file": "alter_remove_options_priv.sql",
"expected_msql_file": "alter_remove_options_priv_msql.sql"
}, {
"type": "delete",
"name": "Drop foreign server",
"endpoint": "NODE-foreign_server.delete_id",
"data": {
"name": "FS_$%{}[]()&*^!@\"'`\\/#"
}
}, {
"type": "delete",
"name": "Drop FDW",
"endpoint": "NODE-foreign_data_wrapper.delete_id",
"data": {
"name": "test_fdw_for_fs"
}
}
]
}

View File

@ -0,0 +1,6 @@
-- User Mapping : postgres
-- DROP USER MAPPING FOR postgres SERVER test_fs_for_user_mapping
CREATE USER MAPPING FOR postgres SERVER test_fs_for_user_mapping
OPTIONS ("user" 'test_user12', password 'secret123');

View File

@ -0,0 +1,5 @@
-- User Mapping : postgres
-- DROP USER MAPPING FOR postgres SERVER test_fs_for_user_mapping
CREATE USER MAPPING FOR postgres SERVER test_fs_for_user_mapping;

View File

@ -0,0 +1,2 @@
ALTER USER MAPPING FOR postgres SERVER test_fs_for_user_mapping
OPTIONS (DROP "user", DROP password);

View File

@ -0,0 +1,2 @@
ALTER USER MAPPING FOR postgres SERVER test_fs_for_user_mapping
OPTIONS (SET "user" 'test_user12', SET password 'secret123');

View File

@ -0,0 +1,6 @@
-- User Mapping : postgres
-- DROP USER MAPPING FOR postgres SERVER test_fs_for_user_mapping
CREATE USER MAPPING FOR postgres SERVER test_fs_for_user_mapping
OPTIONS ("user" 'test_user', password 'secret');

View File

@ -0,0 +1,2 @@
CREATE USER MAPPING FOR postgres SERVER test_fs_for_user_mapping
OPTIONS ("user" 'test_user', password 'secret');

View File

@ -0,0 +1,99 @@
{
"scenarios": [
{
"type": "create",
"name": "Create FDW for user mapping",
"endpoint": "NODE-foreign_data_wrapper.obj",
"sql_endpoint": "NODE-foreign_data_wrapper.sql_id",
"data": {
"name": "test_fdw_for_user_mapping",
"fdwacl": [],
"fdwoptions": []
},
"store_object_id": "True"
}, {
"type": "create",
"name": "Create foreign server for user mapping",
"endpoint": "NODE-foreign_server.obj",
"sql_endpoint": "NODE-foreign_server.sql_id",
"data": {
"name":"test_fs_for_user_mapping"
},
"store_object_id": "True"
}, {
"type": "create",
"name": "Create User Mapping",
"endpoint": "NODE-user_mapping.obj",
"sql_endpoint": "NODE-user_mapping.sql_id",
"msql_endpoint": "NODE-user_mapping.msql",
"data": {
"name": "postgres",
"umoptions":[{
"umoption":"user",
"umvalue":"test_user"
},{
"umoption":"password",
"umvalue":"secret"
}]
},
"expected_sql_file": "create_user_mapping.sql",
"expected_msql_file": "create_user_mapping_msql.sql"
}, {
"type": "alter",
"name": "Alter user mapping options",
"endpoint": "NODE-user_mapping.obj_id",
"sql_endpoint": "NODE-user_mapping.sql_id",
"msql_endpoint": "NODE-user_mapping.msql_id",
"data": {
"umoptions":{
"changed": [{
"umoption":"user",
"umvalue":"test_user12"
},{
"umoption":"password",
"umvalue":"secret123"
}]
}
},
"expected_sql_file": "alter_options.sql",
"expected_msql_file": "alter_options_msql.sql"
}, {
"type": "alter",
"name": "Alter user mapping drop options",
"endpoint": "NODE-user_mapping.obj_id",
"sql_endpoint": "NODE-user_mapping.sql_id",
"msql_endpoint": "NODE-user_mapping.msql_id",
"data": {
"umoptions":{
"deleted": [{
"umoption":"user",
"umvalue":"test_user12"
},{
"umoption":"password",
"umvalue":"secret123"
}]
}
},
"expected_sql_file": "alter_options_deleted.sql",
"expected_msql_file": "alter_options_deleted_msql.sql"
}, {
"type": "delete",
"name": "Drop user mapping",
"endpoint": "NODE-user_mapping.delete_id"
}, {
"type": "delete",
"name": "Drop foreign server",
"endpoint": "NODE-foreign_server.delete_id",
"data": {
"name": "test_fs_for_user_mapping"
}
}, {
"type": "delete",
"name": "Drop FDW",
"endpoint": "NODE-foreign_data_wrapper.delete_id",
"data": {
"name": "test_fdw_for_user_mapping"
}
}
]
}

View File

@ -0,0 +1,6 @@
-- User Mapping : enterprisedb
-- DROP USER MAPPING FOR enterprisedb SERVER test_fs_for_user_mapping
CREATE USER MAPPING FOR enterprisedb SERVER test_fs_for_user_mapping
OPTIONS ("user" 'test_user12', password 'secret123');

View File

@ -0,0 +1,5 @@
-- User Mapping : enterprisedb
-- DROP USER MAPPING FOR enterprisedb SERVER test_fs_for_user_mapping
CREATE USER MAPPING FOR enterprisedb SERVER test_fs_for_user_mapping;

View File

@ -0,0 +1,2 @@
ALTER USER MAPPING FOR enterprisedb SERVER test_fs_for_user_mapping
OPTIONS (DROP "user", DROP password);

View File

@ -0,0 +1,2 @@
ALTER USER MAPPING FOR enterprisedb SERVER test_fs_for_user_mapping
OPTIONS (SET "user" 'test_user12', SET password 'secret123');

View File

@ -0,0 +1,6 @@
-- User Mapping : enterprisedb
-- DROP USER MAPPING FOR enterprisedb SERVER test_fs_for_user_mapping
CREATE USER MAPPING FOR enterprisedb SERVER test_fs_for_user_mapping
OPTIONS ("user" 'test_user', password 'secret');

View File

@ -0,0 +1,2 @@
CREATE USER MAPPING FOR enterprisedb SERVER test_fs_for_user_mapping
OPTIONS ("user" 'test_user', password 'secret');

View File

@ -0,0 +1,99 @@
{
"scenarios": [
{
"type": "create",
"name": "Create FDW for user mapping",
"endpoint": "NODE-foreign_data_wrapper.obj",
"sql_endpoint": "NODE-foreign_data_wrapper.sql_id",
"data": {
"name": "test_fdw_for_user_mapping",
"fdwacl": [],
"fdwoptions": []
},
"store_object_id": "True"
}, {
"type": "create",
"name": "Create foreign server for user mapping",
"endpoint": "NODE-foreign_server.obj",
"sql_endpoint": "NODE-foreign_server.sql_id",
"data": {
"name":"test_fs_for_user_mapping"
},
"store_object_id": "True"
}, {
"type": "create",
"name": "Create User Mapping",
"endpoint": "NODE-user_mapping.obj",
"sql_endpoint": "NODE-user_mapping.sql_id",
"msql_endpoint": "NODE-user_mapping.msql",
"data": {
"name": "enterprisedb",
"umoptions":[{
"umoption":"user",
"umvalue":"test_user"
},{
"umoption":"password",
"umvalue":"secret"
}]
},
"expected_sql_file": "create_user_mapping.sql",
"expected_msql_file": "create_user_mapping_msql.sql"
}, {
"type": "alter",
"name": "Alter user mapping options",
"endpoint": "NODE-user_mapping.obj_id",
"sql_endpoint": "NODE-user_mapping.sql_id",
"msql_endpoint": "NODE-user_mapping.msql_id",
"data": {
"umoptions":{
"changed": [{
"umoption":"user",
"umvalue":"test_user12"
},{
"umoption":"password",
"umvalue":"secret123"
}]
}
},
"expected_sql_file": "alter_options.sql",
"expected_msql_file": "alter_options_msql.sql"
}, {
"type": "alter",
"name": "Alter user mapping drop options",
"endpoint": "NODE-user_mapping.obj_id",
"sql_endpoint": "NODE-user_mapping.sql_id",
"msql_endpoint": "NODE-user_mapping.msql_id",
"data": {
"umoptions":{
"deleted": [{
"umoption":"user",
"umvalue":"test_user12"
},{
"umoption":"password",
"umvalue":"secret123"
}]
}
},
"expected_sql_file": "alter_options_deleted.sql",
"expected_msql_file": "alter_options_deleted_msql.sql"
}, {
"type": "delete",
"name": "Drop user mapping",
"endpoint": "NODE-user_mapping.delete_id"
}, {
"type": "delete",
"name": "Drop foreign server",
"endpoint": "NODE-foreign_server.delete_id",
"data": {
"name": "test_fs_for_user_mapping"
}
}, {
"type": "delete",
"name": "Drop FDW",
"endpoint": "NODE-foreign_data_wrapper.delete_id",
"data": {
"name": "test_fdw_for_user_mapping"
}
}
]
}

View File

@ -11,7 +11,7 @@
"columns": [],
"schema": "testschema"
},
"store_table_id": true
"store_object_id": true
},
{
"type": "create",

View File

@ -11,7 +11,7 @@
"columns": [],
"schema": "testschema"
},
"store_table_id": true
"store_object_id": true
},
{
"type": "create",

View File

@ -11,7 +11,7 @@
"columns": [],
"schema": "testschema"
},
"store_table_id": true
"store_object_id": true
},
{
"type": "create",

View File

@ -19,7 +19,7 @@
"schema": "testschema",
"spcname": "pg_default"
},
"store_table_id": true
"store_object_id": true
}, {
"type": "create",
"name": "Create compound trigger for insert or delete",

View File

@ -16,7 +16,7 @@
"schema": "testschema",
"spcname": "pg_default"
},
"store_table_id": true
"store_object_id": true
},
{
"type": "create",

View File

@ -19,7 +19,7 @@
"schema": "testschema",
"spcname": "pg_default"
},
"store_table_id": true
"store_object_id": true
}, {
"type": "create",
"name": "Create Extension",

View File

@ -19,7 +19,7 @@
"schema": "testschema",
"spcname": "pg_default"
},
"store_table_id": true
"store_object_id": true
}, {
"type": "create",
"name": "Create Extension",

View File

@ -22,7 +22,7 @@
"schema": "public",
"spcname": "pg_default"
},
"store_table_id": true
"store_object_id": true
}, {
"type": "create",
"name": "Create Rule for insert event",

View File

@ -79,6 +79,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
self.apppath = os.getcwd()
# Status of the test case
self.final_test_status = True
self.parent_ids = dict()
# Added line break after scenario name
print("")
@ -99,7 +100,6 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
getattr(BaseTestGenerator, 'for_modules', []))
for module in resql_module_list:
self.table_id = None
module_path = resql_module_list[module]
# Get the folder name based on server version number and
# their existence.
@ -126,6 +126,9 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
for key, scenarios in data.items():
self.execute_test_case(scenarios)
# Clear the parent ids stored for one json file.
self.parent_ids.clear()
# Check the final status of the test case
self.assertEqual(self.final_test_status, True)
@ -174,8 +177,15 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
options['scid'] = int(object_id)
else:
options['scid'] = int(self.schema_id)
elif arg == 'tid' and self.table_id:
options['tid'] = int(self.table_id)
# tid represents table oid
elif arg == 'tid' and 'tid' in self.parent_ids:
options['tid'] = int(self.parent_ids['tid'])
# fid represents FDW oid
elif arg == 'fid' and 'fid' in self.parent_ids:
options['fid'] = int(self.parent_ids['fid'])
# fsid represents Foreign Server oid
elif arg == 'fsid' and 'fsid' in self.parent_ids:
options['fsid'] = int(self.parent_ids['fsid'])
else:
if object_id is not None:
options[arg] = int(object_id)
@ -236,9 +246,9 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
resp_data = json.loads(response.data.decode('utf8'))
object_id = resp_data['node']['_id']
# Table child nodes require table id
if 'store_table_id' in scenario:
self.table_id = object_id
# Store the object id based on endpoints
if 'store_object_id' in scenario:
self.store_object_ids(object_id, scenario['endpoint'])
# Compare the reverse engineering SQL
if not self.check_re_sql(scenario, object_id):
@ -370,7 +380,9 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
# Remove first and last double quotes
if resp_sql.startswith('"') and resp_sql.endswith('"'):
resp_sql = resp_sql[1:-1]
resp_sql = resp_sql.rstrip()
# Remove triling \n
resp_sql = resp_sql.rstrip()
# Check if expected sql is given in JSON file or path of the output
# file is given
@ -429,7 +441,9 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
# Remove first and last double quotes
if resp_sql.startswith('"') and resp_sql.endswith('"'):
resp_sql = resp_sql[1:-1]
resp_sql = resp_sql.rstrip()
# Remove triling \n
resp_sql = resp_sql.rstrip()
# Check if expected sql is given in JSON file or path of the output
# file is given
@ -562,3 +576,17 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
pg_cursor.close()
return sql
def store_object_ids(self, object_id, endpoint):
"""
This functions will store the object id based on endpoints
:param object_id: Object id of the created node
:param endpoint:
:return:
"""
if endpoint.__contains__("NODE-table"):
self.parent_ids['tid'] = object_id
elif endpoint.__contains__("NODE-foreign_data_wrapper"):
self.parent_ids['fid'] = object_id
elif endpoint.__contains__("NODE-foreign_server"):
self.parent_ids['fsid'] = object_id