Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Document why a user should choose the source or reflect mode #406

Open
13rac1 opened this issue Feb 26, 2020 · 6 comments
Open

Document why a user should choose the source or reflect mode #406

13rac1 opened this issue Feb 26, 2020 · 6 comments

Comments

@13rac1
Copy link

13rac1 commented Feb 26, 2020

Requested feature

Document why a user should choose the source or reflect mode.

Why the feature is needed

The README states:

mockgen has two modes of operation: source and reflect.
Source mode generates mock interfaces from a source file.
Reflect mode generates mock interfaces by building a program that uses reflection to understand interfaces.

The CLI help states:

mockgen has two modes of operation: source and reflect.

Source mode generates mock interfaces from a source file.
It is enabled by using the -source flag. Other flags that
may be useful in this mode are -imports and -aux_files.
Example:
mockgen -source=foo.go [other options]

Reflect mode generates mock interfaces by building a program
that uses reflection to understand interfaces. It is enabled
by passing two non-flag arguments: an import path, and a
comma-separated list of symbols.

Neither explains which mode a user should choose. Is one faster than the other? Is one more reliable? Are they the same? If so, why do both exist?

This is a follow up issue as requested in #36 (comment)

@codyoss
Copy link
Member

codyoss commented Feb 27, 2020

Thanks for opening this issue, I agree this is something that should be addressed. I would like to leave this issue open a bit to collect user experiences. I know there are some edge cases out there that force people into one or the other, and honestly I don't know them all. If you have specific cases you have found please share!

Also, I would like to know these difference so that in the future we can blur the lines and the cli just works. I would love to deprecate the need for some of the flags too eventually. Thanks for the report.

@codyoss
Copy link
Member

codyoss commented Feb 28, 2020

One difference is how type aliases are handled, works correct in source mode: #244

@codyoss
Copy link
Member

codyoss commented Feb 28, 2020

mocking unexported interfaces requires source mode: #297

@linzhp
Copy link
Contributor

linzhp commented Mar 27, 2020

At Uber, we call mockgen from bazel_gomock, this is what we found besides what @codyoss said above:

@kishaningithub
Copy link
Contributor

We use source mode for interfaces in our repository and reflect mode for interfaces in dependencies.

@Tatskaari
Copy link

We've migrated from src to reflection in Please for a couple of reasons:

  1. Source mode seemed to have a hard time understanding our code structure. We don't set a go path or use modules, we use -importcfg to tell go tool compile etc. where to find packages. I'm not convinced this should be a problem though... ideally mockgen could just parse the srcs without needing to understand how imports work.
  2. Reflect mode worked better when mocking gRPC interfaces because we can specify which interfaces to mock. Mocking everything lead to some obtuse failures for some internal interface in the gRPC generated code.

Olshansk added a commit to pokt-network/pocket that referenced this issue May 17, 2023
## Description

Fix the mockgen build tags across the board

## Issue

![Screenshot 2023-05-16 at 4 51 23 PM](https://github.com/pokt-network/pocket/assets/1892194/b22c3e73-c9fb-4a72-a9b9-531df7506044)

## Type of change

Please mark the relevant option(s):

- [ ] New feature, functionality or library
- [x] Bug fix
- [x] Code health or cleanup
- [ ] Major breaking change
- [ ] Documentation
- [ ] Other <!-- add details here if it a different type of change -->

## List of changes

- Using `source mode` instead of `reflect mode` across all mocked interfaces for consistency and verbosity; more detailed [here](golang/mock#406)
- Fixed a few copy-pasta path-related issues (interface names and mock destinations)
- Fixed Makefile targets related to mock cleanups

## Testing

- [x] `make develop_test`; if any code changes were made
- [ ] `make test_e2e` on [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any code changes were made
- [ ] `e2e-devnet-test` passes tests on [DevNet](https://pocketnetwork.notion.site/How-to-DevNet-ff1598f27efe44c09f34e2aa0051f0dd); if any code was changed
- [ ] [Docker Compose LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md); if any major functionality was changed or introduced
- [ ] [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any infrastructure or configuration changes were made

## Required Checklist

- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added, or updated, [`godoc` format comments](https://go.dev/blog/godoc) on touched members (see: [tip.golang.org/doc/comment](https://tip.golang.org/doc/comment))
- [ ] I have tested my changes using the available tooling
- [ ] I have updated the corresponding CHANGELOG

### If Applicable Checklist

- [ ] I have updated the corresponding README(s); local and/or global
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s)
- [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants