-
Notifications
You must be signed in to change notification settings - Fork 13
/
mockstream.go
83 lines (65 loc) · 1.52 KB
/
mockstream.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
package watchmanager
import (
"context"
"google.golang.org/grpc/metadata"
"github.com/Axway/agent-sdk/pkg/watchmanager/proto"
"google.golang.org/grpc"
)
type mockWatchClient struct {
stream *mockStream
err error
}
func (m mockWatchClient) Subscribe(_ context.Context, _ ...grpc.CallOption) (proto.Watch_SubscribeClient, error) {
return m.stream, m.err
}
type mockConn struct {
stream *mockStream
}
func (m mockConn) Invoke(_ context.Context, _ string, _ interface{}, _ interface{}, _ ...grpc.CallOption) error {
return nil
}
func (m mockConn) NewStream(
_ context.Context,
_ *grpc.StreamDesc,
_ string,
_ ...grpc.CallOption,
) (grpc.ClientStream, error) {
return m.stream, nil
}
type mockStream struct {
event *proto.Event
err error
context context.Context
}
func (m mockStream) Send(_ *proto.Request) error {
return m.err
}
func (m mockStream) Recv() (*proto.Event, error) {
return m.event, m.err
}
func (m mockStream) Header() (metadata.MD, error) {
return metadata.MD{}, nil
}
func (m mockStream) Trailer() metadata.MD {
return metadata.MD{}
}
func (m mockStream) CloseSend() error {
return nil
}
func (m mockStream) Context() context.Context {
return m.context
}
func (m mockStream) SendMsg(_ interface{}) error {
return nil
}
func (m mockStream) RecvMsg(_ interface{}) error {
return nil
}
func newMockWatchClient(stream *mockStream, err error) newWatchClientFunc {
return func(_ grpc.ClientConnInterface) proto.WatchClient {
return &mockWatchClient{
stream: stream,
err: err,
}
}
}