-
Notifications
You must be signed in to change notification settings - Fork 13
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
Setup test database for running tests for database #350
Conversation
* Add .env.test
I wonder if there's some issue with the what GitHub action is using to run hadolint. Saw the same test error in Won's PR that has nothing to do with Dockerfile. |
I filed hadolint/hadolint-action#79 on the hadolint-action failures. |
Looks like it's fixed. |
* Change volume folder structure * Adjust connection string for .env.example
Glad you showed me that SQL setup file method. It's pretty interesting. Both databases now run under the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not rename mysql-data
. We can move the .sql
you created into config/
and then mount it where it needs to go in Docker.
For tests vs. running dev, the app uses dev-secrets/DATABASE_URL
. How will we deal with differences here?
Ask @dadolhay if there is anything to know about with respect to using the root user like this. I think it's fine, but I'm not an expert.
Also, do you want to blow-away the test-db every time you init in your .sql
? It might make it easier to run tests.
I'm not sure I understand. Is updating |
It is not. The |
Looking at the test and |
How about this? I have applied changes according to your feedbacks, but I keep the original setup for In my mind, I'm not sure it's necessary to drop the test database for testing, since tests should probably clean the test database before running tests, to avoid interference between each tests or any manual testing. I haven't heard from Denes. Given both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this. The only thing I'd like to see improved is not having a duplicate .env
in here. If we have a lot of these files, people have to remember to update them. Can we eliminate the need for that?
Obviously people running the tests (e.g., CI) would need to set this value to override it.
I don't want to make this impossible, but I also don't want more maintenance hassle.
The |
If we don't want another |
@@ -59,6 +59,8 @@ $ npm run db:studio | |||
|
|||
> **Note** `npm run build` needs to be executed the first time running the project. As it generates a `build/server.js` script that `npm run dev` depends on. Subsequent times, only `npm run dev` is needed to run the app in development mode. | |||
|
|||
> **Note** If you are running test scripts for the first time, change `DATABASE_URL` in `.env` to `DATABASE_URL="mysql://starchart:[email protected]:3306/starchart"` and run `npm run setup` to setup the test database. You can change this back afterward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be done in this PR, but would it be worth to add a new setup:test
script to do this instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps. If someone can write a script that has a command to parse the file to change the variable, runs npm run setup
, then changes it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I think we can simply copy the setup
command to setup:test
, and override the value for DATABASE_URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Eakam1007 do you want to file an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I might just create a PR for this today. Seems simple enough (unless I am missing something)
Part of #238
This sets up a test database
starchart_test
in the containertest_database
, and it can be used to run tests without interfering with the other database container or any other database.For convenience, I added a
.env.test
file, for devs to runcp .env.test .env
to change the database connection string to the test database.Changes
docker-compose.yml
.env.test
/mysql-data-test
for git, Prettier, ESlint, and Docker.Testing
cp .env.test .env
docker compose up -d
to make containers like usualnpm run steup
to connect, push schema, and seed the databasenpm run db:studio
to check that the database works