Closed atoulme closed 2 years ago
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
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.
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.
Enhancement: create an interface for Hub.
Fixes #271
changelog.md
Environment