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

Fixed Lookup() bug #174

Merged
merged 1 commit into from
Jun 19, 2023
Merged

Fixed Lookup() bug #174

merged 1 commit into from
Jun 19, 2023

Conversation

thrawn01
Copy link
Contributor

Purpose

In situations where a recipient domain resolved with 2 MX hosts of the same priority only one host would be returned from Lookup()

Implementation

  • ShuffleMXRecords() would not consider the final entry in a list of MX records if there were only 2 entries. This change correctly identifies when the loop is on the last MX record.

if len(mxHosts) == 0 {
return cacheAndReturn(hostname, nil, nil, false, errNoValidMXHosts)
}
return cacheAndReturn(hostname, mxHosts, mxRecords, false, nil)
}

func shuffleMXRecords(mxRecords []*net.MX) []string {
func ShuffleMXRecords(mxRecords []*net.MX) []string {
Copy link
Member

Choose a reason for hiding this comment

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

Why did you make it a public function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I don't like writing tests for private methods. 😮‍💨 But in this case, I don't wanna do the correct thing and embed a DNS server we can query to retrieve proper MX records for testing. Instead we use publicly hosted MX records which don't have the specific regression configuration I wanted to target. So I made the method public and added tests for it.

I understand your position on this so I reverted and made the method private. 👍

@thrawn01 thrawn01 merged commit ccaeadc into master Jun 19, 2023
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.

5 participants