Skip to content

Add AssertionExtensions to work around upstream stability #900

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

Merged
merged 2 commits into from
Mar 24, 2025

Conversation

breedx-splk
Copy link
Contributor

Given this unfortunate situation with "stability" in the core assertions, let's come up with our own extension(s) for doing assertions. This starts with hasEventName() on the LogRecordDataAssert.

This PR also migrates the NetworkChangeMonitorTest to kotlin and mockk in order to demonstrate usage of the extension assert.

fun LogRecordDataAssert.hasEventName(eventName: String): LogRecordDataAssert {
isNotNull()
// TODO: This will be removed after the event bits of logs gets out of incubating.
assertThat(this.actual()).isInstanceOf(ExtendedLogRecordData::class.java)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is likely redundant since the method below will fail if this.actual() as ExtendedLogRecordData fails anyway

import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat

fun LogRecordDataAssert.hasEventName(eventName: String): LogRecordDataAssert {
isNotNull()
Copy link
Member

@marandaneto marandaneto Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is redundant since extension LogRecordDataAssert.hasEventName so LogRecordDataAssert is never null, you cant use this extension with log?.hasEventName

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure about this? The extension is on the LogRecordDataAssert (the assertion class, NOT the log record itself), and the method isNotNull() is on the assetj parent class AbstractAssert and it verifies that the actual result isn't null. I expect that the error message would be easier to read by checking explicitly here, so like assertThat(null).hasEventName("foo") would give a clearer message

Are we talking about the same thing here?

The isInstanceOf() also contains an internal isNotNull() check, but when the eventName comes out of incubating, then the instance checks go away and we will lose the specificity.

@breedx-splk
Copy link
Contributor Author

Given that there are two approvals, I'm going to merge in spite of the unresolved conversation. It's not a big deal to make changes after, but I would like to get the rebase of the following PR going. Thanks for the reviews!

@breedx-splk breedx-splk merged commit b8bfa1f into open-telemetry:main Mar 24, 2025
6 checks passed
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.

3 participants