shanejansen / touchstone

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

MongoDB mock only clears listed collections #27

Closed ScottFreeCode closed 2 years ago

ScottFreeCode commented 3 years ago

The MongoDB mock will not clear the collections created by the service if they are not included in the defaults file.

It should clear any collections that the service created that are left out of the mock specification:

shanejansen commented 3 years ago

I think this is possible but could be difficult to implement depending on the mock. Currently, mocks are reset using the values in their defaults file. So MySql will not delete databases outside its scope. Same for Rabbit queues and exchanges. I'd have to review Rabbit APIs to see if it's possible to get all queues + exchanges that exist in the instance. When designing TS, I made the assumption that services wouldn't be creating collections/databases/exchanges/queues outside the scope of the defaults file

ScottFreeCode commented 3 years ago

I guess the difference is I see collections as more like tables? (Since they're the subsets within the database that actually contain the records.)

With either mock I expect to name the DB as a whole in the defaults file (it's used in the connection string of my app, I am not absolutely certain about Mongo but I know for MySQL the app can't get to work on that DB unless it at least exists), then either:

(Rabbit is the odd one out as Touchstone has to be told which routing keys to listen on and publish to but I can otherwise let the app set the exchanges and queues up. In fact, in Rabbit this doesn't matter so much because messages either are consumed, or are in queues known by Touchstone, or are unneeded: old messages not known to Touchstone can't cause unexpected state the way old DB records can.)

shanejansen commented 3 years ago

That's a good point. I suppose it makes more sense to drop every collection in the db. I'll go ahead and add this to the 1.4 release