grpc_mock 0.4.4 → 0.4.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb0de4a6e730f8e575b50ecfa9ee0d92b97dd3380900dc119de0a41abc285457
4
- data.tar.gz: 912662c5b9ed4398a8377d9207621208f3bcfdf201eff0a4e4cd7ec95e152600
3
+ metadata.gz: b2061779fc0f48faecd97933713277ba734d97c7d1581b0aee12899f54c1ec0c
4
+ data.tar.gz: 78ef2ecb1199bb9e0dedddcfb2aa32ac6d3af6afedd8055396600174d008e17a
5
5
  SHA512:
6
- metadata.gz: f78e70b411a828142b828ca7348e27b25dbd76a86af5fa8886146fd0459f427598f132c092af084848e90a9b5c35dd921f5b77408b5a94850e8ea4fc6b760e79
7
- data.tar.gz: 2cabdde68d88771fca38020d2f5b6cd5cf2ec7462ada062a84139252aeda8103f811486bbdb2e1dc4dbaaaa8c9f134e7880525f7dbfbe1a4672c67a1379190a3
6
+ metadata.gz: d50395ad65d30b8284628ed6a26d1234c99767a4bc8bee47452ae8c018a6e43aadcbf08cc9a04d130c92f3c5c749be53260c823b1238ae2977aca0f135869f8c
7
+ data.tar.gz: 6d93f5de445f48b68128b4c0d4f01f287289fb2f63e882de12e2446500c7fe00682a6af858033e0aa3e531173b1dccae8b59527d2357a8950c8b5eba99ec0cfb
@@ -0,0 +1,25 @@
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.5'
16
+ - '2.6'
17
+ - '2.7'
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ bundler-cache: true
24
+
25
+ - run: 'bundle exec rake'
@@ -9,7 +9,7 @@ module GrpcMock
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
11
  module Adapter
12
- def request_response(method, request, *args, metadata: {}, **kwargs)
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
- mock.evaluate(request, call.single_req_view)
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
- mock.evaluate(r, call.multi_req_view)
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,15 +59,22 @@ 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
50
66
 
51
67
  mock = GrpcMock.stub_registry.response_for_request(method, request)
52
68
  if mock
53
- call = GrpcMock::MockedCall.new(metadata: metadata)
54
- mock.evaluate(request, call.single_req_view)
69
+ if return_op
70
+ operation = call.operation
71
+ operation.define_singleton_method(:execute) do
72
+ mock.evaluate(request, call.single_req_view)
73
+ end
74
+ operation
75
+ else
76
+ mock.evaluate(request, call.single_req_view)
77
+ end
55
78
  elsif GrpcMock.config.allow_net_connect
56
79
  super
57
80
  else
@@ -59,7 +82,7 @@ module GrpcMock
59
82
  end
60
83
  end
61
84
 
62
- def bidi_streamer(method, requests, *args, metadata: {}, **kwargs)
85
+ def bidi_streamer(method, requests, *args, metadata: {}, return_op: false, **kwargs)
63
86
  unless GrpcMock::GrpcStubAdapter.enabled?
64
87
  return super
65
88
  end
@@ -67,7 +90,15 @@ module GrpcMock
67
90
  r = requests.to_a # FIXME: this may not work
68
91
  mock = GrpcMock.stub_registry.response_for_request(method, r)
69
92
  if mock
70
- mock.evaluate(r, nil) # FIXME: provide BidiCall equivalent
93
+ if return_op
94
+ operation = call.operation
95
+ operation.define_singleton_method(:execute) do
96
+ mock.evaluate(r, nil) # FIXME: provide BidiCall equivalent
97
+ end
98
+ operation
99
+ else
100
+ mock.evaluate(r, nil) # FIXME: provide BidiCall equivalent
101
+ end
71
102
  elsif GrpcMock.config.allow_net_connect
72
103
  super
73
104
  else
@@ -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)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GrpcMock
4
+ MockedOperation = Struct.new(:call, :metadata, :deadline)
5
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrpcMock
4
- VERSION = '0.4.4'
4
+ VERSION = '0.4.5'
5
5
  end
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
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuta Iwama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-29 00:00:00.000000000 Z
11
+ date: 2021-11-04 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
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.6.3
5
- - 2.5.3
6
- - 2.4.5
7
- before_install: gem install bundler -v 1.16.1