Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create a Hub interface #272

Closed
wants to merge 1 commit into from
Closed

Conversation

atoulme
Copy link

@atoulme atoulme commented Aug 13, 2022

Enhancement: create an interface for Hub.

Fixes #271

  • All tests passed
  • Add change to changelog.md

Environment

  • OS: Mac OS
  • Go version: 1.19

@ghost
Copy link

ghost commented Aug 13, 2022

CLA assistant check
All CLA requirements met.

@atoulme atoulme force-pushed the hub_interface branch 4 times, most recently from 68502e6 to 828a0c8 Compare August 13, 2022 20:50
@richardpark-msft
Copy link
Member

In general, we try not to export types if possible since they become part of our public contract.

In my tests I usually create an interface in my own code to represent 3rd party libraries. It sounds like you're not able to do this, but I'm curious if you could help me get your use case a bit more.

So, for instance, I'd define this interface in my own code (ie, not in eventhubs):
https://github.com/Azure/azure-event-hubs-go/pull/272/files#diff-953fe0899f69d47c633cae4a70be7c2838ecc0098165d06066e295f6d019d6e6R60

And then here:
https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/12795/files#diff-81400d54e06c8ca9e9898e2be70ab7318917716a47612dd658b5933191a44abfR44

I'd create a function that takes that interface, and pass the result of the constructor function to it.

Closing this for now, but please feel free to reopen/reply.

@atoulme
Copy link
Author

atoulme commented Sep 24, 2022

The Hub struct implements Receive(ctx context.Context, partitionID string, handler eventhub.Handler, opts ...eventhub.ReceiveOption) (*eventhub.ListenerHandle, error), which returns a ListenerHandle struct which is a struct I cannot mock. ListenerHandle has unexported fields, so I cannot set ctx orr in it.
When I try to bind to the lifecycle of the handle, I get a panic since ctx is not set:

// Done will close the channel when the listener has stopped
func (lc *ListenerHandle) Done() <-chan struct{} {
	return lc.ctx.Done()
}

Not sure how to address this, except by building a complete wrapper around your implementation and expanding quite some time doing so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for mock hub
2 participants