lbspec 0.2.11 → 0.2.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48b23c45d1f0d0399f34543470a376b5fb6b85bd
4
- data.tar.gz: e24a0f6d1576dcdd37678c55184b7a9c09838d6e
3
+ metadata.gz: 43048b897beb3ba1a36100e000c80c834e583e6b
4
+ data.tar.gz: 2dfab8428ce339d379cf35e0b5bcacb6b30b6acf
5
5
  SHA512:
6
- metadata.gz: 52b6e18a76563962c7d2a11bf0de40aea25901a707a2bca1bf86731c0693e79ea31ddfc46ca4a92a32239abb145d9bc38dc9170dc38e9eedcbdb9c58abbcd734
7
- data.tar.gz: 2040d851d1c251d52964ee3f1a819d3df5146f987018bd312286ed3f9a9f16414e39219b1e65d7b83cc39d4f2385c367399057a7448abbb9cc1e6a6bc81356d0
6
+ metadata.gz: f14e286e526b7a04d013d40dc879c18290e6faacb37d0b96865d72defdf40b09c05ca391861426e0070f801f2bcc1ffeee58cd6f0590a9446379ee885f6dac7e
7
+ data.tar.gz: b8ccc5ae96580c571872900149ec3885a505e0f13d95cfed0241ff0d51240c2f79d6d7befdfdd87aa0e8dc35b78011ce2dcbfb28d7b3c3793709d0e9ee2040a4
data/README.md CHANGED
@@ -5,6 +5,102 @@ Lbspec is an RSpec plugin for easy Loadbalancer testing.
5
5
  [![Build Status](https://travis-ci.org/otahi/lbspec.png?branch=master)](https://travis-ci.org/otahi/lbspec)
6
6
  [![Coverage Status](https://coveralls.io/repos/otahi/lbspec/badge.png?branch=master)](https://coveralls.io/r/otahi/lbspec?branch=master)
7
7
  [![Gem Version](https://badge.fury.io/rb/lbspec.png)](http://badge.fury.io/rb/lbspec)
8
+
9
+ ## Usage
10
+
11
+ Lbspec is best described by example. First, require `lbspec` in your `spec_helper.rb`:
12
+
13
+ ```ruby
14
+ # spec/spec_helper.rb
15
+ require 'lbspec'
16
+ ```
17
+
18
+ Then, create a spec like this:
19
+
20
+ ```ruby
21
+ require_relative 'spec_helper'
22
+
23
+ describe 'vhost_a' do
24
+ it { should transfer('node_a') }
25
+ it { should respond('200 OK') }
26
+ end
27
+
28
+ describe 'vhost_b' do
29
+ it { should transfer(%w(node_b node_c)) }
30
+ it { should respond('200 OK') }
31
+ end
32
+
33
+ describe 'vhost_c:80' do
34
+ it { should transfer(%w(node_b node_c)).port(80) }
35
+ it { should respond('404') }
36
+ end
37
+
38
+ describe 'vhost_c:80' do
39
+ it { should transfer(%w(node_b node_c)).port(53).udp }
40
+ end
41
+
42
+ describe 'vhost_c:80/test/' do
43
+ it { should transfer('node_c').http }
44
+ it { should respond('200 OK').http }
45
+ end
46
+
47
+ describe 'vhost_c:443' do
48
+ it { should transfer(%w(node_b node_c)).port(80).https.path('/test/') }
49
+ it { should respond('200 OK').https.path('/test/') }
50
+ end
51
+
52
+ describe 'vhost_c:443/test/' do
53
+ it do
54
+ should transfer(%w(node_b node_c)).port(80).https
55
+ .options(ignore_valid_ssl: true)
56
+ end
57
+ it do should respond('200 OK').path('/test/').https
58
+ .options(ignore_valid_ssl: true)
59
+ end
60
+ end
61
+
62
+ describe 'vhost_c:80/test/' do
63
+ it { should transfer('node_c').http.from('node_a') }
64
+ end
65
+
66
+ describe 'loadbalancer' do
67
+ it do should healthcheck('node_c')
68
+ .include('/test/healthcheck').from('192.168.1.1')
69
+ end
70
+ end
71
+
72
+ describe 'loadbalancer' do
73
+ it { should healthcheck('node_c').include('/test/healthcheck').interval(5) }
74
+ end
75
+ ```
76
+
77
+ You will get a result:
78
+ ```
79
+ $ bundle exec rspec spec.rb
80
+
81
+ vhost_a
82
+ should transfer requests to node_a.
83
+ should respond 200 OK.
84
+ vhost_b
85
+ should transfer requests to ["node_b", "node_c"].
86
+ should respond 200 OK.
87
+ vhost_c:80
88
+ should transfer requests to ["node_b", "node_c"] port 80.
89
+ should respond 404.
90
+ vhost_c:80
91
+ should transfer requests to ["node_b", "node_c"] port 53 udp.
92
+ vhost_c:80/test/
93
+ should transfer requests to node_c http.
94
+ should respond 200 OK http.
95
+ vhost_c:443
96
+ should transfer requests to ["node_b", "node_c"] port 80 https via /test/.
97
+ should respond 200 OK https via /test/.
98
+ vhost_c:443/test/
99
+ should transfer requests to ["node_b", "node_c"] port 80 https.
100
+ should respond 200 OK
101
+ ```
102
+
103
+
8
104
  ## Installation
9
105
 
10
106
  Add this line to your application's Gemfile:
@@ -119,73 +215,6 @@ You can use following chains with `#healthcheck`.
119
215
  ## Limitations
120
216
  * Lbspec uses only ssh configuration in ~/.ssh/config
121
217
 
122
- ## Usage
123
-
124
- Lbspec is best described by example. First, require `lbspec` in your `spec_helper.rb`:
125
-
126
- ```ruby
127
- # spec/spec_helper.rb
128
- require 'rspec'
129
- require 'lbspec'
130
- ```
131
-
132
- Then, create a spec like this:
133
-
134
- ```ruby
135
- require_relative 'spec_helper'
136
-
137
- describe 'vhost_a' do
138
- it { should transfer('node_a') }
139
- it { should respond('200 OK') }
140
- end
141
-
142
- describe 'vhost_b' do
143
- it { should transfer(['node_b','node_c']) }
144
- it { should respond('200 OK') }
145
- end
146
-
147
- describe 'vhost_c:80' do
148
- it { should transfer(['node_b','node_c']).port(80) }
149
- it { should respond('404') }
150
- end
151
-
152
- describe 'vhost_c:80' do
153
- it { should transfer(['node_b','node_c']).port(53).udp }
154
- end
155
-
156
- describe 'vhost_c:80/test/' do
157
- it { should transfer('node_c').http }
158
- it { should respond('200 OK').http }
159
- end
160
-
161
- describe 'vhost_c:443' do
162
- it { should transfer(['node_b','node_c']).port(80).https.path('/test/' }
163
- it { should respond('200 OK').https.path('/test/') }
164
- end
165
-
166
- describe 'vhost_c:443/test/' do
167
- it do
168
- should transfer(['node_b','node_c']).port(80).https
169
- .options(ignore_valid_ssl: true)
170
- end
171
- it do should respond('200 OK').path('/test/').https
172
- .options(ignore_valid_ssl: true)
173
- end
174
- end
175
-
176
- describe 'vhost_c:80/test/' do
177
- it { should transfer('node_c').http.from('node_a') }
178
- end
179
-
180
- describe 'loadbalancer' do
181
- it { should healthcheck('node_c').include('/test/healthcheck').from('192.168.1.1') }
182
- end
183
-
184
- describe 'loadbalancer' do
185
- it { should healthcheck('node_c').include('/test/healthcheck').interval(5) }
186
- end
187
-
188
- ```
189
218
  ## How it works
190
219
  ### #transfer
191
220
 
@@ -51,7 +51,7 @@ module Lbspec
51
51
  private
52
52
 
53
53
  def set_initial_value
54
- @threads, @ssh, @nodes_connected = [], [], []
54
+ @threads, @ssh, @nodes_connected = [], [], {}
55
55
  @result = false
56
56
  @output = []
57
57
  end
@@ -82,21 +82,22 @@ module Lbspec
82
82
  end
83
83
 
84
84
  def exec_capture(channel)
85
- exec_capture_command(channel, capture_command)
86
- @nodes_connected.push(true)
87
- end
88
-
89
- def exec_capture_command(channel, command)
90
85
  whole_data = ''
91
86
  @start_sec = Time.now.to_i + 1
92
- channel.exec command do |ch, _stream, _data|
93
- ch.on_data do |_c, d|
94
- whole_data << d
95
- @result = match_all?(whole_data)
96
- end
87
+ channel.exec(capture_command) do |ch, _stream, _data|
88
+ receive_data(ch, whole_data)
97
89
  break if capture_done?
98
90
  end
99
- whole_data
91
+ capture_command + "\n" + whole_data
92
+ end
93
+
94
+ def receive_data(channel, data)
95
+ channel.on_data do |_c, d|
96
+ @nodes_connected.merge!(Thread.current.to_s => true)
97
+ data << d
98
+ @result = match_all?(data)
99
+ end
100
+ data
100
101
  end
101
102
 
102
103
  def capture_done?
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Lbspec is an RSpec plugin for easy Loadbalancer testing.
3
3
  module Lbspec
4
- VERSION = '0.2.11'
4
+ VERSION = '0.2.12'
5
5
  end
data/sample/lb_spec.rb CHANGED
@@ -1,12 +1,81 @@
1
1
  require_relative 'spec_helper'
2
+ require 'net/ssh'
2
3
 
3
- describe 'vhost_a' do
4
- it { should transfer('node_a') }
5
- it { should transfer(['node_c','node_b']) }
6
- it 'should test transfer a node on port 80' do
7
- 'vhost_a'.should transfer('node_a:80')
4
+ describe 'sample spec' do
5
+ before(:each) do
6
+ key = Lbspec::Util.create_prove
7
+ include_str = 'X-Test: 1 /test/healthcheck'
8
+ Lbspec::Util.stub(:create_prove).and_return(key)
9
+ channel_connected = double('channel_connected')
10
+ channel_connected.stub(:request_pty).and_yield(channel_connected, true)
11
+ channel_connected.stub(:exec).and_yield(channel_connected, nil, nil)
12
+ channel_connected.stub(:on_data)
13
+ .and_yield(nil, key + include_str)
14
+ .and_yield(nil, key + include_str)
15
+ ssh_connected = double('ssh_connected')
16
+ ssh_connected.stub(:open_channel).and_yield(channel_connected)
17
+ ssh_connected.stub(:closed?).and_return(false)
18
+ ssh_connected.stub(:close)
19
+ ssh_connected.stub(:exec!).and_return(true)
20
+ Net::SSH.stub(:start).and_yield(ssh_connected).and_return(ssh_connected)
21
+ Lbspec::Util.stub(:`).and_return(key + include_str) # `
22
+ Lbspec::Util.stub(:exec_command).and_return '200 OK 404'
23
+ Kernel.stub(:system).and_return true
24
+ Kernel.stub(:`).and_return(include_str) # `
8
25
  end
9
- it 'should test transfer a node on port 8080' do
10
- 'vhost_a'.should_not transfer('node_a:8080')
26
+
27
+ require_relative 'spec_helper'
28
+
29
+ describe 'vhost_a' do
30
+ it { should transfer('node_a') }
31
+ it { should respond('200 OK') }
32
+ end
33
+
34
+ describe 'vhost_b' do
35
+ it { should transfer(%w(node_b node_c)) }
36
+ it { should respond('200 OK') }
37
+ end
38
+
39
+ describe 'vhost_c:80' do
40
+ it { should transfer(%w(node_b node_c)).port(80) }
41
+ it { should respond('404') }
42
+ end
43
+
44
+ describe 'vhost_c:80' do
45
+ it { should transfer(%w(node_b node_c)).port(53).udp }
46
+ end
47
+
48
+ describe 'vhost_c:80/test/' do
49
+ it { should transfer('node_c').http }
50
+ it { should respond('200 OK').http }
51
+ end
52
+
53
+ describe 'vhost_c:443' do
54
+ it { should transfer(%w(node_b node_c)).port(80).https.path('/test/') }
55
+ it { should respond('200 OK').https.path('/test/') }
56
+ end
57
+
58
+ describe 'vhost_c:443/test/' do
59
+ it do
60
+ should transfer(%w(node_b node_c)).port(80).https
61
+ .options(ignore_valid_ssl: true)
62
+ end
63
+ it do should respond('200 OK').path('/test/').https
64
+ .options(ignore_valid_ssl: true)
65
+ end
66
+ end
67
+
68
+ describe 'vhost_c:80/test/' do
69
+ it { should transfer('node_c').http.from('node_a') }
70
+ end
71
+
72
+ describe 'loadbalancer' do
73
+ it do should healthcheck('node_c')
74
+ .include('/test/healthcheck').from('192.168.1.1')
75
+ end
76
+ end
77
+
78
+ describe 'loadbalancer' do
79
+ it { should healthcheck('node_c').include('/test/healthcheck').interval(5) }
11
80
  end
12
81
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lbspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - OTA Hiroshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-23 00:00:00.000000000 Z
11
+ date: 2014-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler