-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
grpc_channel_server_mock.go
66 lines (53 loc) · 2.2 KB
/
grpc_channel_server_mock.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
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation and Dapr Contributors.
// Licensed under the MIT License.
// ------------------------------------------------------------
package testing
import (
context "context"
"encoding/json"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/emptypb"
commonv1pb "github.com/dapr/dapr/pkg/proto/common/v1"
runtimev1pb "github.com/dapr/dapr/pkg/proto/runtime/v1"
)
// MockServer implementation of fake user app server.
type MockServer struct {
Error error
Subscriptions []*runtimev1pb.TopicSubscription
Bindings []string
BindingEventResponse runtimev1pb.BindingEventResponse
TopicEventResponseStatus runtimev1pb.TopicEventResponse_TopicEventResponseStatus
}
func (m *MockServer) OnInvoke(ctx context.Context, in *commonv1pb.InvokeRequest) (*commonv1pb.InvokeResponse, error) {
md, _ := metadata.FromIncomingContext(ctx)
dt := map[string]string{
"method": in.Method,
}
for k, v := range md {
dt[k] = v[0]
}
dt["httpverb"] = in.HttpExtension.GetVerb().String()
dt["querystring"] = in.HttpExtension.Querystring
ds, _ := json.Marshal(dt)
return &commonv1pb.InvokeResponse{Data: &anypb.Any{Value: ds}, ContentType: "application/json"}, m.Error
}
func (m *MockServer) ListTopicSubscriptions(ctx context.Context, in *emptypb.Empty) (*runtimev1pb.ListTopicSubscriptionsResponse, error) {
return &runtimev1pb.ListTopicSubscriptionsResponse{
Subscriptions: m.Subscriptions,
}, m.Error
}
func (m *MockServer) ListInputBindings(ctx context.Context, in *emptypb.Empty) (*runtimev1pb.ListInputBindingsResponse, error) {
return &runtimev1pb.ListInputBindingsResponse{
Bindings: m.Bindings,
}, m.Error
}
func (m *MockServer) OnBindingEvent(ctx context.Context, in *runtimev1pb.BindingEventRequest) (*runtimev1pb.BindingEventResponse, error) {
return &m.BindingEventResponse, m.Error
}
func (m *MockServer) OnTopicEvent(ctx context.Context, in *runtimev1pb.TopicEventRequest) (*runtimev1pb.TopicEventResponse, error) {
return &runtimev1pb.TopicEventResponse{
Status: m.TopicEventResponseStatus,
}, m.Error
}