From af78f8b3494f244a088d43b36db9b899d9691bea Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Thu, 2 Feb 2023 12:06:54 -0600 Subject: [PATCH] tests: handle new x509 certificate error structure in go1.20 --- command/agent/http_test.go | 9 +++++++-- command/metrics_test.go | 14 +++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/command/agent/http_test.go b/command/agent/http_test.go index 05fe2929b26..6c7b61221af 100644 --- a/command/agent/http_test.go +++ b/command/agent/http_test.go @@ -743,6 +743,7 @@ func TestHTTP_VerifyHTTPSClient(t *testing.T) { CertFile: foocert, KeyFile: fookey, } + c.LogLevel = "off" }) defer s.Shutdown() @@ -758,7 +759,9 @@ func TestHTTP_VerifyHTTPSClient(t *testing.T) { if !ok { t.Fatalf("expected a *url.Error but received: %T -> %v", err, err) } - hostErr, ok := urlErr.Err.(x509.HostnameError) + + cveErr := (urlErr.Err.(*tls.CertificateVerificationError)).Err + hostErr, ok := cveErr.(x509.HostnameError) if !ok { t.Fatalf("expected a x509.HostnameError but received: %T -> %v", urlErr.Err, urlErr.Err) } @@ -786,7 +789,9 @@ func TestHTTP_VerifyHTTPSClient(t *testing.T) { if !ok { t.Fatalf("expected a *url.Error but received: %T -> %v", err, err) } - _, ok = urlErr.Err.(x509.UnknownAuthorityError) + + cveErr = (urlErr.Err.(*tls.CertificateVerificationError)).Err + _, ok = cveErr.(x509.UnknownAuthorityError) if !ok { t.Fatalf("expected a x509.UnknownAuthorityError but received: %T -> %v", urlErr.Err, urlErr.Err) } diff --git a/command/metrics_test.go b/command/metrics_test.go index 4412f1e5014..f899fa3e730 100644 --- a/command/metrics_test.go +++ b/command/metrics_test.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/nomad/ci" "github.com/mitchellh/cli" - "github.com/stretchr/testify/require" + "github.com/shoenig/test/must" ) var _ cli.Command = &OperatorMetricsCommand{} @@ -73,19 +73,19 @@ func TestCommand_Metrics_Cases(t *testing.T) { []string{"-address=http://foo"}, 1, "", - "dial tcp: lookup foo: Temporary failure in name resolution", + "dial tcp: lookup foo", // dns resolution error messages changes with Go, OS version }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { code := cmd.Run(c.args) - out := ui.OutputWriter.String() - outerr := ui.ErrorWriter.String() + stdOut := ui.OutputWriter.String() + stdErr := ui.ErrorWriter.String() - require.Equalf(t, code, c.expectedCode, "expected exit code %d, got: %d: %s", c.expectedCode, code, outerr) - require.Contains(t, out, c.expectedOutput, "expected output \"%s\", got \"%s\"", c.expectedOutput, out) - require.Containsf(t, outerr, c.expectedError, "expected error \"%s\", got \"%s\"", c.expectedError, outerr) + must.Eq(t, code, c.expectedCode, must.Sprintf("expected exit code %d, got: %d: %s", c.expectedCode, code, stdErr)) + must.StrContains(t, stdOut, c.expectedOutput) + must.StrContains(t, stdErr, c.expectedError) ui.OutputWriter.Reset() ui.ErrorWriter.Reset()