Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add has_sequence() variant with schema and no description #58

Closed
Su-Shee opened this issue Feb 3, 2014 · 2 comments
Closed

Add has_sequence() variant with schema and no description #58

Su-Shee opened this issue Feb 3, 2014 · 2 comments

Comments

@Su-Shee
Copy link

Su-Shee commented Feb 3, 2014

I use "has_sequence" to test a column with type serial.

The test fails when I omit the description part and returns ok if I add one.

It does NOT however return "If you omit the test description, it will be set to "Sequence :sequence should exist"." as the documentation says.

On PostgreSQL 9.1.3 on i486-slackware-linux-gnu, compiled by gcc (GCC) 4.7.0, 32-bit, tested with pgtap 0.93.0 and 0.94.0

@theory
Copy link
Owner

theory commented Feb 4, 2014

I usually test a SERIAL column like this:

SELECT has_column(        'foos', 'foo_id' );
SELECT col_type_is(       'foos', 'foo_id', 'integer' );
SELECT col_not_null(      'foos', 'foo_id' );
SELECT col_has_default(   'foos', 'foo_id' );
SELECT col_default_is(    'foos', 'foo_id', 'nextval(''foos_foo_id_seq''::regclass)' );
SELECT col_is_pk(         'foos', 'foo_id' );

You can test for the sequence like this:

SELECT has_sequence('foos_foo_id_seq');

If you have it in a schema not in the search path, so you have to pass the schema name, yeah, you have to specify the description. That's a bug. :-( I usually set the search path, myself, so that I don't worry about the schema arg.

@theory
Copy link
Owner

theory commented Feb 4, 2014

Oh, there is no form of has_sequence() that includes the schema and not the description. From the docs:

SELECT has_sequence( :schema, :sequence, :description );
SELECT has_sequence( :sequence, :description );
SELECT has_sequence( :sequence );

There are a few functions like that, I think because, earlier in the development of pgTAP, I avoided having functions with the same number of params, because otherwise Postgres could complain that two functions matched the signature, if we also had this:

SELECT has_sequence( :schema, :sequence );

However, I later just started disambiguating by casting that second argument to NAME. But it's kind of a PITA. Anyway, that signature could be added, but it might break existing tests in the wild that pass :sequence and :description without any casts.

@theory theory changed the title has_sequence fails without description Add has_sequence() variant with schema and no description Mar 20, 2015
@theory theory closed this as completed in 3629e17 Mar 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants