theory / tap-parser-sourcehandler-pgtap

TAP::Parser::SourceHandler::pgTAP
http://search.cpan.org/dist/TAP::Parser::SourceHandler::pgTAP
11 stars 13 forks source link

pg_tapgen generated test for serial sequence fails #22

Closed wwuck closed 3 years ago

wwuck commented 5 years ago

I am testing on PostgreSQL 11.2 (Debian 11.2-1.pgdg90+1).

I created a new test database with the following psql script:

CREATE DATABASE test_pgtap;

\c test_pgtap;

CREATE SCHEMA pgtap;

CREATE EXTENSION pgtap WITH SCHEMA pgtap;

CREATE TABLE public.test_table
(
    id serial not null
);

I then auto-generated some tests using the latest pg_tapgen, and one of the generated tests was this one:

SELECT col_default_is(   'public', 'test_table', 'id', 'nextval(''test_table_id_seq''::regclass)', 'Column public.test_table.id default is');

The commands I used to generate and run the tests were:

mkdir t
cd t
pg_tapgen -U testuser -h postgres.example.com -p 5432 -d test_pgtap
cd ..
PGOPTIONS=--search_path=pgtap pg_prove --dbname test_pgtap -U testuser -h postgres.example.com -p 5432 --ext .sql

This test fails with the following error:

t/schema.sql ................... ok   
t/table_public.test_table.sql .. 1/8 
# Failed test 8: "Column public.test_table.id default is"
#         have: nextval('public.test_table_id_seq'::regclass)
#         want: nextval('test_table_id_seq'::regclass)
# Looks like you failed 1 test of 8
t/table_public.test_table.sql .. Failed 1/8 subtests 

Test Summary Report
-------------------
t/table_public.test_table.sql (Wstat: 0 Tests: 8 Failed: 1)
  Failed test:  8
Files=2, Tests=14,  0 wallclock secs ( 0.03 usr  0.00 sys +  0.06 cusr  0.01 csys =  0.10 CPU)
Result: FAIL

Is this possible to fix in pg_tapgen or pg_prove? I saw that the want: output in pg_tapgen comes directly from pg_catalog.pg_get_expr(d.adbin, ad.adrelid) but I couldn't find where the have: output is coming from in pg_prove so I was unable to debug this issue any further.

theory commented 3 years ago

pg_tapgen relies on pg_get_expr() to get the default value. Seems like you have the schema in the path when you run pg_tapgen but not when you run the test. I you want the schema included in the test, remove it from the search path when you run pg_tapgen.