66 "fmt"
77 "testing"
88
9+ "github.com/monzo/terrors"
10+ "github.com/stretchr/testify/assert"
11+
912 "github.com/stretchr/testify/require"
1013)
1114
@@ -14,9 +17,9 @@ type http2H2cFlavour struct {
1417 client Service
1518}
1619
17- func (f http2H2cFlavour ) Serve (svc Service ) * Server {
20+ func (f http2H2cFlavour ) Serve (svc Service , opts ... ServerOption ) * Server {
1821 svc = svc .Filter (H2cFilter )
19- s , err := Listen (svc , "localhost:0" )
22+ s , err := Listen (svc , "localhost:0" , opts ... )
2023 require .NoError (f .T , err )
2124 return s
2225}
@@ -33,14 +36,19 @@ func (f http2H2cFlavour) Context() (context.Context, func()) {
3336 return context .WithCancel (context .Background ())
3437}
3538
39+ func (f http2H2cFlavour ) AssertConnectionResetError (t * testing.T , terr * terrors.Error ) {
40+ assert .Equal (t , terrors .ErrInternalService , terr .Code )
41+ assert .Contains (t , terr .Message , "INTERNAL_ERROR" )
42+ }
43+
3644type http2H2cPriorKnowledgeFlavour struct {
3745 T * testing.T
3846 client Service
3947}
4048
41- func (f http2H2cPriorKnowledgeFlavour ) Serve (svc Service ) * Server {
49+ func (f http2H2cPriorKnowledgeFlavour ) Serve (svc Service , opts ... ServerOption ) * Server {
4250 svc = svc .Filter (H2cFilter )
43- s , err := Listen (svc , "localhost:0" )
51+ s , err := Listen (svc , "localhost:0" , opts ... )
4452 require .NoError (f .T , err )
4553 return s
4654}
@@ -59,19 +67,24 @@ func (f http2H2cPriorKnowledgeFlavour) Context() (context.Context, func()) {
5967 return ctx , cancel
6068}
6169
70+ func (f http2H2cPriorKnowledgeFlavour ) AssertConnectionResetError (t * testing.T , terr * terrors.Error ) {
71+ assert .Equal (t , terrors .ErrInternalService , terr .Code )
72+ assert .Equal (t , "EOF" , terr .Message )
73+ }
74+
6275type http2H2Flavour struct {
6376 T * testing.T
6477 client Service
6578 cert tls.Certificate
6679}
6780
68- func (f http2H2Flavour ) Serve (svc Service ) * Server {
81+ func (f http2H2Flavour ) Serve (svc Service , opts ... ServerOption ) * Server {
6982 l , err := tls .Listen ("tcp" , "localhost:0" , & tls.Config {
7083 Certificates : []tls.Certificate {f .cert },
7184 ClientAuth : tls .NoClientCert ,
7285 NextProtos : []string {"h2" }})
7386 require .NoError (f .T , err )
74- s , err := Serve (svc , l )
87+ s , err := Serve (svc , l , opts ... )
7588 require .NoError (f .T , err )
7689 return s
7790}
@@ -87,3 +100,8 @@ func (f http2H2Flavour) Proto() string {
87100func (f http2H2Flavour ) Context () (context.Context , func ()) {
88101 return context .WithCancel (context .Background ())
89102}
103+
104+ func (f http2H2Flavour ) AssertConnectionResetError (t * testing.T , terr * terrors.Error ) {
105+ assert .Equal (t , terrors .ErrInternalService , terr .Code )
106+ assert .Contains (t , terr .Message , "INTERNAL_ERROR" )
107+ }
0 commit comments