Unit Testing using In-memory MongoDB, design question


I want to create a Unit Test case that uses the regular service methods but is backed by a database that can be created by code and ends ones the unit test is over (Mock or in-memory). The connection to a MongoDB, but ONLY WHILE testing I want it to be an in-memory mongoDB.

Note: One can drive configs by Viper (but this is optional), mentioning incase Viper can be used to aid i nthe design of what am asking.

Q1) Is there a PROFILE where while running in UNIT test GO recognizes and is able to work with alternate configs (Test Context). Design wise should this be invoked using a Context, Dependency Injection (DI) or a Viper command line configuration flag? Last is my least preferred way hoping for DI.

Q2) Is there any way GO can spin up an in memory MongoDB instance? Links or code appreciated as answer to this one.

Why In-Memory : Having used HyperSonic database was extremely useful to spin a DB for the life period of test code; put in test data and then have the code run on it. Am hoping to replicate that design cleanliness and not have to depend on actual infrastructure for unit tests (horrible)

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.