google-gax 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec76cdd33b0b9fa99cacf500fe8dfdffb3d74a38
4
- data.tar.gz: ab2e1c9b639932dc661876970be636890339a2bf
3
+ metadata.gz: 9c4b4e8a1661f0a0734a310e5969872001666206
4
+ data.tar.gz: f2af4244cfd73b82bff30393ff21ef5d6bcbc4e3
5
5
  SHA512:
6
- metadata.gz: 641d4a0082acdff4c9d33e22e9e6ce06686863c913d3401fb8204dc0ecaaa5bce4ae2d20296557f6e4f6ce160d64ad9653db9762af31913347de04d3d1152548
7
- data.tar.gz: da6bf4c3bdb36641c935ebd0e9bf23254927d23d2a117ed6d07d5330ee28ad272f887503de9ced775b0161d8d19304c94091e6be6a6308108a74fe5a95d0a80f
6
+ metadata.gz: 9f3c887fb4413c90d7397024a5da6fcf280e656a6dd5fd0e8707e292a955bb0731637c13ec4dbd596750070b314ea431506a80474384716a0227fd4998b044df
7
+ data.tar.gz: b487c73d5bf55f2e135a089b1b6147fbe756b63c73fef312d1c5df7fdb0db8290b58ca5cf7a109124e94b8a5689bd5e877ce0fde260e5608156845526c009b85
@@ -121,22 +121,27 @@ module Google
121
121
  @callbacks = []
122
122
  end
123
123
 
124
- # If the operation is done, returns the result, otherwise returns nil.
124
+ # If the operation is done, returns the response.
125
125
  # If the operation response is an error, the error will be returned.
126
- # If a type is provided, the response will be unpacked using the type
127
- # provided; returning nil if the response is not of the type provided.
128
- # If the type is not of provided, the response will be unpacked using
129
- # the response's type_url if the type_url is found in the
130
- # Google::Protobuf::DescriptorPool.generated_pool.
131
- # If the type cannot be found the raw response is retuned.
126
+ # Otherwise returns nil.
132
127
  #
133
128
  # @return [Object, Google::Rpc::Status, nil]
134
129
  # The result of the operation. If it is an error a Google::Rpc::Status
135
130
  # will be returned.
136
131
  def results
137
- return nil unless done?
138
- return @grpc_op.error if error?
139
- @grpc_op.response.unpack(@result_type)
132
+ return error if error?
133
+ return response if response?
134
+ end
135
+
136
+ # Returns the server-assigned name of the operation, which is only unique
137
+ # within the same service that originally returns it. If you use the
138
+ # default HTTP mapping, the name should have the format of
139
+ # operations/some/unique/name.
140
+ #
141
+ # @return [String]
142
+ # The name of the operation.
143
+ def name
144
+ @grpc_op.name
140
145
  end
141
146
 
142
147
  # Returns the metadata of an operation. If a type is provided,
@@ -162,6 +167,22 @@ module Google
162
167
  @grpc_op.done
163
168
  end
164
169
 
170
+ # Checks if the operation is done and the result is a response.
171
+ # If the operation is not finished then this will return false.
172
+ #
173
+ # @return [Boolean] Whether a response has been returned.
174
+ def response?
175
+ done? ? @grpc_op.result == :response : false
176
+ end
177
+
178
+ # If the operation is done, returns the response, otherwise returns nil.
179
+ #
180
+ # @return [Object, nil]
181
+ # The response of the operation.
182
+ def response
183
+ @grpc_op.response.unpack(@result_type) if response?
184
+ end
185
+
165
186
  # Checks if the operation is done and the result is an error.
166
187
  # If the operation is not finished then this will return false.
167
188
  #
@@ -170,11 +191,25 @@ module Google
170
191
  done? ? @grpc_op.result == :error : false
171
192
  end
172
193
 
194
+ # If the operation response is an error, the error will be returned,
195
+ # otherwise returns nil.
196
+ #
197
+ # @return [Google::Rpc::Status, nil]
198
+ # The error object.
199
+ def error
200
+ @grpc_op.error if error?
201
+ end
202
+
173
203
  # Cancels the operation.
174
204
  def cancel
175
205
  @client.cancel_operation(@grpc_op.name)
176
206
  end
177
207
 
208
+ # Deletes the operation.
209
+ def delete
210
+ @client.delete_operation(@grpc_op.name)
211
+ end
212
+
178
213
  # Reloads the operation object.
179
214
  #
180
215
  # @return [Google::Gax::Operation]
@@ -29,6 +29,6 @@
29
29
 
30
30
  module Google
31
31
  module Gax
32
- VERSION = '0.7.1'.freeze
32
+ VERSION = '0.8.0'.freeze
33
33
  end
34
34
  end
@@ -43,9 +43,10 @@ GaxOp = Google::Gax::Operation
43
43
  MILLIS_PER_SECOND = Google::Gax::MILLIS_PER_SECOND
44
44
 
45
45
  class MockLroClient
46
- def initialize(get_method: nil, cancel_method: nil)
46
+ def initialize(get_method: nil, cancel_method: nil, delete_method: nil)
47
47
  @get_method = get_method
48
48
  @cancel_method = cancel_method
49
+ @delete_method = delete_method
49
50
  end
50
51
 
51
52
  def get_operation(grpc_method, options: nil)
@@ -55,6 +56,10 @@ class MockLroClient
55
56
  def cancel_operation(name)
56
57
  @cancel_method.call(name)
57
58
  end
59
+
60
+ def delete_operation(name)
61
+ @delete_method.call(name)
62
+ end
58
63
  end
59
64
 
60
65
  RESULT_ANY = Google::Protobuf::Any.new
@@ -99,6 +104,13 @@ describe Google::Gax::Operation do
99
104
  end
100
105
  end
101
106
 
107
+ context 'method `name`' do
108
+ it 'should return the operation name' do
109
+ op = create_op(GrpcOp.new(done: true, name: '1234567890'))
110
+ expect(op.name).to eq('1234567890')
111
+ end
112
+ end
113
+
102
114
  context 'method `metadata`' do
103
115
  it 'should unpack the metadata' do
104
116
  op = create_op(GrpcOp.new(done: true, metadata: METADATA_ANY))
@@ -124,12 +136,65 @@ describe Google::Gax::Operation do
124
136
  expect(op.error?).to eq(true)
125
137
  end
126
138
 
127
- it 'should return true on finished operation.' do
139
+ it 'should return false on finished operation.' do
128
140
  op = create_op(GrpcOp.new(done: true, response: RESULT_ANY))
129
141
  expect(op.error?).to eq(false)
130
142
  end
131
143
  end
132
144
 
145
+ context 'method `error`' do
146
+ it 'should return nil on unfinished operation.' do
147
+ op = create_op(GrpcOp.new(done: false))
148
+ expect(op.error).to eq(nil)
149
+ end
150
+
151
+ it 'should return error on error operation.' do
152
+ error = Google::Rpc::Status.new
153
+ op = create_op(GrpcOp.new(done: true, error: error))
154
+ expect(op.error).to eq(error)
155
+ end
156
+
157
+ it 'should return nil on finished operation.' do
158
+ op = create_op(GrpcOp.new(done: true, response: RESULT_ANY))
159
+ expect(op.error).to eq(nil)
160
+ end
161
+ end
162
+
163
+ context 'method `response?`' do
164
+ it 'should return false on unfinished operation.' do
165
+ expect(create_op(GrpcOp.new(done: false)).response?).to eq(false)
166
+ end
167
+
168
+ it 'should return false on error operation.' do
169
+ error = Google::Rpc::Status.new
170
+ op = create_op(GrpcOp.new(done: true, error: error))
171
+ expect(op.response?).to eq(false)
172
+ end
173
+
174
+ it 'should return true on finished operation.' do
175
+ op = create_op(GrpcOp.new(done: true, response: RESULT_ANY))
176
+ expect(op.response?).to eq(true)
177
+ end
178
+ end
179
+
180
+ context 'method `response`' do
181
+ it 'should return nil on unfinished operation.' do
182
+ op = create_op(GrpcOp.new(done: false))
183
+ expect(op.response).to eq(nil)
184
+ end
185
+
186
+ it 'should return nil on error operation.' do
187
+ error = Google::Rpc::Status.new
188
+ op = create_op(GrpcOp.new(done: true, error: error))
189
+ expect(op.response).to eq(nil)
190
+ end
191
+
192
+ it 'should result on finished operation.' do
193
+ op = create_op(GrpcOp.new(done: true, response: RESULT_ANY))
194
+ expect(op.response).to eq(RESULT)
195
+ end
196
+ end
197
+
133
198
  context 'method `cancel`' do
134
199
  it 'should call the clients cancel_operation' do
135
200
  op_name = 'test_name'
@@ -144,6 +209,20 @@ describe Google::Gax::Operation do
144
209
  end
145
210
  end
146
211
 
212
+ context 'method `delete`' do
213
+ it 'should call the clients delete_operation' do
214
+ op_name = 'test_name'
215
+ called = false
216
+ delete_method = proc do |name|
217
+ expect(name).to eq(op_name)
218
+ called = true
219
+ end
220
+ mock_client = MockLroClient.new(delete_method: delete_method)
221
+ create_op(GrpcOp.new(name: op_name), client: mock_client).delete
222
+ expect(called).to eq(true)
223
+ end
224
+ end
225
+
147
226
  context 'method `reload!`' do
148
227
  it 'should call the get_operation of the client' do
149
228
  called = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-gax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google API Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-16 00:00:00.000000000 Z
11
+ date: 2017-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: googleauth
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.3.1
47
+ version: 1.3.5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.3.1
54
+ version: 1.3.5
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: google-protobuf
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 2.4.8
199
+ rubygems_version: 2.6.8
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: Aids the development of APIs for clients and servers based on GRPC and Google