Lbspec
Lbspec is an RSpec plugin for easy Loadbalancer testing.
Installation
Add this line to your application's Gemfile:
gem 'lbspec'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lbspec
Requires
- Users need to be able to login with ssh to the target nodes.
- Users need to be able to
sudoon the target nodes. - netcat and ngrep are needed to be installed.
Limitations
- Lbspec uses only ssh configuration in ~/.ssh/config
Usage
Lbspec is best described by example. First, require lbspec in your spec_helper.rb:
# spec/spec_helper.rb
require 'rspec'
require 'lbspec'
Then, create a spec like this:
require_relative 'spec_helper'
describe 'vhost_a' do
it { should transfer('node_a') }
end
describe 'vhost_b' do
it { should transfer(['node_b','node_c']) }
end
describe 'vhost_c:80' do
it { should transfer(['node_b','node_c']).port(80) }
end
describe 'vhost_c:80' do
it { should transfer(['node_b','node_c']).port(53).udp }
end
describe 'vhost_c:80' do
it { should transfer('node_c').http.path('/test/') }
end
describe 'vhost_c:443' do
it { should transfer(['node_b','node_c']).port(80).https.path('/test/') }
end
How it works
#transfer
- ssh to nodes
- cupture probe
- access with probe
- judge

Configuration
#transfer
You can cnange how to capture probes and access to vhost with probes. You can replace default procedures to your procedures in spec_helpers or .spec files as follows.
RSpec.configuration.lbspec_capture_command =
lambda do |port, prove|
port_str = port > 0 ? "port #{port}" : ''
"sudo ngrep #{prove} #{port_str} | grep -v \"match:\""
end
RSpec.configuration.lbspec_https_request_command =
lambda do |addr, port, path, prove|
uri = 'https://' + "#{addr}:#{port}#{path}?#{prove}"
system("curl -o /dev/null -sk #{uri}")
end
You can replace following items.
lbspec_capture_commandwith|port, prove|lbspec_udp_request_commandwith|addr, port, prove|lbspec_tcp_request_commandwith|addr, port, prove|lbspec_http_request_commandwith|addr, port, path, prove|lbspec_https_request_commandwith|addr, port, path, prove|
Contributing
- Fork it ( http://github.com/otahi/lbspec/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request


