🚚 Moved http testing util to testing/httptest package

This commit is contained in:
Maxim Lebedev 2021-12-28 06:00:04 +05:00
parent 23d658e902
commit 76eeab15be
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
4 changed files with 15 additions and 21 deletions

1
internal/testing/httptest/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pem

View File

@ -1,5 +1,5 @@
//go:generate go run "$GOROOT/src/crypto/tls/generate_cert.go" --host 127.0.0.1,::1,localhost --start-date "Jan 1 00:00:00 1970" --duration=1000000h --ca --rsa-bits 1024 --ecdsa-curve P256
package util
package httptest
import (
"crypto/tls"
@ -12,7 +12,6 @@ import (
httputil "github.com/valyala/fasthttp/fasthttputil"
)
//nolint: gochecknoglobals
var (
//go:embed cert.pem
certData []byte
@ -20,9 +19,9 @@ var (
keyData []byte
)
// TestServe returns the InMemory HTTP-server and the client connected to it
// with the specified handler.
func TestServe(tb testing.TB, handler http.RequestHandler) (*http.Client, *http.Server, func()) {
// New returns the InMemory Server and the Client connected to it with the
// specified handler.
func New(tb testing.TB, handler http.RequestHandler) (*http.Client, *http.Server, func()) {
tb.Helper()
//nolint: exhaustivestruct
@ -53,3 +52,13 @@ func TestServe(tb testing.TB, handler http.RequestHandler) (*http.Client, *http.
server.Shutdown()
}
}
// NewRequest returns a new incoming server Request and cleanup function.
func NewRequest(method, target string, body []byte) *http.Request {
req := http.AcquireRequest()
req.Header.SetMethod(method)
req.SetRequestURI(target)
req.SetBody(body)
return req
}

View File

@ -1,11 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIBqzCCAVGgAwIBAgIQf/XioLO++M9gcgIEzC1mrjAKBggqhkjOPQQDAjASMRAw
DgYDVQQKEwdBY21lIENvMCAXDTcwMDEwMTAwMDAwMFoYDzIwODQwMTI5MTYwMDAw
WjASMRAwDgYDVQQKEwdBY21lIENvMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE
kJnGbMm+QmPdvGFSFKxydVf0A+eKUesaoKa3rJ7ypHKxdizgA6uYumpopHaojf7i
4ms3AJmtLZvFvVDnYTz1yKOBhjCBgzAOBgNVHQ8BAf8EBAMCAoQwEwYDVR0lBAww
CgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUpEj1X34Xtjrm
F/4SrqwZcPbo7cMwLAYDVR0RBCUwI4IJbG9jYWxob3N0hwR/AAABhxAAAAAAAAAA
AAAAAAAAAAABMAoGCCqGSM49BAMCA0gAMEUCIQCoffjdhPWP+jdZQZvdUBLXSmQQ
hbvCvbqE+zCAEnFdGQIgA0JE3HVWJqI0OOiDMNYUF0d5Hz9tTSozkQcmVKQQZJA=
-----END CERTIFICATE-----

View File

@ -1,5 +0,0 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgrZ6k0Iipuq5JLos6
Y6uPFJLbywvTULzPt1x9EG8SWJ6hRANCAASQmcZsyb5CY928YVIUrHJ1V/QD54pR
6xqgpresnvKkcrF2LOADq5i6amikdqiN/uLiazcAma0tm8W9UOdhPPXI
-----END PRIVATE KEY-----