Skip to content
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

Use backend specific env vars if present for tests #644

Merged
merged 1 commit into from Feb 8, 2017

Conversation

sgrif
Copy link
Member

@sgrif sgrif commented Feb 8, 2017

Having a single DATABASE_URL is really nice in contexts where you're
likely only using one backend. It makes a lot of sense for Travis, which
runs against one backend at a time. It also makes sense for CLI to
continue to default to it by convention, as it has to look at the URL to
figure out which backend to use.

However, for development on Diesel itself, we are switching between
different backends all the time. This didn't matter as much for SQLite,
since we can just give it some random file path and have it work (and
we're usually connecting to :memory: anyway). For MySQL though, we
need to be more concrete. Where applicable, our test suite will now look
for PG_DATABASE_URL, before falling back to just DATABASE_URL. This
does not apply to our examples, as they assume PG and set the
DATABASE_URL manually in examples/test_all. This also doesn't apply
to CLI's test suite, which sets DATABASE_URL manually as needed, since
it can't run in a transaction and thus needs a different database
per-test.

So developers who frequently run our test suite against more than one
backend will likely have a .env file which looks like:

PG_DATABASE_URL=postgres://localhost/diesel_test
MYSQL_DATABASE_URL=mysql://localhost/diesel_test
SQLITE_DATABASE_URL=/tmp/test.db

Having a single `DATABASE_URL` is really nice in contexts where you're
likely only using one backend. It makes a lot of sense for Travis, which
runs against one backend at a time. It also makes sense for CLI to
continue to default to it by convention, as it has to look at the URL to
figure out which backend to use.

However, for development on Diesel itself, we are switching between
different backends all the time. This didn't matter as much for SQLite,
since we can just give it some random file path and have it work (and
we're usually connecting to `:memory:` anyway). For MySQL though, we
need to be more concrete. Where applicable, our test suite will now look
for `PG_DATABASE_URL`, before falling back to just `DATABASE_URL`. This
does not apply to our examples, as they assume PG and set the
`DATABASE_URL` manually in `examples/test_all`. This also doesn't apply
to CLI's test suite, which sets `DATABASE_URL` manually as needed, since
it can't run in a transaction and thus needs a different database
per-test.

So developers who frequently run our test suite against more than one
backend will likely have a `.env` file which looks like:

```
PG_DATABASE_URL=postgres://localhost/diesel_test
MYSQL_DATABASE_URL=mysql://localhost/diesel_test
SQLITE_DATABASE_URL=/tmp/test.db
```
@sgrif sgrif requested a review from killercup February 8, 2017 13:47
Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

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

Nice. We should probably have a contributing.md documenting stuff like this.

@sgrif
Copy link
Member Author

sgrif commented Feb 8, 2017

Agreed. I'll add it to the todo list.

@sgrif sgrif merged commit 6570663 into master Feb 8, 2017
@sgrif sgrif deleted the sg-backend-specific-env-vars branch February 8, 2017 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants