Skip to content

Conversation

@sweatybridge
Copy link
Contributor

@sweatybridge sweatybridge commented Aug 3, 2022

What kind of change does this PR introduce?

feature: supabase db test

What is the current behavior?

no cli native way to run tests

What is the new behavior?

  • installs pg_prove on supabase_db_cli container once
  • copies supabase/tests into supabase_db_cli container
  • enable pgtap extension temporarily
  • runs pg_prove via docker exec and prints out results

Additional context

Example order_test.pg

BEGIN;
SELECT plan(1);

SELECT has_column(
    'public',
    'order',
    'status',
    'status should exist'
);

SELECT * FROM finish();
ROLLBACK;

Output

$ supabase db test
supabase/tests/order_test.pg .. ok
supabase/tests/pet_test.pg .... ok
All tests successful.
Files=2, Tests=2,  1 wallclock secs ( 0.01 usr  0.00 sys +  0.04 cusr  0.02 csys =  0.07 CPU)
Result: PASS

@coveralls
Copy link

coveralls commented Aug 3, 2022

Pull Request Test Coverage Report for Build 3172017203

  • 30 of 78 (38.46%) changed or added relevant lines in 6 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.08%) to 40.536%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cmd/db.go 2 8 25.0%
internal/db/test/test.go 23 65 35.38%
Files with Coverage Reduction New Missed Lines %
cmd/db.go 1 44.94%
Totals Coverage Status
Change from base Build 3166989322: -0.08%
Covered Lines: 2041
Relevant Lines: 5035

💛 - Coveralls

@sweatybridge sweatybridge marked this pull request as ready for review August 5, 2022 14:29
@psteinroe
Copy link

this is awesome!! Are tests within nested directories also supported?

@soedirgo
Copy link
Member

I think instead of manually traversing the dirs, we can instead use one file as an entrypoint and use the \i/\include directive to include other files.

Or use the --recurse flag from pg_prove.

@psteinroe
Copy link

I think instead of manually traversing the dirs, we can instead use one file as an entrypoint and use the \i/\include directive to include other files.

Or use the --recurse flag from pg_prove.

+1 for the recurse flag. The \include directive would require the user to manually include hundreds of files eventually.

@soedirgo
Copy link
Member

soedirgo commented Sep 30, 2022

You can also use wildcards with the include directive iirc, so both approaches should be fine.

(Somehow I can't find where the reference is for the directives, so we should probably put this up somewhere on the CLI docs)

@sweatybridge
Copy link
Contributor Author

Thanks for the suggestions! Added --recurse flag and undid changes to initial schema.

@sweatybridge sweatybridge enabled auto-merge (rebase) October 3, 2022 06:26
@sweatybridge sweatybridge disabled auto-merge October 3, 2022 06:27
@sweatybridge sweatybridge merged commit 0e1fac8 into main Oct 3, 2022
@sweatybridge sweatybridge deleted the pgtap branch October 3, 2022 06:27
@github-actions
Copy link

github-actions bot commented Oct 3, 2022

🎉 This PR is included in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@psteinroe
Copy link

psteinroe commented Oct 31, 2022

@sweatybridge why do we only search for .pg files? All our tests are .sql. I can fix my nvim config, but still curious since most editors do not recognise .pg files.

EDIT: Created issue #571

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants