-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
how to create table use go-sqlmock #219
Comments
sqlmock is used for testing purposes, not for in memory db. you can still implement your functional tests very efficiently by using sqlite (if you just use SQL standard queries) or by using https://github.com/DATA-DOG/go-txdb which would wrap your mysql or other SQL database within a transaction, reverting transaction is instant and so your tests would be fast without any need to change your actual code. Sqlmock is not validating sql statements and does not have an in memory query processing engine. SQL databases are different, they have different query engines and in some cases sql syntax additions. Sqlmock will never even try to implement an SQL query engine. Additionally, every database handles indexes or primary key generation differently, default ordering of records created and so on. It would be insane to even try to do such a thing. |
@l3pp4rd
But I'm testing for failed insert when inserting row with duplicate unique |
As I said, sqlmock is meant for unit testing certain functions or blocks of logic. It would not be wise to use it for functional tests and try to test the logic in the database you use, because it cannot replicate a database it can only mock one for an unit test. It would be much wiser to use a real database to functionally test your code. Especially the internal database behavior, such as duplicate key failures. If you mock the database, how you can think that your test is testing anything at all what is happening in db, such as duplicate unique key or any other constraints or locks or ordering behavior. Sqlmock only helps to test you the correct program flow in certain conditions which you simulate. But it will not give you functional behavior tests |
I understand now. Thank you. |
is it possible to create a mysql database in memory use go-sqlmock?
just like https://github.com/alicebob/miniredis which creates a redis server in your own computer's memory with golang.
if so, we can use the mocked mysql instead of the real mysql server, i think it will be the ultimate solution for mysql mock in golang.
The text was updated successfully, but these errors were encountered: