Skip to content

#29 - Use TestContainers for integration tests #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

Conversation

schauder
Copy link
Contributor

This change only provides the change for postgresql since for MS-SQL im still waiting for advice from legal.

… found.

Postgres integration tests now run either with a locally installed and started database or if no such database can be found an instance gets started in a Docker container via Testcontainers.
Formatting for improved readability.
Fixed cut'n'paste JavaDoc.
Copying over the port from configuration to `ConnectionFactory`.
@schauder schauder requested a review from mp911de January 15, 2019 12:58
return local();

ExternalDatabase local = local();
if (local.checkValidity()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest inverting the condition. "If Docker is available, otherwise".
Some users might have an important state in their local database, or an outdated version of it, or many other reasons.

FYI you can check Docker's availability with:

return DockerClientFactory.instance().client() != null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand and somewhat agree with the concern.
My idea behind making it in this order was that one might want to use a specially configured database, e.g. for reproducing an issue that only appears with a special configuration.

I'm not at all sure if that is a relevant use case but we would lose it if we reverse the preference.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. What about something like Boolean.getProperty("spring.data.r2dbc.test.forceLocalDB")?

Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall and testcontainers integrate nicely with the existing code. Do we want to wait for the SQL Server change or do we want to proceed and merge this PR?

@schauder
Copy link
Contributor Author

@mp911de I vote for going forward with the PR without waiting for Ms-SQL. To freely quote Winnie the Pooh: "You never know about legal".

What is your opinion on the little discussion I had with @bsideup? I'd currently say: let's just invert the order of things and add more flexibility to it once we need it.

@mp911de
Copy link
Member

mp911de commented Jan 16, 2019

I guess I'm the only one with a strong local-running database preference. Let's call the property spring.data.r2dbc.test.preferLocalDatabase and default to test-containers usage.

We now prefer a database based on TestContainers.
Only if this can't be obtained do we try to access a local database for Postgres.

This minimizes the risk of accessing a database during tests that is not intended for that purpose.

If the system property `spring.data.r2dbc.test.preferLocalDatabase` is set to "true" the local database is preferred.
@schauder
Copy link
Contributor Author

schauder commented Jan 16, 2019

I added a commit making the preferred order configurable and defaulting on TestContainers first.

Will you take it from here, @mp911de ?

@mp911de
Copy link
Member

mp911de commented Jan 18, 2019

Going to merge this one now.

mp911de pushed a commit that referenced this pull request Jan 18, 2019
Postgres integration tests now run either with a locally installed and started database or if no such database can be found an instance gets started in a Docker container via Testcontainers.

We prefer a database based on TestContainers. Only if this can't be obtained do we try to access a local database for Postgres.

This minimizes the risk of accessing a database during tests that is not intended for that purpose.

If the system property `spring.data.r2dbc.test.preferLocalDatabase` is set to "true" the local database is preferred.

Original pull request: #51.
mp911de added a commit that referenced this pull request Jan 18, 2019
Add author tags. Add static factory method to create an unavailable database object instance. Simplify database selection. Javadoc.

Original pull request: #51.
@mp911de mp911de added the type: enhancement A general enhancement label Jan 18, 2019
@mp911de mp911de added this to the 1.0 M2 milestone Jan 18, 2019
@mp911de
Copy link
Member

mp911de commented Jan 18, 2019

That's merged and polished now. Thank you.

@mp911de mp911de closed this Jan 18, 2019
@mp911de mp911de deleted the issue/gh-29 branch January 18, 2019 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants