lundi 19 septembre 2016

Test strategy for postgres in the backend

I'd like to test a backend that performs queries agains a Postgres DB. As far as I understand mocking postgres is not possible (as opposed to MongoDB) and one should query a real database.

So my first question is, what are the standard strategies to test postgres queries?

Right now, I'm trying to recreate a database with no data so that I can plug in information for each test and have full control of the output. However, it is not clear how that can be done. So far I've come up with something like:

pg_dump mydb --schema-only | pg_restore testdb

However it is really slow. I suppose one of the reasons is that if the test client is not in the same net as the database, then pg_dump will have to fetch all the information through the net only to send it back to the same machine.

I suppose what I'm looking for would be similar to

Create new database testdb with template mydb 

which only copied schema info and which didn't force all connections to be closed.

Aucun commentaire:

Enregistrer un commentaire