etcdv3 0.11.4 → 0.11.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/etcdv3/lock.rb +2 -2
- data/lib/etcdv3/namespace/lock.rb +2 -2
- data/lib/etcdv3/version.rb +1 -1
- data/spec/etcdv3/lock_spec.rb +19 -5
- data/spec/etcdv3/namespace/lock_spec.rb +26 -7
- data/spec/helpers/connections.rb +8 -0
- data/spec/helpers/metadata_passthrough.rb +21 -0
- data/spec/helpers/test_instance.rb +2 -0
- data/spec/spec_helper.rb +6 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03fa84076fc6d31e895bc80d55abb4501398a0be305cefa1f492b5e217e52277
|
4
|
+
data.tar.gz: 020aa912711d848ceb60a842a2d04bc1d5d3aacbf2714a380782cefd37c3b9c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7541f20326b9577fa7b595e371a0e94713b0b0d83ced62eaae120b5fe77c853625020425258ed941f49b345d40025f7c9d8398ba7bbb136e666f13d1b64e181b
|
7
|
+
data.tar.gz: 3e1226dcf9a6f7a3fcfce148148fcdcabe3f07bf92f24335a7a624b8af3e3b07176162a8f52f606b80dc9df864574ce8e430b95c456a54e79444f6466d3b37b4
|
data/lib/etcdv3/lock.rb
CHANGED
@@ -10,12 +10,12 @@ class Etcdv3
|
|
10
10
|
|
11
11
|
def lock(name, lease_id, timeout: nil)
|
12
12
|
request = V3lockpb::LockRequest.new(name: name, lease: lease_id)
|
13
|
-
@stub.lock(request, deadline: deadline(timeout))
|
13
|
+
@stub.lock(request, metadata: @metadata, deadline: deadline(timeout))
|
14
14
|
end
|
15
15
|
|
16
16
|
def unlock(key, timeout: nil)
|
17
17
|
request = V3lockpb::UnlockRequest.new(key: key)
|
18
|
-
@stub.unlock(request, deadline: deadline(timeout))
|
18
|
+
@stub.unlock(request, metadata: @metadata, deadline: deadline(timeout))
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
@@ -13,14 +13,14 @@ class Etcdv3::Namespace
|
|
13
13
|
def lock(name, lease_id, timeout: nil)
|
14
14
|
name = prepend_prefix(@namespace, name)
|
15
15
|
request = V3lockpb::LockRequest.new(name: name, lease: lease_id)
|
16
|
-
resp = @stub.lock(request, deadline: deadline(timeout))
|
16
|
+
resp = @stub.lock(request, metadata: @metadata, deadline: deadline(timeout))
|
17
17
|
strip_prefix_from_lock(@namespace, resp)
|
18
18
|
end
|
19
19
|
|
20
20
|
def unlock(key, timeout: nil)
|
21
21
|
key = prepend_prefix(@namespace, key)
|
22
22
|
request = V3lockpb::UnlockRequest.new(key: key)
|
23
|
-
@stub.unlock(request, deadline: deadline(timeout))
|
23
|
+
@stub.unlock(request, metadata: @metadata, deadline: deadline(timeout))
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
data/lib/etcdv3/version.rb
CHANGED
data/spec/etcdv3/lock_spec.rb
CHANGED
@@ -10,14 +10,28 @@ unless $instance.version < Gem::Version.new("3.2.0")
|
|
10
10
|
#it_should_behave_like "a method with a GRPC timeout", described_class, :lock, :lock, 'foo'
|
11
11
|
|
12
12
|
describe '#lock' do
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
it 'returns a response' do
|
14
|
+
lease_id = lease_stub.lease_grant(10)['ID']
|
15
|
+
|
16
|
+
expect(stub.lock('example1', lease_id)).to be_an_instance_of(V3lockpb::LockResponse)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'passes metadata correctly' do
|
20
|
+
lease_id = lease_stub.lease_grant(10)['ID']
|
21
|
+
stub = expect_metadata_passthrough(described_class, :lock, :lock)
|
22
|
+
stub.lock('example2', lease_id)
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
26
|
describe '#unlock' do
|
19
|
-
|
20
|
-
|
27
|
+
it 'returns a response' do
|
28
|
+
expect(stub.unlock('example3')).to be_an_instance_of(V3lockpb::UnlockResponse)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'passes metadata correctly' do
|
32
|
+
stub = expect_metadata_passthrough(described_class, :unlock, :unlock)
|
33
|
+
stub.unlock('example4')
|
34
|
+
end
|
21
35
|
end
|
22
36
|
end
|
23
37
|
end
|
@@ -2,22 +2,41 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
# Locking is not implemented in etcd v3.1.X
|
4
4
|
unless $instance.version < Gem::Version.new("3.2.0")
|
5
|
-
describe Etcdv3::Lock do
|
5
|
+
describe Etcdv3::Namespace::Lock do
|
6
6
|
let(:stub) { local_namespace_stub(Etcdv3::Namespace::Lock, 1, '/namespace/') }
|
7
7
|
let(:lease_stub) { local_stub(Etcdv3::Lease, 1) }
|
8
8
|
|
9
|
-
|
9
|
+
# NOTE: this was running duplicate tests against Etcdv3::Lock before, but it
|
10
|
+
# doesn't work with Etcdv3::Namespace::Lock
|
11
|
+
#
|
12
|
+
# it_should_behave_like "a method with a GRPC timeout", described_class, :unlock, :unlock, 'foo'
|
13
|
+
|
10
14
|
# it_should_behave_like "a method with a GRPC timeout", described_class, :lock, :lock, 'foo'
|
11
15
|
|
12
16
|
describe '#lock' do
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
it 'returns a response' do
|
18
|
+
lease_id = lease_stub.lease_grant(10)['ID']
|
19
|
+
expect(stub.lock('example1', lease_id)).to(
|
20
|
+
be_an_instance_of(V3lockpb::LockResponse)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'passes metadata correctly' do
|
25
|
+
lease_id = lease_stub.lease_grant(10)['ID']
|
26
|
+
stub = expect_metadata_passthrough_namespace(described_class, :lock, :lock, '/namespace/')
|
27
|
+
stub.lock('example2', lease_id)
|
28
|
+
end
|
16
29
|
end
|
17
30
|
|
18
31
|
describe '#unlock' do
|
19
|
-
|
20
|
-
|
32
|
+
it 'returns a response' do
|
33
|
+
expect(stub.unlock('example3')).to be_an_instance_of(V3lockpb::UnlockResponse)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'passes metadata correctly' do
|
37
|
+
stub = expect_metadata_passthrough_namespace(described_class, :unlock, :unlock, '/namespace/')
|
38
|
+
stub.unlock('example4')
|
39
|
+
end
|
21
40
|
end
|
22
41
|
end
|
23
42
|
end
|
data/spec/helpers/connections.rb
CHANGED
@@ -21,10 +21,18 @@ module Helpers
|
|
21
21
|
interface.new(local_url, :this_channel_is_insecure, timeout, {})
|
22
22
|
end
|
23
23
|
|
24
|
+
def local_stub_with_metadata(interface, timeout: nil, metadata: {})
|
25
|
+
interface.new(local_url, :this_channel_is_insecure, timeout, metadata)
|
26
|
+
end
|
27
|
+
|
24
28
|
def local_namespace_stub(interface, timeout=nil, namespace)
|
25
29
|
interface.new(local_url, :this_channel_is_insecure, timeout, namespace, {})
|
26
30
|
end
|
27
31
|
|
32
|
+
def local_namespace_stub_with_metadata(interface, timeout: nil, namespace:, metadata: {})
|
33
|
+
interface.new(local_url, :this_channel_is_insecure, timeout, namespace, metadata)
|
34
|
+
end
|
35
|
+
|
28
36
|
def local_url
|
29
37
|
"127.0.0.1:#{port}"
|
30
38
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Helpers
|
2
|
+
module MetadataPassthrough
|
3
|
+
include Connections
|
4
|
+
|
5
|
+
def expect_metadata_passthrough(stub_class, method_name, expectation_target)
|
6
|
+
metadata = { user: "foo", password: "bar" }
|
7
|
+
handler = local_stub_with_metadata(stub_class, metadata: metadata, timeout: 1)
|
8
|
+
inner_stub = handler.instance_variable_get("@stub")
|
9
|
+
expect(inner_stub).to receive(expectation_target).with(anything, hash_including(metadata: metadata)).and_call_original
|
10
|
+
return handler
|
11
|
+
end
|
12
|
+
|
13
|
+
def expect_metadata_passthrough_namespace(stub_class, method_name, expectation_target, namespace)
|
14
|
+
metadata = { user: "foo", password: "bar" }
|
15
|
+
handler = local_namespace_stub_with_metadata(stub_class, metadata: metadata, timeout: 1, namespace: namespace)
|
16
|
+
inner_stub = handler.instance_variable_get("@stub")
|
17
|
+
expect(inner_stub).to receive(expectation_target).with(anything, hash_including(metadata: metadata)).and_call_original
|
18
|
+
return handler
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -3,10 +3,12 @@ require 'tmpdir'
|
|
3
3
|
require 'socket'
|
4
4
|
require 'timeout'
|
5
5
|
require 'helpers/connections'
|
6
|
+
require 'helpers/metadata_passthrough'
|
6
7
|
|
7
8
|
module Helpers
|
8
9
|
class TestInstance
|
9
10
|
include Helpers::Connections
|
11
|
+
include Helpers::MetadataPassthrough
|
10
12
|
|
11
13
|
class InvalidVersionException < StandardError; end
|
12
14
|
class PortInUseException < StandardError; end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,20 +3,22 @@ $LOAD_PATH.unshift File.expand_path('./helpers', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift File.expand_path('./namespace', __FILE__)
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
require 'simplecov'
|
7
|
+
require 'codecov'
|
8
|
+
SimpleCov.start
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
10
10
|
|
11
11
|
require 'etcdv3'
|
12
12
|
require 'helpers/test_instance'
|
13
13
|
require 'helpers/connections'
|
14
|
+
require 'helpers/metadata_passthrough'
|
14
15
|
require 'helpers/shared_examples_for_timeout'
|
15
16
|
|
16
17
|
$instance = Helpers::TestInstance.new
|
17
18
|
|
18
19
|
RSpec.configure do |config|
|
19
20
|
config.include(Helpers::Connections)
|
21
|
+
config.include(Helpers::MetadataPassthrough)
|
20
22
|
|
21
23
|
config.expect_with :rspec do |expectations|
|
22
24
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etcdv3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaun Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- spec/etcdv3/watch_spec.rb
|
127
127
|
- spec/etcdv3_spec.rb
|
128
128
|
- spec/helpers/connections.rb
|
129
|
+
- spec/helpers/metadata_passthrough.rb
|
129
130
|
- spec/helpers/shared_examples_for_timeout.rb
|
130
131
|
- spec/helpers/test_instance.rb
|
131
132
|
- spec/spec_helper.rb
|
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
149
|
- !ruby/object:Gem::Version
|
149
150
|
version: '0'
|
150
151
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
152
|
+
rubygems_version: 3.1.6
|
152
153
|
signing_key:
|
153
154
|
specification_version: 4
|
154
155
|
summary: A Etcd client library for Version 3
|
@@ -166,6 +167,7 @@ test_files:
|
|
166
167
|
- spec/etcdv3/watch_spec.rb
|
167
168
|
- spec/etcdv3_spec.rb
|
168
169
|
- spec/helpers/connections.rb
|
170
|
+
- spec/helpers/metadata_passthrough.rb
|
169
171
|
- spec/helpers/shared_examples_for_timeout.rb
|
170
172
|
- spec/helpers/test_instance.rb
|
171
173
|
- spec/spec_helper.rb
|