tonic-rails 0.2.0-aarch64-linux-gnu → 0.4.0-aarch64-linux-gnu

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.
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/expectations"
4
+ require "tonic/rails/testing"
5
+ require "tonic/rails/testing/errors"
6
+
7
+ # Matches a block that ends with a gRPC status, raised as a
8
+ # Tonic::Rails::RpcError (Testing.call) or a GRPC::BadStatus (the official
9
+ # client):
10
+ #
11
+ # expect { Tonic::Rails::Testing.call(ItemService, :GetItem, { id: 0 }) }
12
+ # .to raise_grpc_error(:not_found)
13
+ # expect { stub.get_item(request) }.to raise_grpc_error(:invalid_argument).with_message(/name/)
14
+ # expect { ... }.to raise_grpc_error # any non-OK status
15
+ RSpec::Matchers.define :raise_grpc_error do |expected_code = nil|
16
+ errors = Tonic::Rails::Testing::Errors
17
+
18
+ supports_block_expectations
19
+
20
+ chain(:with_message) { |message| @expected_message = message }
21
+
22
+ match do |block|
23
+ @expected = expected_code && Tonic::Rails::RpcError.normalize_code(expected_code)
24
+ begin
25
+ block.call
26
+ @error = nil
27
+ rescue Exception => e # rubocop:disable Lint/RescueException
28
+ raise unless errors.status?(e)
29
+
30
+ @error = e
31
+ end
32
+ return false unless @error
33
+
34
+ (@expected.nil? || errors.code(@error) == @expected) &&
35
+ (!defined?(@expected_message) || errors.message_matches?(@expected_message, errors.message(@error)))
36
+ end
37
+
38
+ description do
39
+ text = +"raise a gRPC error"
40
+ text << " #{errors.code_name(@expected).to_s.upcase}" if @expected
41
+ text << " with message #{@expected_message.inspect}" if defined?(@expected_message)
42
+ text
43
+ end
44
+
45
+ failure_message do
46
+ actual = @error ? "got #{errors.describe(@error)}" : "nothing was raised"
47
+ "expected block to #{description}, but #{actual}"
48
+ end
49
+
50
+ failure_message_when_negated do
51
+ "expected block not to #{description}, but got #{errors.describe(@error)}"
52
+ end
53
+ end
@@ -65,11 +65,12 @@ module Tonic
65
65
  # request; an Array of them for client- and bidi-streaming RPCs
66
66
  # @param metadata [Hash{String=>String}]
67
67
  # @param timeout_ms [Integer, nil] simulated client deadline
68
+ # @param peer [Tonic::Rails::Peer, nil] simulated client (address, certificates)
68
69
  # @return [Google::Protobuf::AbstractMessage, Array] the response, or
69
70
  # an Array of responses for server- and bidi-streaming RPCs
70
71
  # @raise [RpcError] when the handler ends the call with a status
71
- def call(service_class, rpc_name, request, metadata: {}, timeout_ms: nil)
72
- invoke(service_class, rpc_name, request, metadata: metadata, timeout_ms: timeout_ms).response
72
+ def call(service_class, rpc_name, request, metadata: {}, timeout_ms: nil, peer: nil)
73
+ invoke(service_class, rpc_name, request, metadata: metadata, timeout_ms: timeout_ms, peer: peer).response
73
74
  end
74
75
 
75
76
  # Like #call, but returns a Result with the response metadata too:
@@ -80,7 +81,7 @@ module Tonic
80
81
  # result.trailers["x-cost-ms"] # => "3"
81
82
  #
82
83
  # @return [Result]
83
- def invoke(service_class, rpc_name, request, metadata: {}, timeout_ms: nil)
84
+ def invoke(service_class, rpc_name, request, metadata: {}, timeout_ms: nil, peer: nil)
84
85
  spec = service_class.grpc_rpcs.fetch(rpc_name.to_s) do
85
86
  raise ArgumentError, "#{service_class} has no RPC #{rpc_name}"
86
87
  end
@@ -95,6 +96,7 @@ module Tonic
95
96
  reader: reader,
96
97
  sender: sender,
97
98
  timeout_ms: timeout_ms,
99
+ peer: peer,
98
100
  )
99
101
 
100
102
  response = if spec[:response_stream]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tonic
4
4
  module Rails
5
- VERSION = "0.2.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
data/lib/tonic-rails.rb CHANGED
@@ -11,11 +11,13 @@ end
11
11
 
12
12
  require "tonic/rails/version"
13
13
  require "tonic/rails/metadata"
14
+ require "tonic/rails/peer"
14
15
  require "tonic/rails/rpc_error"
15
16
  require "tonic/rails/configuration"
16
17
  require "tonic/rails/router"
17
18
  require "tonic/rails/instrumentation"
18
19
  require "tonic/rails/base"
20
+ require "tonic/rails/health"
19
21
  require "tonic/rails/reflection"
20
22
  require "tonic/rails/server"
21
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tonic-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: aarch64-linux-gnu
6
6
  authors:
7
7
  - Matt Tanous
@@ -54,6 +54,13 @@ files:
54
54
  - CHANGELOG.md
55
55
  - LICENSE
56
56
  - README.md
57
+ - lib/generators/tonic_rails/install/install_generator.rb
58
+ - lib/generators/tonic_rails/install/templates/tonic_rails.rb.tt
59
+ - lib/generators/tonic_rails/service/service_generator.rb
60
+ - lib/generators/tonic_rails/service/templates/handler.rb.tt
61
+ - lib/generators/tonic_rails/service/templates/service.proto.tt
62
+ - lib/generators/tonic_rails/service/templates/service_spec.rb.tt
63
+ - lib/generators/tonic_rails/service/templates/service_test.rb.tt
57
64
  - lib/puma/plugin/tonic_rails.rb
58
65
  - lib/tonic-rails.rb
59
66
  - lib/tonic/rails/3.3/tonic_rails_native.so
@@ -61,8 +68,10 @@ files:
61
68
  - lib/tonic/rails/4.0/tonic_rails_native.so
62
69
  - lib/tonic/rails/base.rb
63
70
  - lib/tonic/rails/configuration.rb
71
+ - lib/tonic/rails/health.rb
64
72
  - lib/tonic/rails/instrumentation.rb
65
73
  - lib/tonic/rails/metadata.rb
74
+ - lib/tonic/rails/peer.rb
66
75
  - lib/tonic/rails/railtie.rb
67
76
  - lib/tonic/rails/reflection.rb
68
77
  - lib/tonic/rails/router.rb
@@ -70,6 +79,9 @@ files:
70
79
  - lib/tonic/rails/server.rb
71
80
  - lib/tonic/rails/tasks/tonic-rails.rake
72
81
  - lib/tonic/rails/testing.rb
82
+ - lib/tonic/rails/testing/errors.rb
83
+ - lib/tonic/rails/testing/minitest.rb
84
+ - lib/tonic/rails/testing/rspec.rb
73
85
  - lib/tonic/rails/version.rb
74
86
  homepage: https://github.com/CodingAnarchy/tonic-rails
75
87
  licenses: