ardanlabs / service

Starter-kit for writing services in Go using Kubernetes.
https://www.ardanlabs.com
Apache License 2.0
3.43k stars 619 forks source link

Tests #384

Closed himynamej closed 1 month ago

himynamej commented 1 month ago

What do you think about using testcontainer for run database in docker https://testcontainers.com/

And can we just write each test in there own package ? For example run user test in user package . We can do something about run one instance of database for test.

ardan-bkennedy commented 1 month ago

I don't want to add any new tech to the project.

If you want to move the tests from being a business unit to a package unit test you need to change the Docker package and live with the idea you can't terminate the test database after you run tests.

This isn't necessarily a bad thing. Encore works this way. They start a database just for tests. If it's already running great. If not, it is started.

I've been torn doing this with service. I believe a test should clean up after itself when it can. We can in this project.

So think about the tests in the project as being business unit and api unit tests. The packages being tested are not, nor will they ever, live in their own module or be accessed outside the project.

There are no rules that say you can't have a unit at a layer level.

himynamej commented 1 month ago

Thank you ,I just Mentally respect the tests to be in there package ,it's not necessary but when the tests increase can be helpful and testcontainer clean up containers after test.I can't choose so I follow the easiest way, which is the way you said

ardan-bkennedy commented 1 month ago

I'll play with the idea of keeping a single test database and see how it works.

ardan-bkennedy commented 1 month ago

I made the change. The code now uses a single docker image for all tests. You will need to use make test-down to stop the image. I will do that in the circle ci.

himynamej commented 1 month ago

Thank you .I saw it that's so great 👍