shanejansen / touchstone

Touchstone is a testing framework for your services that focuses on component, end-to-end, and exploratory testing.
17 stars 2 forks source link

Mongo collection defaults requirement #49

Open ScottFreeCode opened 2 years ago

ScottFreeCode commented 2 years ago

My thinking on MongoDB mocks is that, since it's a database, it should largely parallel MySQL (except where the difference between the two is relevant, if there are any).

MySQL does not require anything in the defaults file (beyond the existence of a particular DB for the service to connect to), as the actual tables created by the service can be used by Touchstone on the fly without Touchstone needing to set anything up before their use.

This can be contrasted with, say, in Rabbit the messages are consumed or lost unless Touchstone creates shadow queues ahead of time, hence Touchstone must know about routing in the defaults file.

In Mongo I believe MySQL could be paralleled: services can automatically create their databases and collections, it is possible to query them on the fly without needing information about them in the defaults file.

(Touchstone already parallels MySQL with wiping the entire Mongo DB, not just what's in the defaults, thereby ensuring no state carries over between tests and it must be explicitly set in defaults or per-test mocks setup calls, as is best practice for testing in general. See also #47 )

ScottFreeCode commented 2 years ago

While not required by Touchstone, and while I don't know if any services require it as with MySQL in https://github.com/shanejansen/touchstone/issues/46#issuecomment-1050841435 , it may make sense to create the DBs from the defaults file without applying any of the collections/content, in case any service expects the DBs to already be available? See also #47 and #46 re. ideal order of creating things, adding data, service applying things versus Touchstone applying things…

ScottFreeCode commented 2 years ago

I think this also goes for mocks.mongodb.setup() in the individual tests as it could create missing collections on the fly. I am not sure off the top of my head if it supports that right now.