vors / ZLocation

ZLocation is the new Jump-Location
MIT License
564 stars 29 forks source link

Database mocking not working #88

Open theaquamarine opened 5 years ago

theaquamarine commented 5 years ago

The Pester setup for mocking Get-ZLocationDatabaseFilePath and Get-ZLocationLegacyBackupFilePath doesn't work: the mocked functions are never actually called and tests run using my actual database.

The easiest way to confirm this is lock the production database and run the tests- if they were using the testing database, this wouldn't be an issue, but instead database operations fail. Other tests such as checking mocks are actually called suggest the same thing.

theaquamarine commented 4 years ago

The issue is the $collection.EnsureIndex('path') which is run against the database every time ZLocation.Service is imported https://github.com/vors/ZLocation/blob/67638c11eaae0bbfc7b3f7eda476d9751a659442/ZLocation/ZLocation.Service.psm1#L113-L115

93 has a fix of sorts in that EnsureIndex() will not be run against a database file that already exists, so the only contact between tests and a user's real database should be a Test-Path. https://github.com/vors/ZLocation/blob/c2dfe2c9ed689378c5cefdcec7f40e95b6dc5784/ZLocation/ZLocation.Service.psm1#L135-L139