Skip to content

Message's private PhantomData<T> makes it difficult to unit test my code #367

@chamons

Description

@chamons

I would like to do something like this in my application code:

pub struct FetchedMessage {
    pub message: Message<MessagePayload>,
    pub is_priority: bool,
}

#[async_trait]
impl PulsarConnection for TestPulsarConnection {
    async fn fetch(&self) -> Result<Option<FetchedMessage>, pulsar::Error> {}
    async fn ack(&self, message: FetchedMessage) -> Result<(), ConsumerError> {
        panic!()
    }
    async fn nack(&self, message: FetchedMessage) -> Result<(), ConsumerError> {
        panic!();
    }
    async fn shutdown(&self, worker_shutdown: impl Future<Output = ()> + Send) {}
}

In my tests, so I could stub out all of the pulsar connection code from my unit tests and test some rare cases.

However, I can not do this because this is the type returned by the pulsar consumer APIs:

https://github.com/streamnative/pulsar-rs/blob/master/src/consumer/message.rs#L9-L20

There is no way to construct it, as it both:

  • Does not have a public construction function
  • Contains a field that is not public (_phantom)

Could we possible relax one of these two constraints so I can write my tests?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions