minigl: Allow using embedded postgres in unit tests #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here's a proof of concept for #179. It uses embedded-postgres to spin up a test server, and uses the configModifier feature to load a new config file we write to a temporary directory
I wanted to get this working with parameterized tests or test templates.. but I couldn't find a way to pull this off in junit5. one reason this is so so is BalanceTest - we want the entire test class to be parameterized and to use the same database resource, but this doesn't seem to work. I think junit4 used to be able to parameterize an entire class, but not junit5. While doing test templates, I noted that although the test template can dynamically register ParameterResolvers, these aren't registered in advance of calling the classes constructor.. so we can't initialize the class in that way.
So instead I just got it working by setting a system property when calling
gradle test
. TestBase checks which driver to use and sets up the database accordingly.One downside is this isn't automatic, so we'll have to decide how to tackle it in the travis-ci.yml file or look into alternative approaches. That said, if we don't mind tacking on on
cd modules/minigl && gradle clean test -Dtest.minigl_db_driver=postgres
as an extra test command, we're good to go :)