]> Cypherpunks.ru repositories - gostls13.git/commitdiff
log/syslog: report hostname mismatch error details
authorMichael Pratt <mpratt@google.com>
Wed, 12 Apr 2023 15:56:14 +0000 (11:56 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 12 Apr 2023 16:09:24 +0000 (16:09 +0000)
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>
src/log/syslog/syslog_test.go

index c7a5bfbd7bbed3c1a8fde4036bfa4c59bbf54ee4..cec225f75131f2cd0fe1e3fee1f783231eb95097 100644 (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) {