grpc_mock 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/grpc_mock.rb +2 -2
- data/lib/grpc_mock/{configure.rb → configuration.rb} +1 -1
- data/lib/grpc_mock/grpc_stub_adapter.rb +37 -48
- data/lib/grpc_mock/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a3a30164b826b389b7ab94f98d006695d0fbbe0
|
4
|
+
data.tar.gz: 52a58e8da81742811f8fc9f63e6f1b4eed6e5ed9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 054c34b5b45030d9671da3bb41952f77105f43f6554dbe4ab0a3812d90fa578c58e172020290ff3b5be07907cec4906abbcad4f3af14a5478f585d0db2d1df33
|
7
|
+
data.tar.gz: f733ca899fc9319e175cd953c9117c063a1759844f39faabfea697f2ba2eb39202cdd0c4f3cff327d06704c0e6a2ac2368a9b19f8a78b457c64b78ff2601fdc3
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# GrpcMock
|
1
|
+
# GrpcMock [![Build Status](https://travis-ci.org/ganmacs/grpc_mock.svg?branch=master)](https://travis-ci.org/ganmacs/grpc_mock)
|
2
2
|
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/grpc_mock`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
data/lib/grpc_mock.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'grpc_mock/version'
|
2
|
-
require 'grpc_mock/
|
2
|
+
require 'grpc_mock/configuration'
|
3
3
|
require 'grpc_mock/adapter'
|
4
4
|
|
5
5
|
module GrpcMock
|
@@ -25,7 +25,7 @@ module GrpcMock
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def config
|
28
|
-
@config ||=
|
28
|
+
@config ||= Configuration.new
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -3,89 +3,78 @@ require 'grpc_mock/errors'
|
|
3
3
|
|
4
4
|
module GrpcMock
|
5
5
|
class GrpcStubAdapter
|
6
|
-
# To make hook point for
|
6
|
+
# To make hook point for GRPC::ClientStub
|
7
7
|
# https://github.com/grpc/grpc/blob/bec3b5ada2c5e5d782dff0b7b5018df646b65cb0/src/ruby/lib/grpc/generic/service.rb#L150-L186
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
GRPC.send(:remove_const, :ClientStub)
|
15
|
-
GRPC.send(:const_set, :ClientStub, ADAPTER_CLASS)
|
8
|
+
class AdapterClass < GRPC::ClientStub
|
9
|
+
def request_response(method, *args)
|
10
|
+
unless GrpcMock::GrpcStubAdapter.enabled?
|
11
|
+
return super
|
12
|
+
end
|
16
13
|
|
17
|
-
HOOKED_CLASS = Module.new do
|
18
|
-
def request_response(method, req, marshal, unmarshal, **opt)
|
19
14
|
if GrpcMock.config.allow_net_connect
|
20
|
-
|
15
|
+
super
|
21
16
|
else
|
22
17
|
raise NetConnectNotAllowedError, method
|
23
18
|
end
|
24
19
|
end
|
25
20
|
|
26
|
-
def client_streamer(method,
|
21
|
+
def client_streamer(method, *args)
|
22
|
+
unless GrpcMock::GrpcStubAdapter.enabled?
|
23
|
+
return super
|
24
|
+
end
|
25
|
+
|
27
26
|
if GrpcMock.config.allow_net_connect
|
28
|
-
|
27
|
+
super
|
29
28
|
else
|
30
29
|
raise NetConnectNotAllowedError, method
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
|
-
def server_streamer(method,
|
33
|
+
def server_streamer(method, *args)
|
34
|
+
unless GrpcMock::GrpcStubAdapter.enabled?
|
35
|
+
return super
|
36
|
+
end
|
37
|
+
|
35
38
|
if GrpcMock.config.allow_net_connect
|
36
|
-
|
39
|
+
super
|
37
40
|
else
|
38
41
|
raise NetConnectNotAllowedError, method
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
42
|
-
def bidi_streamer(method,
|
45
|
+
def bidi_streamer(method, *args)
|
46
|
+
unless GrpcMock::GrpcStubAdapter.enabled?
|
47
|
+
return super
|
48
|
+
end
|
49
|
+
|
43
50
|
if GrpcMock.config.allow_net_connect
|
44
|
-
|
51
|
+
super
|
45
52
|
else
|
46
53
|
raise NetConnectNotAllowedError, method
|
47
54
|
end
|
48
55
|
end
|
49
56
|
end
|
57
|
+
GRPC.send(:remove_const, :ClientStub)
|
58
|
+
GRPC.send(:const_set, :ClientStub, AdapterClass)
|
50
59
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
original_request_response(method, req, marshal, unmarshal, **opt)
|
55
|
-
end
|
56
|
-
|
57
|
-
def client_streamer(method, requests, marshal, unmarshal, **opt)
|
58
|
-
original_client_streamer(method, requests, marshal, unmarshal, **opt)
|
59
|
-
end
|
60
|
+
def self.disable!
|
61
|
+
@enabled = false
|
62
|
+
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
+
def self.enable!
|
65
|
+
@enabled = true
|
66
|
+
end
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
+
def self.enabled?
|
69
|
+
@enabled
|
68
70
|
end
|
69
71
|
|
70
72
|
def enable!
|
71
|
-
|
72
|
-
ADAPTER_CLASS.prepend(HOOKED_CLASS)
|
73
|
+
GrpcMock::GrpcStubAdapter.enable!
|
73
74
|
end
|
74
75
|
|
75
76
|
def disable!
|
76
|
-
|
77
|
-
ADAPTER_CLASS.prepend(THROUGHT_CLASS)
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def clean_up
|
83
|
-
ADAPTER_CLASS.class_eval do
|
84
|
-
undef_method(:request_response)
|
85
|
-
undef_method(:client_streamer)
|
86
|
-
undef_method(:server_streamer)
|
87
|
-
undef_method(:bidi_streamer)
|
88
|
-
end
|
77
|
+
GrpcMock::GrpcStubAdapter.disable!
|
89
78
|
end
|
90
79
|
end
|
91
80
|
end
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ganmacs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -129,7 +129,7 @@ files:
|
|
129
129
|
- grpc_mock.gemspec
|
130
130
|
- lib/grpc_mock.rb
|
131
131
|
- lib/grpc_mock/adapter.rb
|
132
|
-
- lib/grpc_mock/
|
132
|
+
- lib/grpc_mock/configuration.rb
|
133
133
|
- lib/grpc_mock/errors.rb
|
134
134
|
- lib/grpc_mock/grpc_stub_adapter.rb
|
135
135
|
- lib/grpc_mock/rspec.rb
|