lbspec 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +33 -0
- data/lib/lbspec/request.rb +4 -4
- data/lib/lbspec/respond.rb +88 -0
- data/lib/lbspec/util.rb +1 -1
- data/lib/lbspec/version.rb +1 -1
- data/lib/lbspec.rb +1 -0
- data/spec/lbspec_respond_spec.rb +61 -0
- data/spec/lbspec_transfer_spec.rb +93 -95
- metadata +7 -4
data/README.md
CHANGED
@@ -48,6 +48,31 @@ You can use following chains with `#transfer`.
|
|
48
48
|
- Options which can be used in http or https request commands.
|
49
49
|
- You can use `options` if you configure request commands or capture commands.
|
50
50
|
|
51
|
+
### #respond
|
52
|
+
`#respond` tests if a virtual host on a load balancer respond as same as expected.
|
53
|
+
|
54
|
+
#### chains
|
55
|
+
You can use following chains with `#respond`.
|
56
|
+
|
57
|
+
- tcp
|
58
|
+
- Tests with tcp packets for the virtual host.
|
59
|
+
- udp
|
60
|
+
- Tests with udp packets for the virtual host.
|
61
|
+
- http
|
62
|
+
- Tests with an http request for the virtual host.
|
63
|
+
- https
|
64
|
+
- Tests with an https request for the virtual host.
|
65
|
+
- from
|
66
|
+
- Specifies which host sends to the virtual host.
|
67
|
+
- path
|
68
|
+
- Specifies a path for http or https requests.
|
69
|
+
- with
|
70
|
+
- Specifies a string included in requests.
|
71
|
+
- options
|
72
|
+
- Options which can be used in http or https request commands.
|
73
|
+
- You can use `options` if you configure request commands or capture commands.
|
74
|
+
|
75
|
+
|
51
76
|
## Requires
|
52
77
|
* Users need to be able to login with ssh to the target nodes.
|
53
78
|
* Users need to be able to `sudo` on the target nodes.
|
@@ -74,14 +99,17 @@ require_relative 'spec_helper'
|
|
74
99
|
|
75
100
|
describe 'vhost_a' do
|
76
101
|
it { should transfer('node_a') }
|
102
|
+
it { should respond('200 OK') }
|
77
103
|
end
|
78
104
|
|
79
105
|
describe 'vhost_b' do
|
80
106
|
it { should transfer(['node_b','node_c']) }
|
107
|
+
it { should respond('200 OK') }
|
81
108
|
end
|
82
109
|
|
83
110
|
describe 'vhost_c:80' do
|
84
111
|
it { should transfer(['node_b','node_c']).port(80) }
|
112
|
+
it { should respond('404') }
|
85
113
|
end
|
86
114
|
|
87
115
|
describe 'vhost_c:80' do
|
@@ -90,10 +118,12 @@ end
|
|
90
118
|
|
91
119
|
describe 'vhost_c:80/test/' do
|
92
120
|
it { should transfer('node_c').http }
|
121
|
+
it { should respond('200 OK').http }
|
93
122
|
end
|
94
123
|
|
95
124
|
describe 'vhost_c:443' do
|
96
125
|
it { should transfer(['node_b','node_c']).port(80).https.path('/test/' }
|
126
|
+
it { should respond('200 OK').https.path('/test/') }
|
97
127
|
end
|
98
128
|
|
99
129
|
describe 'vhost_c:443/test/' do
|
@@ -101,6 +131,9 @@ describe 'vhost_c:443/test/' do
|
|
101
131
|
should transfer(['node_b','node_c']).port(80).https
|
102
132
|
.options(ignore_valid_ssl: true)
|
103
133
|
end
|
134
|
+
it do should respond('200 OK').path('/test/').https
|
135
|
+
.options(ignore_valid_ssl: true)
|
136
|
+
end
|
104
137
|
end
|
105
138
|
|
106
139
|
describe 'vhost_c:80/test/' do
|
data/lib/lbspec/request.rb
CHANGED
@@ -15,7 +15,7 @@ module Lbspec
|
|
15
15
|
@options = options[:options] ? options[:options] : {}
|
16
16
|
end
|
17
17
|
|
18
|
-
def send(prove)
|
18
|
+
def send(prove = nil)
|
19
19
|
if @application
|
20
20
|
send_application(prove)
|
21
21
|
else
|
@@ -54,11 +54,11 @@ module Lbspec
|
|
54
54
|
opt << (options[:ignore_valid_ssl] ? ' -k' : '')
|
55
55
|
opt << (options[:proxy] ? %Q( -x "#{options[:proxy]}") : '')
|
56
56
|
if options[:noproxy]
|
57
|
-
env << %Q(
|
58
|
-
env << %Q(
|
57
|
+
env << %Q(no_proxy="#{options[:noproxy]}" )
|
58
|
+
env << %Q(NO_PROXY="#{options[:noproxy]}" )
|
59
59
|
end
|
60
60
|
opt << header_option(options[:header])
|
61
|
-
%Q(#{env}
|
61
|
+
%Q(#{env}curl -i -s #{opt} '#{uri}')
|
62
62
|
end
|
63
63
|
|
64
64
|
def header_option(header)
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'net/ssh'
|
3
|
+
require 'rspec/core'
|
4
|
+
require 'rspec/expectations'
|
5
|
+
require 'lbspec'
|
6
|
+
|
7
|
+
RSpec::Matchers.define :respond do |expect|
|
8
|
+
|
9
|
+
@expect = expect
|
10
|
+
@protocol = :tcp
|
11
|
+
@application = nil
|
12
|
+
@path = nil
|
13
|
+
@string = nil
|
14
|
+
@chain_str = ''
|
15
|
+
@options = {}
|
16
|
+
@output_request = ''
|
17
|
+
|
18
|
+
match do |vhost|
|
19
|
+
request =
|
20
|
+
Lbspec::Request.new(vhost, @from,
|
21
|
+
protocol: @protocol, application: @application,
|
22
|
+
path: @path, options: @options)
|
23
|
+
@output_request = request.send(@string)
|
24
|
+
@output_request.include?(expect)
|
25
|
+
end
|
26
|
+
|
27
|
+
chain :tcp do
|
28
|
+
@protocol = :tcp
|
29
|
+
@application = nil
|
30
|
+
@chain_str << ' tcp'
|
31
|
+
end
|
32
|
+
|
33
|
+
chain :udp do
|
34
|
+
@protocol = :udp
|
35
|
+
@application = nil
|
36
|
+
@chain_str << ' udp'
|
37
|
+
end
|
38
|
+
|
39
|
+
chain :http do
|
40
|
+
@protocol = :tcp
|
41
|
+
@application = :http
|
42
|
+
@chain_str << ' http'
|
43
|
+
end
|
44
|
+
|
45
|
+
chain :https do
|
46
|
+
@protocol = :tcp
|
47
|
+
@application = :https
|
48
|
+
@chain_str << ' https'
|
49
|
+
end
|
50
|
+
|
51
|
+
chain :from do |from|
|
52
|
+
@from = from
|
53
|
+
@chain_str << " from #{from}"
|
54
|
+
end
|
55
|
+
|
56
|
+
chain :path do |path|
|
57
|
+
@path = path
|
58
|
+
@chain_str << " via #{path}"
|
59
|
+
end
|
60
|
+
|
61
|
+
chain :with do |string|
|
62
|
+
@string = string
|
63
|
+
@chain_str << " via #{string}"
|
64
|
+
end
|
65
|
+
|
66
|
+
chain :options do |options|
|
67
|
+
@options = options
|
68
|
+
end
|
69
|
+
|
70
|
+
description do
|
71
|
+
"respond #{@expect} #{@chain_str}"
|
72
|
+
end
|
73
|
+
|
74
|
+
failure_message_for_should do |vhost|
|
75
|
+
result = "expected #{vhost} to respond #{@expect}"
|
76
|
+
result << result_string
|
77
|
+
end
|
78
|
+
|
79
|
+
failure_message_for_should_not do |vhost|
|
80
|
+
result = "expected #{vhost} not to respond #{@expect}"
|
81
|
+
result << result_string
|
82
|
+
end
|
83
|
+
|
84
|
+
def result_string
|
85
|
+
result = ", but did.\n" + "requested:\n"
|
86
|
+
result << request_str.gsub(/^/, ' ')
|
87
|
+
end
|
88
|
+
end
|
data/lib/lbspec/util.rb
CHANGED
data/lib/lbspec/version.rb
CHANGED
data/lib/lbspec.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'net/ssh'
|
4
|
+
|
5
|
+
describe '#respond' do
|
6
|
+
|
7
|
+
context 'http/https' do
|
8
|
+
it 'should test vhost_a responds with 200 OK' do
|
9
|
+
Lbspec::Util.stub(:exec_command).and_return '200 OK'
|
10
|
+
'vhost_a'.should respond('200 OK')
|
11
|
+
end
|
12
|
+
it 'should test vhost:80 responds with 200 OK by request with options' do
|
13
|
+
Lbspec::Util.stub(:exec_command).and_return '200 OK'
|
14
|
+
'vhost_a:443'.should respond('200 OK').http.path('/test')
|
15
|
+
end
|
16
|
+
it 'should test vhost:443 responds with 404 by request with options' do
|
17
|
+
Lbspec::Util.stub(:exec_command).and_return '404 Not Found'
|
18
|
+
'vhost_a:443'.should respond('404').https.path('/test')
|
19
|
+
.options(ignore_valid_ssl: false, timeout: 5)
|
20
|
+
end
|
21
|
+
it 'should test vhost:443 responds by requests from specified host' do
|
22
|
+
Lbspec::Util.stub(:exec_command).and_return '200 OK'
|
23
|
+
'vhost_a:443'.should respond('200 OK')
|
24
|
+
.https.path('/test').from('node_a')
|
25
|
+
end
|
26
|
+
it 'should test vhost:443 does not respond 404' do
|
27
|
+
Lbspec::Util.stub(:exec_command).and_return '200 OK'
|
28
|
+
'vhost_a:443'.should_not respond('404')
|
29
|
+
.https.path('/test').from('node_a')
|
30
|
+
end
|
31
|
+
it 'should test vhost:443/test does not respond 404' do
|
32
|
+
Lbspec::Util.stub(:exec_command).and_return '200 OK'
|
33
|
+
'vhost_a:443/test'.should_not respond('404')
|
34
|
+
.https.from('node_a')
|
35
|
+
end
|
36
|
+
it 'should test vhost:443/test does not respond 404' do
|
37
|
+
Lbspec::Util.stub(:exec_command).and_return '200 OK'
|
38
|
+
'vhost_a:443/test'.should_not respond('404')
|
39
|
+
.https.from('node_a')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
context 'tcp/udp' do
|
43
|
+
it 'should test vhost:25/tcp respond 220' do
|
44
|
+
Lbspec::Util.stub(:exec_command).and_return '220'
|
45
|
+
'vhost_a:25'.should respond('220')
|
46
|
+
.tcp.with('HELO test.example.com')
|
47
|
+
end
|
48
|
+
it 'should test vhost:53/udp respond ' do
|
49
|
+
Lbspec::Util.stub(:exec_command).and_return '220'
|
50
|
+
'vhost_a:25'.should respond('220')
|
51
|
+
.udp.with('HELO test.example.com')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
context 'description works with 200 OK' do
|
55
|
+
subject { 'vhost_a' }
|
56
|
+
it do
|
57
|
+
Lbspec::Util.stub(:exec_command).and_return '200 OK'
|
58
|
+
should respond('200 OK')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -2,105 +2,103 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'net/ssh'
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
5
|
+
describe '#transfer' do
|
6
|
+
before(:each) do
|
7
|
+
key = Lbspec::Util.create_prove
|
8
|
+
include_str = 'X-Test: 1'
|
9
|
+
Lbspec::Util.stub(:create_prove).and_return(key)
|
10
|
+
channel_connected = double('channel_connected')
|
11
|
+
channel_connected.stub(:request_pty).and_yield(channel_connected, true)
|
12
|
+
channel_connected.stub(:exec).and_yield(channel_connected, nil, nil)
|
13
|
+
channel_connected.stub(:on_data)
|
14
|
+
.and_yield(nil, key + include_str)
|
15
|
+
.and_yield(nil, key + include_str)
|
16
|
+
ssh_connected = double('ssh_connected')
|
17
|
+
ssh_connected.stub(:open_channel).and_yield(channel_connected)
|
18
|
+
ssh_connected.stub(:closed?).and_return(false)
|
19
|
+
ssh_connected.stub(:close)
|
20
|
+
ssh_connected.stub(:exec!).and_return(true)
|
21
|
+
Net::SSH.stub(:start).and_yield(ssh_connected).and_return(ssh_connected)
|
22
|
+
Kernel.stub(:system).and_return true
|
23
|
+
Kernel.stub(:`).and_return(key + include_str) # `
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
26
|
+
it 'should test transfer a node' do
|
27
|
+
'vhost_a'.should transfer('node_a')
|
28
|
+
end
|
29
|
+
it 'should test transfer nodes' do
|
30
|
+
'vhost_a'.should transfer(%w(node_a node_b))
|
31
|
+
end
|
32
|
+
it 'should test transfer a node on port 80' do
|
33
|
+
'vhost_a'.should transfer('node_a').port(80)
|
34
|
+
end
|
35
|
+
it 'should test transfer vhost:80 and a node on port 80' do
|
36
|
+
'vhost_a:80'.should transfer('node_a').port(80)
|
37
|
+
end
|
38
|
+
it 'should test transfer vhost:80 and a node on port 80/tcp' do
|
39
|
+
'vhost_a:80'.should transfer('node_a').port(80).tcp
|
40
|
+
end
|
41
|
+
it 'should test transfer vhost:80 and a node on port 53/tcp' do
|
42
|
+
'vhost_a:80'.should transfer('node_a').port(53).udp
|
43
|
+
end
|
44
|
+
it 'should test transfer vhost:80 and a node with http' do
|
45
|
+
'vhost_a:80'.should transfer('node_a').http
|
46
|
+
end
|
47
|
+
it 'should test transfer vhost:443 and a node with https' do
|
48
|
+
'vhost_a:443'.should transfer('node_a').port(80).https
|
49
|
+
end
|
50
|
+
it 'should test transfer vhost:443 and a node:80 with https' do
|
51
|
+
'vhost_a:443'.should transfer('node_a').port(80).https
|
52
|
+
end
|
53
|
+
it 'should test transfer vhost:443 and a node with https /test' do
|
54
|
+
'vhost_a:443/test'.should transfer('node_a').https
|
55
|
+
end
|
56
|
+
it 'should test transfer vhost:443 with options for requests' do
|
57
|
+
'vhost_a:443'.should transfer('node_a').https.path('/test')
|
58
|
+
.options(ignore_valid_ssl: true)
|
59
|
+
'vhost_a:443/test'.should transfer('node_a').https
|
60
|
+
.options(ignore_valid_ssl: false, timeout: 5)
|
61
|
+
end
|
62
|
+
it 'should test transfer vhost:443 requests from specified host' do
|
63
|
+
'vhost_a:443/test'.should transfer('node_a')
|
64
|
+
.https.from('node_a')
|
65
|
+
end
|
66
|
+
it 'should test transfer vhost:80 and a node with http includes ' do
|
67
|
+
'vhost_a:80'.should transfer('node_a').http
|
68
|
+
.include('X-Test: 1')
|
69
|
+
'vhost_a:80'.should transfer('node_a').http
|
70
|
+
.include(/Test:/)
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'request_command' do
|
74
|
+
it 'should create single header options for http' do
|
75
|
+
Lbspec::Util.should_receive(:exec_command)
|
76
|
+
.with(/ -H.*/, nil)
|
77
|
+
Lbspec::Util.should_not_receive(:exec_command)
|
78
|
+
.with(/ -H.* -H/, nil)
|
79
|
+
'vhost_a:443'.should transfer('node_a').http
|
80
|
+
.options(header: 'X-Test1:1')
|
62
81
|
end
|
63
|
-
it 'should
|
64
|
-
|
65
|
-
.
|
82
|
+
it 'should create single header options for https' do
|
83
|
+
Lbspec::Util.should_receive(:exec_command)
|
84
|
+
.with(/ -H.*/, nil)
|
85
|
+
Lbspec::Util.should_not_receive(:exec_command)
|
86
|
+
.with(/ -H.* -H/, nil)
|
87
|
+
'vhost_a:443'.should transfer('node_a').https
|
88
|
+
.options(header: 'X-Test1:1')
|
66
89
|
end
|
67
|
-
it 'should
|
68
|
-
|
69
|
-
.
|
70
|
-
'vhost_a:
|
71
|
-
.
|
90
|
+
it 'should create multi header options for http' do
|
91
|
+
Lbspec::Util.should_receive(:exec_command)
|
92
|
+
.with(/ -H.* -H/, nil)
|
93
|
+
'vhost_a:443'.should transfer('node_a').http
|
94
|
+
.options(header: %w(X-Test1:1 X-Test2:2))
|
72
95
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
Lbspec::Util.should_not_receive(:exec_command)
|
79
|
-
.with(/ -H.* -H/, nil)
|
80
|
-
'vhost_a:443'.should transfer('node_a').http
|
81
|
-
.options(header: 'X-Test1:1')
|
82
|
-
end
|
83
|
-
it 'should create single header options for https' do
|
84
|
-
Lbspec::Util.should_receive(:exec_command)
|
85
|
-
.with(/ -H.*/, nil)
|
86
|
-
Lbspec::Util.should_not_receive(:exec_command)
|
87
|
-
.with(/ -H.* -H/, nil)
|
88
|
-
'vhost_a:443'.should transfer('node_a').https
|
89
|
-
.options(header: 'X-Test1:1')
|
90
|
-
end
|
91
|
-
it 'should create multi header options for http' do
|
92
|
-
Lbspec::Util.should_receive(:exec_command)
|
93
|
-
.with(/ -H.* -H/, nil)
|
94
|
-
'vhost_a:443'.should transfer('node_a').http
|
95
|
-
.options(header: %w(X-Test1:1 X-Test2:2))
|
96
|
-
end
|
97
|
-
it 'should create multi header options for https' do
|
98
|
-
Lbspec::Util.should_receive(:exec_command)
|
99
|
-
.with(/ -H.* -H/, nil)
|
100
|
-
'vhost_a:443'.should transfer('node_a').https
|
101
|
-
.options(header: %w(X-Test1:1 X-Test2:2))
|
102
|
-
end
|
96
|
+
it 'should create multi header options for https' do
|
97
|
+
Lbspec::Util.should_receive(:exec_command)
|
98
|
+
.with(/ -H.* -H/, nil)
|
99
|
+
'vhost_a:443'.should transfer('node_a').https
|
100
|
+
.options(header: %w(X-Test1:1 X-Test2:2))
|
103
101
|
end
|
104
|
-
|
105
102
|
end
|
103
|
+
|
106
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lbspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -162,12 +162,14 @@ files:
|
|
162
162
|
- lib/lbspec.rb
|
163
163
|
- lib/lbspec/capture.rb
|
164
164
|
- lib/lbspec/request.rb
|
165
|
+
- lib/lbspec/respond.rb
|
165
166
|
- lib/lbspec/transfer.rb
|
166
167
|
- lib/lbspec/util.rb
|
167
168
|
- lib/lbspec/version.rb
|
168
169
|
- rubocop-todo.yml
|
169
170
|
- sample/lb_spec.rb
|
170
171
|
- sample/spec_helper.rb
|
172
|
+
- spec/lbspec_respond_spec.rb
|
171
173
|
- spec/lbspec_spec.rb
|
172
174
|
- spec/lbspec_transfer_spec.rb
|
173
175
|
- spec/spec_helper.rb
|
@@ -186,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
188
|
version: '0'
|
187
189
|
segments:
|
188
190
|
- 0
|
189
|
-
hash: -
|
191
|
+
hash: -4421484859760496342
|
190
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
193
|
none: false
|
192
194
|
requirements:
|
@@ -195,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
197
|
version: '0'
|
196
198
|
segments:
|
197
199
|
- 0
|
198
|
-
hash: -
|
200
|
+
hash: -4421484859760496342
|
199
201
|
requirements: []
|
200
202
|
rubyforge_project:
|
201
203
|
rubygems_version: 1.8.21
|
@@ -203,6 +205,7 @@ signing_key:
|
|
203
205
|
specification_version: 3
|
204
206
|
summary: Easily test your Loadbalancers with RSpec.
|
205
207
|
test_files:
|
208
|
+
- spec/lbspec_respond_spec.rb
|
206
209
|
- spec/lbspec_spec.rb
|
207
210
|
- spec/lbspec_transfer_spec.rb
|
208
211
|
- spec/spec_helper.rb
|