Skip to content

RFC database: mocks as a field on RepoStore

Warren Gifford requested to merge k/mock-repo-store into main

Created by: keegancsmith

This is a mergeable idea/pattern. Posting as pull request to gather feedback.

This is a step towards removing global mocks. In a test instead of mocking the global "database.Mocks.Repos.List", you will pass in a "RepoStore" with "rs.Mock.List" set.

I quite like this pattern, since it avoids interfaces but gives you the benefit of mocking. As we move to passing around RepoStore more it will start to bare fruit (right now we seem to pass around db a lot, instead of the stores).

My preference of mocking this way is if a service uses a RepoStore, it can directly store a "*RepoStore" in its struct rather than an interface. This allows static analysis tools (find references, rename, etc) to continue to function.

To see an example of it being used, see this PR https://github.com/sourcegraph/sourcegraph/pull/19173

Merge request reports

Loading