-
Notifications
You must be signed in to change notification settings - Fork 57
/
e2e_http1_test.go
72 lines (57 loc) · 1.68 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package typhon
import (
"context"
"crypto/tls"
"fmt"
"testing"
"github.com/monzo/terrors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type http1Flavour struct {
T *testing.T
}
func (f http1Flavour) Serve(svc Service, opts ...ServerOption) *Server {
s, err := Listen(svc, "localhost:0", opts...)
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"
}
func (f http1Flavour) Context() (context.Context, func()) {
return context.WithCancel(context.Background())
}
func (f http1Flavour) AssertConnectionResetError(t *testing.T, terr *terrors.Error) {
assert.Equal(t, terrors.ErrInternalService, terr.Code)
assert.Equal(t, "EOF", terr.Message)
}
type http1TLSFlavour struct {
T *testing.T
cert tls.Certificate
}
func (f http1TLSFlavour) Serve(svc Service, opts ...ServerOption) *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, opts...)
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"
}
func (f http1TLSFlavour) Context() (context.Context, func()) {
return context.WithCancel(context.Background())
}
func (f http1TLSFlavour) AssertConnectionResetError(t *testing.T, terr *terrors.Error) {
assert.Equal(t, terrors.ErrInternalService, terr.Code)
assert.Equal(t, "local error: tls: bad record MAC", terr.Message)
}