Add documentation on using pg_tap with sqitch #78

Closed
joevandyk opened this Issue Mar 4, 2013 · 8 comments

Projects

None yet

2 participants

@joevandyk

What's the best way of using pg_tap with sqitch?

I wouldn't want to add pg_tap to production databases, I think (so that rules out adding a 'deploy' script for pg_tap).

Should the pg_tap extension be installed on test databases outside of sqitch? Or maybe the pg_tap extension is installed by a verification script if it doesn't exist yet?

@theory
Owner
theory commented Mar 4, 2013

I install the pgTAP extension separately, and then just have this at the top of al my test files:

SET client_min_messages TO warning;
CREATE EXTENSION IF NOT EXISTS pgtap;
RESET client_min_messages;
@theory theory closed this Mar 4, 2013
@joevandyk

Could there be a test file that runs before all the tests?

So this doesn't have to be in every single file?

Could also use that "before test" file to load data that's used by all the
tests.

On Mar 4, 2013, at 10:51 AM, "David E. Wheeler" notifications@github.com
wrote:

I install the pgTAP extension separately, and then just have this at the
top of al my test files:

SET client_min_messages TO warning;
CREATE EXTENSION IF NOT EXISTS pgtap;
RESET client_min_messages;


Reply to this email directly or view it on
GitHubhttps://github.com/theory/sqitch/issues/78#issuecomment-14397577
.

@theory
Owner
theory commented Mar 4, 2013

Sure. You could just put that into a file, and then use \i to include it at the top of each test.

@joevandyk

The downside of that is then the file gets ran for every single test file in the project.

Would be simpler if there was a way to tell sqitch that there's a file it should load once before running all the tests.

@joevandyk

Also, this doesn't seem to raise an error:

BEGIN;                                                                                              
select plan(1);                                                                                     

SELECT has_schema('no', 'ugh');                                                                     
SELECT hasnt_schema('no', 'ugh');                                                                   

ROLLBACK;

How should pg_tap work with sqitch?

If I raise a plpgsql exception from inside a verify script, then i see the error and sqitch verify fails.

@theory
Owner
theory commented Mar 5, 2013

Would be simpler if there was a way to tell sqitch that there's a file it should load once before running all the tests.

Sqitch does not run tests.

Unless you mean the verify scripts? I personally have not been using pgTAP for those, because I would expect them to run in production. Think of them ore like verification tests rather than unit tests. In fact, because pgTAP does not cause psql to exit with a non-0 on test failure, it won't even work in verify scripts. You need to have something that throws an exception to indicate verify failure; I have some examples in this presentation. Slide 96 has one example using privilege-testing functions, while Slide 303 shows a hack to get something to fail with a divide-by-zero error. :-)

Anyway, your pgTAP example needs this line before the ROLLBACK:

SELECT * FROM finish();

But I always have my unit tests independent of Sqitch scripts, and run them with pg_prove.

@joevandyk

Yes, sorry, I meant the verify scripts.

I was thinking of using those for unit tests, but it sounds like that's not the intent of the verify scripts.

@theory
Owner
theory commented Mar 5, 2013

Right, it's not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment