Skip to content
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

Make FQDN lookup function more testable #158

Merged
merged 6 commits into from
Mar 27, 2023

Conversation

ycombinator
Copy link
Contributor

This PR refactors the shared.FQDN() function, extracting the lookup algorithm into a helper function, to make the code a bit more testable. Having done that, the PR also adds a unit test for the helper function.

@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 27, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-03-27T22:42:51.338+0000

  • Duration: 10 min 28 sec

Test stats 🧪

Test Results
Failed 0
Passed 280
Skipped 4
Total 284

}{
"long_real_hostname": {
osHostname: "elastic.co",
expectedFQDN: "elastic.co",
Copy link
Member

Choose a reason for hiding this comment

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

Will temporary DNS errors cause this test to fail even if the logic is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it will. Just tested it with my Internet connection turned off.

I'm hoping such network/DNS unavailability errors are extremely rare, though. Perhaps we could add a comment here and remove this test case if it starts proving to be flaky?

Copy link
Member

Choose a reason for hiding this comment

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

I think a comment is a good idea, it won't necessarily be obvious that this requires an internet connection without context.

I'm fine waiting and seeing if this turns out to be flaky. Anyone testing this code will need to hit the real code path anyway so mocking it out doesn't necessarily help.

@ycombinator
Copy link
Contributor Author

The tests added in this PR are failing in CI with a slightly different error (as returned by shared.fqdn()) than on my development machine. So I'm going to relax the error assertions in the test slightly to make the tests less sensitive to the environment they're running in.

@ycombinator
Copy link
Contributor Author

/test

@ycombinator ycombinator merged commit aeb677b into elastic:main Mar 27, 2023
@ycombinator ycombinator deleted the fqdn-testable branch March 27, 2023 23:03
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