pgtap icon indicating copy to clipboard operation
pgtap copied to clipboard

Allow to test with snapshots

Open S-Stanley opened this issue 2 years ago • 2 comments

Hello guys,

I have to update many tests of SQL functions, and it's a tough work because, when we add/update/delete new columns, we have to update all the previous assertions, which is kind of a lot of work.

I was wondering if it was possible to add snapshot feature, similar to what you can find on javascript testing library like jest toMatchSnapshot.

For example, now we are testing like this:

SELECT results_eq(
    $$
        SELECT
            column_name
        FROM
            table_name
    $$,
    $$
        VALUES(
            'x'
        ), (
            'y'
        ), (
            '42'
        )
    $$,
    'Assert that...'
)

And using snapshots it would be for example

SELECT snapshot_equal(
    $$
        SELECT
            column_name
        FROM
            table_name
    $$,
    'Assert that...'
)

S-Stanley avatar Oct 02 '23 13:10 S-Stanley

Where would it store the snapshot?

theory avatar Oct 02 '23 16:10 theory

This sounds like the regression testing in Postgres: comparing the output of psql scripts to the stored expected output.

pgTAP could implement something similar using temporary tables and \copy for loading the snapshot data.

ewie avatar Oct 15 '23 20:10 ewie