njord-rs / njord

A versatile, feature-rich Rust ORM ⛵
https://njord.rs
BSD 3-Clause "New" or "Revised" License
409 stars 21 forks source link

Add mysql delete tests #155

Closed chaseWillden closed 1 month ago

chaseWillden commented 1 month ago

@mjovanc I was trying to figure out how to mock the PooledConn so that we don't have to have a MySql db up and running during the tests.

I think this was the closest that I was able to come up with.

Check it out and let me know if this is good practice.

mjovanc commented 1 month ago

My take is that everything that is in tests/ should not be mocked since it is not unit tests. They are integration tests. If you want to write unit tests you should put the tests inside the corresponding file, let's say you create unit tests for select.rs then the tests should be inside the same file.

But if you want to test the integration, you should spin up the docker container for a MySQL database and test it against that.

mjovanc commented 1 month ago

Here we are spinning up the MySQL db service in the workflow which we should have integration tests to: https://github.com/njord-rs/njord/blob/master/.github/workflows/core.yml#L24

So you need to setup the docker container for MySQL with docker compose, and when running the docker compose up command, you need to configure a script to be run inside it to add the schema, populate the db (with a .SQL file) with dummy data and then run test against that db. Let me know if I was clear enough.

chaseWillden commented 1 month ago

Here we are spinning up the MySQL db service in the workflow which we should have integration tests to: https://github.com/njord-rs/njord/blob/master/.github/workflows/core.yml#L24

So you need to setup the docker container for MySQL with docker compose, and when running the docker compose up command, you need to configure a script to be run inside it to add the schema, populate the db (with a .SQL file) with dummy data and then run test against that db. Let me know if I was clear enough.

Ok sweet, in this case, this should be much easier to write. Ok I'll adjust that and get those out

chaseWillden commented 1 month ago

@mjovanc alright, I got some basic tests. I'm going to do a separate PR for all the commented out tests if that's cool with you.

mjovanc commented 1 month ago

Sounds good! Great job Chase! Thanks!