Some services require lots of dependencies and this means that every consumer (worker, api, etc) has to inject that. Many times, we have leaky abstraction by allowing some dependencies to be optional, and it's overall fragile if we continue to do this.
We have several patterns in addition to passing nil, including Noop implementation structs, and more.
Create a wrapper over firestore so that we can create a mock for tests
Some services require lots of dependencies and this means that every consumer (worker, api, etc) has to inject that. Many times, we have leaky abstraction by allowing some dependencies to be optional, and it's overall fragile if we continue to do this.
We have several patterns in addition to passing nil, including Noop implementation structs, and more.
- [x] Create a wrapper over firestore so that we can create a mock for tests
Completed with the following idiomatic go patterns:
Caller defines a narrow interface, and external package implements it. Caller injected with a struct, and type safety ensures that the struct satisfies the interface.
Mocks are co-located by the interface definition. Other packages can utilize the mock for tests.
Split packages into multiple external services / interfaces (e.g. NetworkReader vs. NetworkService), because the reader requires minimal dependencies, which is nice for the majority of consumers.
Use //go:generate directive in the interface to create mocks.
Introduce an abstraction for firestore: livestore. Currently contains MembershipPublisher which is only useful to NetworkService, however can be expanded into more functionality. Allows unit tests to mock the livestore interface because firestore doesn't have interfaces to mock.
Completed with the following idiomatic go patterns:
- Caller defines a narrow interface, and external package implements it. Caller injected with a struct, and type safety ensures that the struct satisfies the interface.
- Mocks are co-located by the interface definition. Other packages can utilize the mock for tests.
- Split packages into multiple external services / interfaces (e.g. NetworkReader vs. NetworkService), because the reader requires minimal dependencies, which is nice for the majority of consumers.
- Use //go:generate directive in the interface to create mocks.
- Introduce an abstraction for firestore: livestore. Currently contains MembershipPublisher which is only useful to NetworkService, however can be expanded into more functionality. Allows unit tests to mock the livestore interface because firestore doesn't have interfaces to mock.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Some services require lots of dependencies and this means that every consumer (worker, api, etc) has to inject that. Many times, we have leaky abstraction by allowing some dependencies to be optional, and it's overall fragile if we continue to do this.
We have several patterns in addition to passing nil, including Noop implementation structs, and more.
Completed with the following idiomatic go patterns: