Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql扩展pg_跨pg版本回归测试_Postgresql - Fatal编程技术网

Postgresql扩展pg_跨pg版本回归测试

Postgresql扩展pg_跨pg版本回归测试,postgresql,Postgresql,我正在编写一个PostgreSQL扩展,它需要在PostgreSQL 9.4、9.5、9.6和10上工作。我正在使用标准的pg_回归回归测试和make installcheck进行测试。我正在尝试使用Travis CI跨版本设置测试 因为这是一个安全关键的扩展,所以在我的测试用例中有很多语句应该抛出错误,例如检查白名单关键字 pg_regresse通过将测试脚本的输出与预期输出进行比较来工作。对于普通的、成功的查询,这很好,但是对于错误,我有一个问题 对于9.6,错误的输出似乎总是有上下文行,而

我正在编写一个PostgreSQL扩展,它需要在PostgreSQL 9.4、9.5、9.6和10上工作。我正在使用标准的
pg_回归
回归测试和
make installcheck
进行测试。我正在尝试使用Travis CI跨版本设置测试

因为这是一个安全关键的扩展,所以在我的测试用例中有很多语句应该抛出错误,例如检查白名单关键字

pg_regresse
通过将测试脚本的输出与预期输出进行比较来工作。对于普通的、成功的查询,这很好,但是对于错误,我有一个问题

对于9.6,错误的输出似乎总是有
上下文
行,而对于9.4,它从来没有这样做过。换句话说,9.6正在发送9.4中缺少的故障排除信息,这导致测试在不同版本之间不兼容

我的测试脚本的相关部分包括:

set client_min_messages to warning;
set log_error_verbosity to terse;
create extension roleman;

-- whitelist errors

-- no tables so pick a random number and cast to oid
select roleman.grant_table('postgres', 1::oid, array['execute', 'drop']);
select roleman.grant_schema('postgres', 'foo', array['execute']);
select roleman.grant_schema_all('postgres', 'foo', 'tables', array['execute', 'drop everything']);
select roleman.grant_database('postgres', 'foo', array['execute']);
select roleman.grant_function('postgres', 1::OID, array['wheeee']);
select roleman.grant_seq('postgres', 1::oid, array['execute']);
9.6的输出为:

set client_min_messages to warning;
set log_error_verbosity to terse;
create extension roleman;
-- whitelist errors
-- no tables so pick a random number and cast to oid
select roleman.grant_table('postgres', 1::oid, array['execute', 'drop']);
ERROR:  bad database permissions for postgres,  table 1, perms execute, drop
CONTEXT:  PL/pgSQL function grant_table(text,regclass,text[]) line 4 at RAISE
select roleman.grant_schema('postgres', 'foo', array['execute']);
ERROR:  bad permissions for postgres,  schema foo, perms execute
CONTEXT:  PL/pgSQL function grant_schema(text,text,text[]) line 4 at RAISE
select roleman.grant_schema_all('postgres', 'foo', 'tables', array['execute', 'drop everything']);
ERROR:  bad database permissions for postgres,  schema foo, type tables, perms execute, drop everything
CONTEXT:  PL/pgSQL function grant_schema_all(text,text,text,text[]) line 5 at RAISE
select roleman.grant_database('postgres', 'foo', array['execute']);
ERROR:  bad database permissions for postgres, dbname foo, perms execute
CONTEXT:  PL/pgSQL function grant_database(text,text,text[]) line 4 at RAISE
select roleman.grant_function('postgres', 1::OID, array['wheeee']);
ERROR:  bad database permissions for postgres,  function 1, perms wheeee
CONTEXT:  PL/pgSQL function grant_function(text,regprocedure,text[]) line 4 at RAISE
select roleman.grant_seq('postgres', 1::oid, array['execute']);
ERROR:  bad database permissions for postgres,  sequence 1, perms execute
CONTEXT:  PL/pgSQL function grant_seq(text,regclass,text[]) line 4 at RAISE
在9.4上,输出相同,只是缺少上下文行。我试图通过在脚本开头设置错误详细程度来禁用这些行,但没有效果。上下文行的缺失通过测试失败来处理


有什么办法可以解决这个问题吗?

这类事情是一件很痛苦的事情
pg_regresse
支持备用输出文件,但它们的使用和维护非常笨拙

BDR和pglogical所做的是
\set VERBOSITY terse
,这有助于解决一些此类问题

在更复杂的情况下,有时可以使用
DO
块。差不多

DO LANGUAGE plpgsql $$
BEGIN
    BEGIN
        PERFORM the_statement;
    EXCEPTION WHEN ... THEN ...
        ... check exception matches expected here ...
    END;
END;
$$

这是一个好主意,我可能不得不使用do block方法,但我很惊讶
\set VERBOSITY
似乎没有效果。是的,我也是。即使在
\c
等中也应该是持久的,因为它是psql端。确实要这样做,而不是设置日志\u错误\u详细程度?好的,因此找到了问题,
详细程度
区分大小写。谢谢