Infrataster
Infrastructure Behavior Testing Framework.
Usage
You can see example directory too.
First, create Gemfile:
source 'https://rubygems.org'
gem 'infrataster'
Install gems:
$ bundle install
Initialize rspec directory:
$ rspec --init
create spec/spec_helper.rb
create .rspec
require 'infrataster/rspec' and define target servers for testing in spec/spec_helper.rb:
# spec/spec_helper.rb
require 'infrataster/rspec'
Infrataster::Server.define(
:proxy, # name
'192.168.33.10', # ip address
vagrant: true # for vagrant VM
)
Infrataster::Server.define(
:app, # name
'172.16.33.11', # ip address
vagrant: true, # for vagrant VM
from: :proxy # access to this machine via SSH port forwarding from proxy
)
Infrataster::Server.define(
:db, # name
'172.16.33.12', # ip address
vagrant: true, # for vagrant VM
from: :app, # access to this machine via SSH port forwarding from app
mysql: {user: 'app', password: 'app'}
# settings for MySQL
)
If you use capybara, you should download and extract BrowserMob Proxy and set Infrataster::BrowsermobProxy.bin_path to binary path in spec/spec_helper.rb:
# spec/spec_helper.rb
Infrataster::BrowsermobProxy.bin_path = '/path/to/browsermob/bin/browsermob'
Then, you can write spec files:
# spec/example_spec.rb
require 'spec_helper'
describe server(:app) do
describe http('http://app') do
it "responds content including 'Hello Sinatra'" do
expect(response.body).to include('Hello Sinatra')
end
it "responds as 'text/html'" do
expect(response.header.content_type).to eq('text/html')
end
end
describe ('http://app') do
it "responds content including 'Hello Sinatra'" do
visit '/'
expect(page).to have_content('Hello Sinatra')
end
end
end
describe server(:db) do
describe mysql_query('SHOW STATUS') do
it 'responds uptime' do
row = results.find {|r| r['Variable_name'] == 'Uptime' }
expect(row['Value'].to_i).to be > 0
end
end
end
describe server(:proxy) do
describe http('http://app') do
it "responds content including 'Hello Sinatra'" do
expect(response.body).to include('Hello Sinatra')
end
end
describe http('http://static') do
it "responds content including 'Welcome to nginx!'" do
expect(response.body).to include('Welcome to nginx!')
end
end
describe ('http://app') do
it "responds content including 'Hello Sinatra'" do
visit '/'
expect(page).to have_content('Hello Sinatra')
end
end
describe ('http://static') do
it "responds content including 'Welcome to nginx!'" do
visit '/'
expect(page).to have_content('Welcome to nginx!')
end
end
end
Example
How to Run Tests
Unit Tests
$ bundle exec rake spec:unit
Integration Tests
Start and provision VMs:
$ bundle exec rake spec:integration:prepare
Run tests:
$ bundle exec rake spec:integration
Presentations
Contributing
- Fork it ( http://github.com/ryotarai/infrataster/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