test: allow specifying HTTP protocol (#822)

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
This commit is contained in:
罗泽轩
2024-02-20 11:29:05 +08:00
committed by GitHub
parent ae20420179
commit f277d4f6ae
5 changed files with 200 additions and 4 deletions

View File

@@ -88,6 +88,7 @@ const (
// values can be provided, as a comma-separated value.
type Request struct {
Host string
Protocol string
Method string
Path string
Headers map[string]string
@@ -162,12 +163,10 @@ func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripp
var (
scheme = "http"
protocol = "HTTP"
tlsConfig *roundtripper.TLSConfig
)
if expected.Request.ActualRequest.TLSConfig != nil {
scheme = "https"
protocol = "HTTPS"
clientKeyPairs := make([]roundtripper.ClientKeyPair, 0, len(expected.Request.ActualRequest.TLSConfig.Certificates.ClientKeyPairs))
for _, keyPair := range expected.Request.ActualRequest.TLSConfig.Certificates.ClientKeyPairs {
clientKeyPairs = append(clientKeyPairs, roundtripper.ClientKeyPair{
@@ -213,6 +212,11 @@ func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripp
path, query, _ := strings.Cut(expected.Request.ActualRequest.Path, "?")
protocol := "HTTP/1.1"
if expected.Request.ActualRequest.Protocol != "" {
protocol = expected.Request.ActualRequest.Protocol
}
req := roundtripper.Request{
Method: expected.Request.ActualRequest.Method,
Host: expected.Request.ActualRequest.Host,