Lbspec

Lbspec is an RSpec plugin for easy Loadbalancer testing.

Build Status Coverage Status Gem Version

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 sudo on 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

  1. ssh to nodes
  2. cupture probe
  3. access with probe
  4. judge

#tranfer works

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_command with |port, prove|
  • lbspec_udp_request_command with |addr, port, prove|
  • lbspec_tcp_request_command with |addr, port, prove|
  • lbspec_http_request_command with |addr, port, path, prove|
  • lbspec_https_request_command with |addr, port, path, prove|

Contributing

  1. Fork it ( http://github.com/otahi/lbspec/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request