ardanlabs / service

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

remove seed database #366

Closed himynamej closed 1 month ago

himynamej commented 1 month ago

do you think this change is good ,do we need seed database? i want to do this in my project because its so complicated and must have different user base of every scenario

ardan-bkennedy commented 1 month ago

The idea is to skip the seed. Not a bad idea. Do the test pass?

ardan-bkennedy commented 1 month ago

I don't think you can remove the seeding because that adds an admin user to the database. This is needed to run tests. You don't know what order tests may run in. You might want to just run a home test. That is why the seeding adds two initial users to the system.

I am not sure you have tried running just a CreateProduct test, which won't work without users in the system.

ardan-bkennedy commented 1 month ago

Granted, we don't need to query the seeded users in the app layer tests, but they are there and it can affect results. That is why I query them. You can create as many users as you want, and fix your tests to use that user.

ardan-bkennedy commented 1 month ago

My last statement was wrong. You can create the user using the business layer API. The question is, should we use the seeded users since they exist, or always create a new user?

himynamej commented 1 month ago

seed may cause confusion in writing tests

ardan-bkennedy commented 1 month ago

I made changes to the repo based on your PR. I removed the seeding of the db during a test and removed those query calls. Let me know what you think.

himynamej commented 1 month ago

its so good,thanks

ardan-bkennedy commented 1 month ago

Thanks for the PR