forked from monzo/typhon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e_http1_test.go
50 lines (40 loc) · 960 Bytes
/
e2e_http1_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package typhon
import (
"crypto/tls"
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
type http1Flavour struct {
T *testing.T
}
func (f http1Flavour) Serve(svc Service) *Server {
s, err := Listen(svc, "localhost:0")
require.NoError(f.T, err)
return s
}
func (f http1Flavour) URL(s *Server) string {
return fmt.Sprintf("http://%s", s.Listener().Addr())
}
func (f http1Flavour) Proto() string {
return "HTTP/1.1"
}
type http1TLSFlavour struct {
T *testing.T
cert tls.Certificate
}
func (f http1TLSFlavour) Serve(svc Service) *Server {
l, err := tls.Listen("tcp", "localhost:0", &tls.Config{
Certificates: []tls.Certificate{f.cert},
ClientAuth: tls.NoClientCert})
require.NoError(f.T, err)
s, err := Serve(svc, l)
require.NoError(f.T, err)
return s
}
func (f http1TLSFlavour) URL(s *Server) string {
return fmt.Sprintf("https://%s", s.Listener().Addr())
}
func (f http1TLSFlavour) Proto() string {
return "HTTP/1.1"
}