-
Notifications
You must be signed in to change notification settings - Fork 3
/
mock_test.go
69 lines (56 loc) · 1.97 KB
/
mock_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
package quic
import (
"context"
"net"
quic "github.com/lucas-clemente/quic-go"
)
var ( // interface constraints
_ net.Addr = mockAddrNetloc("")
_ netlocator = mockAddrNetloc("")
_ quic.Listener = &mockLstn{}
_ quic.Session = &mockSess{}
)
type mockAddrNetloc string
func (mockAddrNetloc) Network() string { return "quic" }
func (m mockAddrNetloc) String() string { return string(m) }
func (m mockAddrNetloc) Netloc() string { return m.String() }
type mockLstn struct {
closed bool
sessFactory func() *mockSess
}
func (m mockLstn) Accept() (quic.Session, error) {
if m.sessFactory == nil {
return &mockSess{}, nil
}
return m.sessFactory(), nil
}
func (mockLstn) Addr() net.Addr { return mockAddrNetloc("") }
func (mockLstn) Listen() (quic.Listener, error) { return nil, nil }
func (m *mockLstn) Close() error {
m.closed = true
return nil
}
type mockSess struct {
closed bool
contextFactory func() context.Context
}
func (mockSess) AcceptStream() (quic.Stream, error) { return nil, nil }
func (m mockSess) Context() context.Context {
if m.contextFactory == nil {
return context.TODO()
}
return m.contextFactory()
}
func (mockSess) LocalAddr() net.Addr { return mockAddrNetloc("") }
func (mockSess) OpenStream() (quic.Stream, error) { return nil, nil }
func (mockSess) OpenStreamSync() (quic.Stream, error) { return nil, nil }
func (mockSess) RemoteAddr() net.Addr { return mockAddrNetloc("") }
func (mockSess) AcceptUniStream() (quic.ReceiveStream, error) { return nil, nil }
func (mockSess) OpenUniStream() (quic.SendStream, error) { return nil, nil }
func (mockSess) OpenUniStreamSync() (quic.SendStream, error) { return nil, nil }
func (mockSess) CloseWithError(quic.ErrorCode, error) error { return nil }
func (m *mockSess) Close() error {
m.closed = true
return nil
}
func (*mockSess) ConnectionState() quic.ConnectionState { return quic.ConnectionState{} }