Skip to content

micrometer-observation-test support for assertions on events #5576

Closed

Description

@wabrit

Please describe the feature request.
The micrometer-observation-test dependency does not appear to offer a simple way of asserting on observation events in tests

Rationale
The TestObservationRegistryAssert class handles assertions on what observations have been made, the key values associated with an observation, etc. But it does not appear to provide support for asserting that particular calls to Observation#event(...) have been made.

This is necessary to provide test coverage for observations which raise events.

Additional context
This is based on using version 1.13.2 of io.micrometer:micrometer-observation-test

Activity

  1. added this to the 1.x milestone on Oct 11, 2024
  2. shakuzen commented on Oct 11, 2024

    @shakuzen
    Member

    @wabrit thanks for opening the issue. It sounds like a useful enhancement. Would you be interested in contributing a pull request for this?

  3. wabrit commented on Oct 11, 2024

    @wabrit
    ContributorAuthor

    Hi @shakuzen - I'd be happy to try, and I do have my own "workaround", but perhaps it would be a good idea to submit some kind of API design proposal first before a PR? Is here the right place to do that?

  4. shakuzen commented on Oct 11, 2024

    @shakuzen
    Member

    Sure, here is fine. Leave a comment with what you have in mind.

  5. wabrit commented on Oct 11, 2024

    @wabrit
    ContributorAuthor

    What I envisaged would be to extend the TestObservationRegistryAssert class (and supporting classes) to support this:

    TestObservationRegistryAssert.assertThat(observationRegistry)
            .hasObservationWithNameEqualTo("foo")
            .that()
            .hasEvent("event1") /* event with name event1 exists in observation */
            .doesNotHaveEvent("event2") /* no event with name event2 in observation */
            ....
  6. wabrit commented on Oct 21, 2024

    @wabrit
    ContributorAuthor

    Hi all - does the above proposal sound ok before I embark on a PR, and (not having committed to this project before) is there a guide to that process? (I assume I need to fork the repo and create a branch on the fork to submit the PR against)

  7. shakuzen commented on Oct 22, 2024

    @shakuzen
    Member

    Your proposal looks reasonable to me. As for contributing, check the contributing guide. Yes, forking the repo and committing the changes to a branch in that fork and submitting a pull request would be the right process.

  8. wabrit commented on Oct 24, 2024

    @wabrit
    ContributorAuthor

    PR raised: #5605

  9. removed
    help wantedAn issue that a contributor can help us with
    on Oct 25, 2024
  10. modified the milestones: 1.x, 1.15.0-M1 on Oct 25, 2024
  11. added a commit that references this issue on Nov 13, 2024
    6b238b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions