dbrgn / tracing-test

Access and evaluate tracing logs in async and sync tests.
Apache License 2.0
62 stars 27 forks source link

Add a log count function #7

Closed joshuef closed 2 years ago

joshuef commented 3 years ago

Hey @dbrgn !

I've used the main crate ina couple of repos, so first thanks for that!

I'm not sure if this would be wanted? But I hope so, as it's useful to us ot ensure certain events are happening the correct number of times. (msgs received eg).

Let me know if you want any changes or more tests eg, and I'll get on it asap.

Cheers!

joshuef commented 3 years ago

Maybe a function like this could be provided?

Hmm, interesting. Aye, I'll have a poke at your suggestion + general feedback the coming week. 🙇

joshuef commented 3 years ago

Okay, so as per the suggestion, I've updated the PR with a more general logs_run function, which can take a function and will just pass it the logs so we can do what we want with it.

Also rebased on master and addressed the other comments (as made sense w/ the changes).

Seems to work well enough, and is definitely more flexible. It's not taking a closure though as the compiler was giving me grief about that... It may be possible to get it going, but I'm not sure how myself. Any tips there or other suggestions welcome!

threema-danilo commented 2 years ago

It's not taking a closure though as the compiler was giving me grief about that... It may be possible to get it going, but I'm not sure how myself.

It was easier to do this myself than to explain it, so I pushed a commit to your branch. What do you think about that approach, @joshuef?

The logs_assert function is different than logs_contain because the latter returns a boolean (which you need to include in an assertion of your own) while the former panics directly if the passed in function returns an error. However, with the function naming, I think that's the best and most ergonomic approach.

dbrgn commented 2 years ago

I added some docs, this should be good to merge now. Thanks @joshuef for getting this started!