1
0
mirror of https://github.com/golang/go synced 2024-11-26 17:56:55 -07:00

log/syslog: report hostname mismatch error details

The existing error log in check doesn't report the got/want hostname
even though that can be the cause of the error. Log those as well.

While we're here, also report os.Hostname() errors.

For #59568.

Change-Id: Ia277f85eddc541f2e78d719bc731db24e4513754
Reviewed-on: https://go-review.googlesource.com/c/go/+/483915
Run-TryBot: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
Michael Pratt 2023-04-12 11:56:14 -04:00 committed by Gopher Robot
parent d91d832530
commit ebc13fb0b8

View File

@ -270,7 +270,7 @@ func TestDial(t *testing.T) {
func check(t *testing.T, in, out, transport string) {
hostname, err := os.Hostname()
if err != nil {
t.Error("Error retrieving hostname")
t.Errorf("Error retrieving hostname: %v", err)
return
}
@ -290,9 +290,12 @@ func check(t *testing.T, in, out, transport string) {
var pid int
tmpl := fmt.Sprintf("<%d>%%s %%s syslog_test[%%d]: %s\n", LOG_USER+LOG_INFO, in)
n, err := fmt.Sscanf(out, tmpl, &timestamp, &parsedHostname, &pid)
if n != 3 || err != nil || hostname != parsedHostname {
if n != 3 || err != nil {
t.Errorf("Got %q, does not match template %q (%d %s)", out, tmpl, n, err)
}
if hostname != parsedHostname {
t.Errorf("Hostname got %q want %q in %q", parsedHostname, hostname, out)
}
}
func TestWrite(t *testing.T) {