paurkedal / ocaml-caqti

Cooperative-threaded access to relational data
https://paurkedal.github.io/ocaml-caqti/index.html
GNU Lesser General Public License v3.0
299 stars 36 forks source link

Testing without db #111

Closed Tozarin closed 9 months ago

Tozarin commented 9 months ago

I want to test my application without physical connection to db. Does caqti have any tools for this?

If this is not supported, are there any ways to do this? By mocking CONNECTION module or something else?

paurkedal commented 9 months ago

It depends what you mean physical connection. Can you use sqlite3::memory: or maybe even disk-backed sqlite3 since it still does not need a network connection? There is a related discussion in #52.

Tozarin commented 9 months ago

Thanks for answer!

I mean to mock CONNECTION module in code to perform queries without any interactions with db, without passing any db files to code. Use something like this: give me that -> returns user defined data, give it again -> return same data. To testing some application logic that call CONNECTION functions, but not use real db entity.

I think that sqlite3::memory: could help me, but using dummy db entity seems like uh. If it is common way of testing, then ok.

paurkedal commented 9 months ago

Isn't it limited what you can test without something behaving like a database? What should e.g. a find call of a mock connection return? Note that it must return exactly one row according to the API, or an error.

Tozarin commented 9 months ago

If mock object behaves exactly like db, then it doesn't seem to be limitation. But you are right, this forces to simulate exactly db in order to match API. So, probably, yes, it is easier to use sqlite3::memory: and not worry.

Thank you for your time.