Skip to content

Commit deae65b

Browse files
committed
update error message
1 parent 99d82ef commit deae65b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

x/mongo/driver/connstring/initial_dns_seedlist_discovery_prose_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,20 @@ func TestInitialDNSSeedlistDiscoveryProse(t *testing.T) {
8181
uri string
8282
labels int
8383
}{
84-
{"localhost", "mongodb+srv://localhost", 2},
85-
{"mongo.local", "mongodb+srv://mongo.local", 3},
84+
{"localhost", "mongodb+srv://localhost", 1},
85+
{"mongo.local", "mongodb+srv://mongo.local", 2},
8686
}
8787
for _, c := range cases {
8888
c := c
8989
t.Run(c.uri, func(t *testing.T) {
9090
t.Parallel()
9191

9292
_, err := newTestParser(c.record).parse(c.uri)
93-
assert.ErrorContains(t, err, fmt.Sprintf("DNS name must contain at least %d labels", c.labels))
93+
expected := fmt.Sprintf(
94+
"Server record (%d levels) should have more domain levels than parent URI (%d levels)",
95+
c.labels, c.labels,
96+
)
97+
assert.ErrorContains(t, err, expected)
9498
})
9599
}
96100
})

x/mongo/driver/dns/dns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func validateSRVResult(recordFromSRV, inputHostName string) error {
114114
separatedInputDomain := strings.Split(strings.ToLower(inputHostName), ".")
115115
separatedRecord := strings.Split(strings.ToLower(recordFromSRV), ".")
116116
if l := len(separatedInputDomain); l < 3 && len(separatedRecord) <= l {
117-
return fmt.Errorf("DNS name must contain at least %d labels", l+1)
117+
return fmt.Errorf("Server record (%d levels) should have more domain levels than parent URI (%d levels)", l, len(separatedRecord))
118118
}
119119
if len(separatedRecord) < len(separatedInputDomain) {
120120
return errors.New("Domain suffix from SRV record not matched input domain")

0 commit comments

Comments
 (0)