orlangure/gnomock

Bug: postgres WithDatabase() causes failure on WithContainerReuse()

cgeers opened this issue · 1 comments

Describe the bug
with the postgres preset, the WithDatabase option can't be used in combination with WithContainerReuse gnomock start option. The desired change is to make WithDatabase idempotent.

To Reproduce
create a postgres preset with WithDatabase option, also use gnomock WithContainerReuse start option. The first creation operates normally, the second attempt, when the container is reused, it fails with:

can't init container: pq: database "<db_name>" already exists

Expected behavior
multiple, subsequent runs of this preset with this configuration succeeds.

Screenshots
n/a

System (please complete the following information):

  • OS: macos
  • Version: v0.24.0
  • Docker version: 20.10.17

Additional context
n/a

Hi @cgeers and thank you for the report.

I was able to reproduce the problem and have a fix in #785.
In addition, I'm planning another improvement in container reuse, would you like to share your thoughts about this draft? It will allow to not only reuse a database, but to reset the container to its default state when asked to, so that the container itself is not recreated, but the state is fresh for every test.