Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore database state after integration test using Docker?

We are using PostgreSQL along with EAR deployed to JBoss. During the build process we have a development database dump that is used then in integration test: special artifact is deployed and tests communicate with the app using http client.

Currently, the database state changes during tests run, so we have no way but to put additional content for each test that modifies it, so no tests would depend each other. It takes really lots of time and patience as such test become even dependent on the order of records.

Is there a way to make a snapshot of DB so that to restore it after each test run with a reasonable amount of resources? Could Docker help? Or any other way around?

H2 is not the way, because we use some PostgreSQL-specific features. Tests may span multiple transactions, so I guess rollback would not help either.

like image 637
Valya Avatar asked Oct 17 '16 17:10

Valya


1 Answers

One straightforward way with Docker is to have your database snapshot as a volume you reset and then mount into the beginning of your test run.

You can massage this data prior to your tests running (either have a tar of your entire starting database config or something else), then launch your PostgreSQL test database, with the test data mounted as a volume and your PostgreSQL pointing to this, for each test.

like image 68
enderland Avatar answered Sep 30 '22 05:09

enderland