backend/remote-state/http: tests support go1.21 (#391)

This commit is contained in:
Lars Lehtonen 2023-09-18 01:01:28 -07:00 committed by GitHub
parent 072d1dce56
commit 9724c4d748
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,10 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"io"
"net"
"net/http"
"net/http/httptest"
"os"
@ -281,11 +284,20 @@ func TestMTLSServer_NoCertFails(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error fetching StateMgr with %s: %v", backend.DefaultStateName, err)
}
opErr := new(net.OpError)
err = sm.RefreshState()
if nil == err {
t.Error("expected error when refreshing state without a client cert")
} else if !strings.Contains(err.Error(), "remote error: tls: bad certificate") {
t.Errorf("expected the error to report missing tls credentials: %v", err)
if err == nil {
t.Fatal("expected error when refreshing state without a client cert")
}
if errors.As(err, &opErr) {
errType := fmt.Sprintf("%T", opErr.Err)
expected := "tls.alert"
if errType != expected {
t.Fatalf("expected net.OpError.Err type: %q got: %q error:%s", expected, errType, err)
}
} else {
t.Fatalf("unexpected error: %v", err)
}
}