From ebc13fb0b83341a444f55cf226f786fdc9782018 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Wed, 12 Apr 2023 11:56:14 -0400 Subject: [PATCH] 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 Auto-Submit: Michael Pratt TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- src/log/syslog/syslog_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/log/syslog/syslog_test.go b/src/log/syslog/syslog_test.go index c7a5bfbd7b..cec225f751 100644 --- a/src/log/syslog/syslog_test.go +++ b/src/log/syslog/syslog_test.go @@ -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, ×tamp, &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) { -- 2.48.1