Skip to content

Commit

Permalink
tests: handle new x509 certificate error structure in go1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Feb 2, 2023
1 parent 1a77eb8 commit af78f8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 7 additions & 2 deletions command/agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ func TestHTTP_VerifyHTTPSClient(t *testing.T) {
CertFile: foocert,
KeyFile: fookey,
}
c.LogLevel = "off"
})
defer s.Shutdown()

Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions command/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit af78f8b

Please sign in to comment.