-
Notifications
You must be signed in to change notification settings - Fork 56
/
e2e_http2_test.go
107 lines (86 loc) · 2.64 KB
/
e2e_http2_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package typhon
import (
"context"
"crypto/tls"
"fmt"
"testing"
"github.com/monzo/terrors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type http2H2cFlavour struct {
T *testing.T
client Service
}
func (f http2H2cFlavour) Serve(svc Service, opts ...ServerOption) *Server {
svc = svc.Filter(H2cFilter)
s, err := Listen(svc, "localhost:0", opts...)
require.NoError(f.T, err)
return s
}
func (f http2H2cFlavour) URL(s *Server) string {
return fmt.Sprintf("http://%s", s.Listener().Addr())
}
func (f http2H2cFlavour) Proto() string {
return "HTTP/2.0"
}
func (f http2H2cFlavour) Context() (context.Context, func()) {
return context.WithCancel(context.Background())
}
func (f http2H2cFlavour) AssertConnectionResetError(t *testing.T, terr *terrors.Error) {
assert.Equal(t, terrors.ErrInternalService, terr.Code)
assert.Contains(t, terr.Message, "INTERNAL_ERROR")
}
type http2H2cPriorKnowledgeFlavour struct {
T *testing.T
client Service
}
func (f http2H2cPriorKnowledgeFlavour) Serve(svc Service, opts ...ServerOption) *Server {
svc = svc.Filter(H2cFilter)
s, err := Listen(svc, "localhost:0", opts...)
require.NoError(f.T, err)
return s
}
func (f http2H2cPriorKnowledgeFlavour) URL(s *Server) string {
return fmt.Sprintf("http://%s", s.Listener().Addr())
}
func (f http2H2cPriorKnowledgeFlavour) Proto() string {
return "HTTP/2.0"
}
func (f http2H2cPriorKnowledgeFlavour) Context() (context.Context, func()) {
ctx, cancel := context.WithCancel(context.Background())
ctx = WithH2C(ctx)
return ctx, cancel
}
func (f http2H2cPriorKnowledgeFlavour) AssertConnectionResetError(t *testing.T, terr *terrors.Error) {
assert.Equal(t, terrors.ErrInternalService, terr.Code)
assert.Equal(t, "EOF", terr.Message)
}
type http2H2Flavour struct {
T *testing.T
client Service
cert tls.Certificate
}
func (f http2H2Flavour) Serve(svc Service, opts ...ServerOption) *Server {
l, err := tls.Listen("tcp", "localhost:0", &tls.Config{
Certificates: []tls.Certificate{f.cert},
ClientAuth: tls.NoClientCert,
NextProtos: []string{"h2"}})
require.NoError(f.T, err)
s, err := Serve(svc, l, opts...)
require.NoError(f.T, err)
return s
}
func (f http2H2Flavour) URL(s *Server) string {
return fmt.Sprintf("https://%s", s.Listener().Addr())
}
func (f http2H2Flavour) Proto() string {
return "HTTP/2.0"
}
func (f http2H2Flavour) Context() (context.Context, func()) {
return context.WithCancel(context.Background())
}
func (f http2H2Flavour) AssertConnectionResetError(t *testing.T, terr *terrors.Error) {
assert.Equal(t, terrors.ErrInternalService, terr.Code)
assert.Contains(t, terr.Message, "INTERNAL_ERROR")
}