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

use *Server interfaces in implementations of fake*Server #167

Closed
Capstan opened this issue Jul 5, 2019 · 1 comment · Fixed by #168
Closed

use *Server interfaces in implementations of fake*Server #167

Capstan opened this issue Jul 5, 2019 · 1 comment · Fixed by #168
Labels
bug Something isn't working

Comments

@Capstan
Copy link
Contributor

Capstan commented Jul 5, 2019

In equivalence_test.go, there's a fake implementation of MetricService. It implements exactly the methods of that service as of now. Thus, if new methods are introduced (or in the case of the mono-repo, there are additional internal-only methods), this causes a compilation break, even if those methods are never exercised.

The protocol compiler will produce an UnimplementedMetricServiceServer which provides dummy methods that return NYI errors. If this is used as a field of the fake, e.g.,

type fakeMetricsServer struct {
  monitoringpb.UnimplementedMetricServiceServer
  …

then if methods are introduced, the fake will still compile and the new methods will just return errors. In this particular case, all the methods unused by the test could just be removed, since it will still fulfill the interface.

@Capstan Capstan added the bug Something isn't working label Jul 5, 2019
Capstan added a commit to Capstan/opencensus-go-exporter-stackdriver that referenced this issue Jul 5, 2019
@Capstan
Copy link
Contributor Author

Capstan commented Jul 5, 2019

Appears that this isn't rendered as a part of genproto, so perhaps use of just the raw MetricServiceServer interface would do. It won't nicely error, but just panic if a nil method is called.

@Capstan Capstan changed the title use Unimplemented*Server interfaces in implementations of fake*Server use *Server interfaces in implementations of fake*Server Jul 5, 2019
Capstan added a commit to Capstan/opencensus-go-exporter-stackdriver that referenced this issue Jul 5, 2019
Capstan added a commit to Capstan/opencensus-go-exporter-stackdriver that referenced this issue Jul 5, 2019
songy23 pushed a commit that referenced this issue Jul 16, 2019
* Use MetricServiceServer in fakeMetricService.

Fixes #167.

* Remove uncalled fake methods and type assertion.

Given that the fakeMetricService includes the MetricServiceServer interface, it necessarily implements the interface, even if some of the methods are nil and would panic if called. Uncalled methods are removed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant