Skip to content

Commit

Permalink
update error message
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Jan 10, 2025
1 parent 99d82ef commit deae65b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,20 @@ func TestInitialDNSSeedlistDiscoveryProse(t *testing.T) {
uri string
labels int
}{
{"localhost", "mongodb+srv://localhost", 2},
{"mongo.local", "mongodb+srv://mongo.local", 3},
{"localhost", "mongodb+srv://localhost", 1},
{"mongo.local", "mongodb+srv://mongo.local", 2},
}
for _, c := range cases {
c := c
t.Run(c.uri, func(t *testing.T) {
t.Parallel()

_, err := newTestParser(c.record).parse(c.uri)
assert.ErrorContains(t, err, fmt.Sprintf("DNS name must contain at least %d labels", c.labels))
expected := fmt.Sprintf(
"Server record (%d levels) should have more domain levels than parent URI (%d levels)",
c.labels, c.labels,
)
assert.ErrorContains(t, err, expected)
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion x/mongo/driver/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func validateSRVResult(recordFromSRV, inputHostName string) error {
separatedInputDomain := strings.Split(strings.ToLower(inputHostName), ".")
separatedRecord := strings.Split(strings.ToLower(recordFromSRV), ".")
if l := len(separatedInputDomain); l < 3 && len(separatedRecord) <= l {
return fmt.Errorf("DNS name must contain at least %d labels", l+1)
return fmt.Errorf("Server record (%d levels) should have more domain levels than parent URI (%d levels)", l, len(separatedRecord))
}
if len(separatedRecord) < len(separatedInputDomain) {
return errors.New("Domain suffix from SRV record not matched input domain")
Expand Down

0 comments on commit deae65b

Please sign in to comment.