etcd 0.2.0.alpha → 0.2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,51 +2,52 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe "Etcd test_and_set" do
5
+ describe 'Etcd test_and_set' do
6
6
 
7
7
  let(:client) do
8
8
  Etcd.client
9
9
  end
10
10
 
11
- it "should pass when prev value is correct" do
11
+ it 'should pass when prev value is correct' do
12
12
  key = random_key(2)
13
13
  old_value = uuid.generate
14
14
  new_value = uuid.generate
15
- client.set(key, old_value)
16
- client.test_and_set(key, new_value, old_value)
15
+ resp = client.set(key, value: old_value)
16
+ resp.node.value.should eql old_value
17
+ client.test_and_set(key, value: new_value, prevValue: old_value)
17
18
  expect(client.get(key).value).to eq(new_value)
18
19
  end
19
20
 
20
- it "should fail when prev value is incorrect" do
21
+ it 'should fail when prev value is incorrect' do
21
22
  key = random_key(2)
22
23
  value = uuid.generate
23
- client.set(key, value)
24
- expect{ client.test_and_set(key, 10, 2)}.to raise_error(Etcd::TestFailed)
24
+ client.set(key, value: value)
25
+ expect { client.test_and_set(key, value: 10, prevValue: 2) }.to raise_error(Etcd::TestFailed)
25
26
  end
26
27
 
27
- it "#create should succeed when the key is absent and update should fail" do
28
+ it '#create should succeed when the key is absent and update should fail' do
28
29
  key = random_key(2)
29
30
  value = uuid.generate
30
- expect {
31
- client.update(key, value)
32
- }.to raise_error
33
- expect {
34
- client.create(key, value)
35
- }.to_not raise_error
31
+ expect do
32
+ client.update(key, value: value)
33
+ end.to raise_error
34
+ expect do
35
+ client.create(key, value: value)
36
+ end.to_not raise_error
36
37
  expect(client.get(key).value).to eq(value)
37
38
  end
38
39
 
39
- it "#create should fail when the key is present and update should succeed" do
40
+ it '#create should fail when the key is present and update should succeed' do
40
41
  key = random_key(2)
41
42
  value = uuid.generate
42
- client.set(key, 1)
43
+ client.set(key, value: 1)
43
44
 
44
- expect {
45
- client.create(key, value)
46
- }.to raise_error
45
+ expect do
46
+ client.create(key, value: value)
47
+ end.to raise_error
47
48
 
48
- expect {
49
- client.update(key, value)
50
- }.to_not raise_error
49
+ expect do
50
+ client.update(key, value: value)
51
+ end.to_not raise_error
51
52
  end
52
53
  end
@@ -2,32 +2,32 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe "Etcd watch" do
5
+ describe 'Etcd watch' do
6
6
 
7
7
  let(:client) do
8
8
  Etcd.client
9
9
  end
10
10
 
11
- it "without index, returns the value at a particular index" do
11
+ it 'without index, returns the value at a particular index' do
12
12
  key = random_key(4)
13
13
  value1 = uuid.generate
14
14
  value2 = uuid.generate
15
15
 
16
- index1 = client.create(key, value1).node.modifiedIndex
17
- index2 = client.test_and_set(key, value2, value1).node.modifiedIndex
16
+ index1 = client.create(key, value: value1).node.modifiedIndex
17
+ index2 = client.test_and_set(key, value: value2, prevValue: value1).node.modifiedIndex
18
18
 
19
19
  expect(client.watch(key, index: index1).node.value).to eq(value1)
20
20
  expect(client.watch(key, index: index2).node.value).to eq(value2)
21
21
  end
22
22
 
23
- it "with index, waits and return when the key is updated" do
23
+ it 'with index, waits and return when the key is updated' do
24
24
  response = nil
25
25
  key = random_key
26
26
  value = uuid.generate
27
27
  thr = Thread.new do
28
28
  response = client.watch(key)
29
29
  end
30
- client.set(key, value)
30
+ client.set(key, value: value)
31
31
  thr.join
32
32
  expect(response.node.value).to eq(value)
33
33
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- $:.unshift(File.expand_path("../lib", __FILE__))
4
- $:.unshift(File.expand_path("../spec", __FILE__))
3
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
4
+ $LOAD_PATH.unshift(File.expand_path('../spec', __FILE__))
5
5
 
6
6
  require 'coco'
7
7
  require 'uuid'
@@ -9,40 +9,39 @@ require 'etcd'
9
9
 
10
10
  module Etcd
11
11
  module SpecHelper
12
-
13
12
  @@pids = []
14
13
 
15
14
  def self.etcd_binary
16
- if File.exists? './etcd/etcd'
17
- './etcd/etcd'
18
- elsif !! ENV['ETCD_BIN']
15
+ if File.exists? './etcd/bin/etcd'
16
+ './etcd/bin/etcd'
17
+ elsif !!ENV['ETCD_BIN']
19
18
  ENV['ETCD_BIN']
20
19
  else
21
- raise 'etcd binary not found., you need to set ETCD_BIN'
20
+ fail 'etcd binary not found., you need to set ETCD_BIN'
22
21
  end
23
22
  end
24
23
 
25
24
  def self.start_etcd_servers
26
25
  @@tmpdir = Dir.mktmpdir
27
- pid = spawn_etcd_server(@@tmpdir+'/leader')
26
+ pid = spawn_etcd_server(@@tmpdir + '/leader')
28
27
  @@pids = Array(pid)
29
28
  leader = '127.0.0.1:7001'
30
29
  4.times do |n|
31
30
  client_port = 4002 + n
32
31
  server_port = 7002 + n
33
- pid = spawn_etcd_server(@@tmpdir+client_port.to_s, client_port, server_port, leader)
32
+ pid = spawn_etcd_server(@@tmpdir + client_port.to_s, client_port, server_port, leader)
34
33
  @@pids << pid
35
34
  end
36
35
  end
37
36
 
38
37
  def self.stop_etcd_servers
39
38
  @@pids.each do |pid|
40
- Process.kill("TERM", pid)
39
+ Process.kill('TERM', pid)
41
40
  end
42
41
  FileUtils.remove_entry_secure(@@tmpdir, true)
43
42
  end
44
43
 
45
- def self.spawn_etcd_server(dir, client_port=4001, server_port=7001, leader = nil)
44
+ def self.spawn_etcd_server(dir, client_port = 4001, server_port = 7001, leader = nil)
46
45
  args = " -addr 127.0.0.1:#{client_port} -peer-addr 127.0.0.1:#{server_port} -data-dir #{dir} -name node_#{client_port}"
47
46
  command = if leader.nil?
48
47
  etcd_binary + args
@@ -59,16 +58,16 @@ module Etcd
59
58
  @uuid ||= UUID.new
60
59
  end
61
60
 
62
- def random_key(n=1)
63
- key=''
61
+ def random_key(n = 1)
62
+ key = ''
64
63
  n.times do
65
- key << '/'+ uuid.generate
64
+ key << '/' + uuid.generate
66
65
  end
67
66
  key
68
67
  end
69
68
 
70
69
  def etcd_servers
71
- (1..5).map{|n| "http://127.0.0.1:700#{n}"}
70
+ (1..5).map { |n| "http://127.0.0.1:700#{n}" }
72
71
  end
73
72
 
74
73
  def other_client
@@ -76,7 +75,7 @@ module Etcd
76
75
  end
77
76
 
78
77
  def read_only_client
79
- Etcd.client(:allow_redirect=>false, :port=> 4004)
78
+ Etcd.client(allow_redirect: false, port: 4004)
80
79
  end
81
80
  end
82
81
  end
@@ -91,4 +90,3 @@ RSpec.configure do |c|
91
90
  Etcd::SpecHelper.stop_etcd_servers
92
91
  end
93
92
  end
94
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etcd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.alpha
4
+ version: 0.2.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ranjib Dey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
11
+ date: 2014-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-log
@@ -90,8 +90,10 @@ files:
90
90
  - .coco.yml
91
91
  - .gitignore
92
92
  - .rspec
93
+ - .rubocop.yml
93
94
  - .travis.yml
94
95
  - Gemfile
96
+ - Guardfile
95
97
  - LICENSE.txt
96
98
  - README.md
97
99
  - Rakefile
@@ -108,6 +110,7 @@ files:
108
110
  - lib/etcd/response.rb
109
111
  - lib/etcd/stats.rb
110
112
  - lib/etcd/version.rb
113
+ - spec/etcd/basic_auth_client_spec.rb
111
114
  - spec/etcd/client_spec.rb
112
115
  - spec/etcd/keys_spec.rb
113
116
  - spec/etcd/leader_spec.rb
@@ -144,6 +147,7 @@ signing_key:
144
147
  specification_version: 4
145
148
  summary: Ruby client library for etcd
146
149
  test_files:
150
+ - spec/etcd/basic_auth_client_spec.rb
147
151
  - spec/etcd/client_spec.rb
148
152
  - spec/etcd/keys_spec.rb
149
153
  - spec/etcd/leader_spec.rb