grpc_mock 0.4.3 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +26 -0
- data/README.md +1 -1
- data/lib/grpc_mock/grpc_stub_adapter.rb +47 -11
- data/lib/grpc_mock/mocked_call.rb +5 -0
- data/lib/grpc_mock/mocked_operation.rb +5 -0
- data/lib/grpc_mock/version.rb +1 -1
- metadata +8 -7
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 923aaec305faa3a4f0a093ec6eb4fed078177ed24ec159fbc8682ccff0cd41b6
|
4
|
+
data.tar.gz: 78f0e359f956ee325815460def53092eee7915aab443a11211fd1d72835371e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7112127ba8e8d8b139fcff5810ef8d84bf5fe3e57cc445bb662f5a31811814f66ccc485a5f28b79770f61e428914a587baf86026c15461a3fe56cb546b993ef
|
7
|
+
data.tar.gz: 93ef179f2f8eb0abc3210f5029aaf04e847ac8c8bcd643e4cab9d458a97f5989b745f2446ae292f2dec887a06d0cc3eeefeba9973b49a3f4f160a0fba0f8218b
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request: {}
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version:
|
15
|
+
- '2.7'
|
16
|
+
- '3.0'
|
17
|
+
- '3.1'
|
18
|
+
- '3.2'
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true
|
25
|
+
|
26
|
+
- run: 'bundle exec rake'
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ require 'grpc_mock/rspec'
|
|
28
28
|
|
29
29
|
## Examples
|
30
30
|
|
31
|
-
See definition of protocol buffers and gRPC generated code in [spec/
|
31
|
+
See definition of protocol buffers and gRPC generated code in [spec/examples/hello](https://github.com/ganmacs/grpc_mock/tree/master/spec/examples/hello)
|
32
32
|
|
33
33
|
### Stubbed request based on path and with the default response
|
34
34
|
|
@@ -8,8 +8,8 @@ module GrpcMock
|
|
8
8
|
class GrpcStubAdapter
|
9
9
|
# To make hook point for GRPC::ClientStub
|
10
10
|
# https://github.com/grpc/grpc/blob/bec3b5ada2c5e5d782dff0b7b5018df646b65cb0/src/ruby/lib/grpc/generic/service.rb#L150-L186
|
11
|
-
|
12
|
-
def request_response(method, request, *args, metadata: {}, **kwargs)
|
11
|
+
module Adapter
|
12
|
+
def request_response(method, request, *args, metadata: {}, return_op: false, **kwargs)
|
13
13
|
unless GrpcMock::GrpcStubAdapter.enabled?
|
14
14
|
return super
|
15
15
|
end
|
@@ -17,7 +17,15 @@ module GrpcMock
|
|
17
17
|
mock = GrpcMock.stub_registry.response_for_request(method, request)
|
18
18
|
if mock
|
19
19
|
call = GrpcMock::MockedCall.new(metadata: metadata)
|
20
|
-
|
20
|
+
if return_op
|
21
|
+
operation = call.operation
|
22
|
+
operation.define_singleton_method(:execute) do
|
23
|
+
mock.evaluate(request, call.single_req_view)
|
24
|
+
end
|
25
|
+
operation
|
26
|
+
else
|
27
|
+
mock.evaluate(request, call.single_req_view)
|
28
|
+
end
|
21
29
|
elsif GrpcMock.config.allow_net_connect
|
22
30
|
super
|
23
31
|
else
|
@@ -26,7 +34,7 @@ module GrpcMock
|
|
26
34
|
end
|
27
35
|
|
28
36
|
# TODO
|
29
|
-
def client_streamer(method, requests, *args, metadata: {}, **kwargs)
|
37
|
+
def client_streamer(method, requests, *args, metadata: {}, return_op: false, **kwargs)
|
30
38
|
unless GrpcMock::GrpcStubAdapter.enabled?
|
31
39
|
return super
|
32
40
|
end
|
@@ -35,7 +43,15 @@ module GrpcMock
|
|
35
43
|
mock = GrpcMock.stub_registry.response_for_request(method, r)
|
36
44
|
if mock
|
37
45
|
call = GrpcMock::MockedCall.new(metadata: metadata)
|
38
|
-
|
46
|
+
if return_op
|
47
|
+
operation = call.operation
|
48
|
+
operation.define_singleton_method(:execute) do
|
49
|
+
mock.evaluate(r, call.multi_req_view)
|
50
|
+
end
|
51
|
+
operation
|
52
|
+
else
|
53
|
+
mock.evaluate(r, call.multi_req_view)
|
54
|
+
end
|
39
55
|
elsif GrpcMock.config.allow_net_connect
|
40
56
|
super
|
41
57
|
else
|
@@ -43,7 +59,7 @@ module GrpcMock
|
|
43
59
|
end
|
44
60
|
end
|
45
61
|
|
46
|
-
def server_streamer(method, request, *args, metadata: {}, **kwargs)
|
62
|
+
def server_streamer(method, request, *args, metadata: {}, return_op: false, **kwargs)
|
47
63
|
unless GrpcMock::GrpcStubAdapter.enabled?
|
48
64
|
return super
|
49
65
|
end
|
@@ -51,7 +67,15 @@ module GrpcMock
|
|
51
67
|
mock = GrpcMock.stub_registry.response_for_request(method, request)
|
52
68
|
if mock
|
53
69
|
call = GrpcMock::MockedCall.new(metadata: metadata)
|
54
|
-
|
70
|
+
if return_op
|
71
|
+
operation = call.operation
|
72
|
+
operation.define_singleton_method(:execute) do
|
73
|
+
mock.evaluate(request, call.single_req_view)
|
74
|
+
end
|
75
|
+
operation
|
76
|
+
else
|
77
|
+
mock.evaluate(request, call.single_req_view)
|
78
|
+
end
|
55
79
|
elsif GrpcMock.config.allow_net_connect
|
56
80
|
super
|
57
81
|
else
|
@@ -59,7 +83,7 @@ module GrpcMock
|
|
59
83
|
end
|
60
84
|
end
|
61
85
|
|
62
|
-
def bidi_streamer(method, requests, *args, metadata: {}, **kwargs)
|
86
|
+
def bidi_streamer(method, requests, *args, metadata: {}, return_op: false, **kwargs)
|
63
87
|
unless GrpcMock::GrpcStubAdapter.enabled?
|
64
88
|
return super
|
65
89
|
end
|
@@ -67,7 +91,15 @@ module GrpcMock
|
|
67
91
|
r = requests.to_a # FIXME: this may not work
|
68
92
|
mock = GrpcMock.stub_registry.response_for_request(method, r)
|
69
93
|
if mock
|
70
|
-
|
94
|
+
if return_op
|
95
|
+
operation = call.operation
|
96
|
+
operation.define_singleton_method(:execute) do
|
97
|
+
mock.evaluate(r, nil) # FIXME: provide BidiCall equivalent
|
98
|
+
end
|
99
|
+
operation
|
100
|
+
else
|
101
|
+
mock.evaluate(r, nil) # FIXME: provide BidiCall equivalent
|
102
|
+
end
|
71
103
|
elsif GrpcMock.config.allow_net_connect
|
72
104
|
super
|
73
105
|
else
|
@@ -75,8 +107,6 @@ module GrpcMock
|
|
75
107
|
end
|
76
108
|
end
|
77
109
|
end
|
78
|
-
GRPC.send(:remove_const, :ClientStub)
|
79
|
-
GRPC.send(:const_set, :ClientStub, AdapterClass)
|
80
110
|
|
81
111
|
def self.disable!
|
82
112
|
@enabled = false
|
@@ -99,3 +129,9 @@ module GrpcMock
|
|
99
129
|
end
|
100
130
|
end
|
101
131
|
end
|
132
|
+
|
133
|
+
module GRPC
|
134
|
+
class ClientStub
|
135
|
+
prepend GrpcMock::GrpcStubAdapter::Adapter
|
136
|
+
end
|
137
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'grpc'
|
4
|
+
require 'grpc_mock/mocked_operation'
|
4
5
|
|
5
6
|
module GrpcMock
|
6
7
|
class MockedCall
|
@@ -19,6 +20,10 @@ module GrpcMock
|
|
19
20
|
GRPC::ActiveCall::SingleReqView.new(self)
|
20
21
|
end
|
21
22
|
|
23
|
+
def operation
|
24
|
+
GrpcMock::MockedOperation.new(self, metadata, deadline)
|
25
|
+
end
|
26
|
+
|
22
27
|
private
|
23
28
|
|
24
29
|
def sanitize_metadata(metadata)
|
data/lib/grpc_mock/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grpc_mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuta Iwama
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -121,10 +121,10 @@ executables: []
|
|
121
121
|
extensions: []
|
122
122
|
extra_rdoc_files: []
|
123
123
|
files:
|
124
|
+
- ".github/workflows/ci.yml"
|
124
125
|
- ".gitignore"
|
125
126
|
- ".rspec"
|
126
127
|
- ".rubocop.yml"
|
127
|
-
- ".travis.yml"
|
128
128
|
- Gemfile
|
129
129
|
- LICENSE.txt
|
130
130
|
- README.md
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/grpc_mock/matchers/hash_argument_matcher.rb
|
142
142
|
- lib/grpc_mock/matchers/request_including_matcher.rb
|
143
143
|
- lib/grpc_mock/mocked_call.rb
|
144
|
+
- lib/grpc_mock/mocked_operation.rb
|
144
145
|
- lib/grpc_mock/request_pattern.rb
|
145
146
|
- lib/grpc_mock/request_stub.rb
|
146
147
|
- lib/grpc_mock/response.rb
|
@@ -152,7 +153,7 @@ homepage: https://github.com/ganmacs/grpc_mock
|
|
152
153
|
licenses:
|
153
154
|
- MIT
|
154
155
|
metadata: {}
|
155
|
-
post_install_message:
|
156
|
+
post_install_message:
|
156
157
|
rdoc_options: []
|
157
158
|
require_paths:
|
158
159
|
- lib
|
@@ -167,8 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
168
|
- !ruby/object:Gem::Version
|
168
169
|
version: '0'
|
169
170
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
171
|
-
signing_key:
|
171
|
+
rubygems_version: 3.3.7
|
172
|
+
signing_key:
|
172
173
|
specification_version: 4
|
173
174
|
summary: Library for stubbing grpc in Ruby
|
174
175
|
test_files: []
|