Skip to content

Commit

Permalink
Add unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
arioch committed May 25, 2012
1 parent 3c47bce commit 62a8c22
Show file tree
Hide file tree
Showing 16 changed files with 636 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ clean:

build:
bash build.sh

vagrant-build:
cd vagrant && vagrant ssh -c 'cd build; make'

vagrant-validate:
cd vagrant && cucumber
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ A script to build packages yourself is included as well.

* [FPM](https://github.com/jordansissel/fpm)
* Ruby (for FPM)
* rpmbuild
* rpmbuild


### Usage

Expand All @@ -30,15 +31,32 @@ Debian:

### Optional

* Jenkins

In order to have Jenkins to build your packages simply add a new command shell build directive, with the following content:

make


* Vagrant

An example Vagrant project has been included to get you started right away.

cd vagrant
vagrant up
vagrant ssh
cd build
make
make vagrant-build


* Unit testing

(work in progress)<br>
This requires cucumber to be installed on your workstation.

cd vagrant
vagrant up
make vagrant-validate



### Available plugins

Expand Down Expand Up @@ -173,7 +191,10 @@ Guidelines:
- Fork this repository
- Add plugin script to the repository
- Add plugin details to build.txt
- Add plugin name to vagrant/features/build.feature
- # make vagrant-validate
- Update author table in README.md
- Send a pull request
- ...
- Profit!

51 changes: 51 additions & 0 deletions vagrant/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
AVAILABLE BOXES:
--

Debian 6
CentOS 6


UPDATE REPOSITORIES:
--

$ cd /usr/src/puppet/
$ git checkout master
$ git pull

$ cd /usr/src/facter/
$ git checkout master
$ git pull


EXAMPLE USAGE:
--

$ cd /usr/src/puppet/
$ git checkout tags/2.7.2
$ puppet --version
2.7.2

$ cd /usr/src/puppet/
$ git checkout tags/2.6.2
$ puppet --version
2.6.2

$ cd /usr/src/puppet/
$ git checkout tags/2.7.14
$ puppet --version
2.7.9

$ cd /usr/src/facter/
$ git checkout tags/1.6.8
$ facter --version
1.6.0

$ cd /usr/src/facter/
$ git checkout tags/1.5.4
$ facter --version
1.5.4

$ cd /usr/src/facter/
$ git checkout tags/1.6.2
$ facter --version
1.6.2
35 changes: 35 additions & 0 deletions vagrant/features/build.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: Build tests

Scenario: Connect to vagrant
When I run 'vagrant ssh -c "uptime"'
Then 'stdout' should have 'load average'
Then it should exit '0'

Scenario: Build monkey, build!
When I run 'vagrant ssh -c "cd build; make"'
Then it should exit '0'
Then 'stdout' should have 'Entering directory'
Then 'stdout' should have 'Build package: check_apache-auto.pl'
Then 'stdout' should have 'Build package: check_bacula'
Then 'stdout' should have 'Build package: check_drbd'
Then 'stdout' should have 'Build package: check_iostat'
Then 'stdout' should have 'Build package: check_linux-procstat.pl'
Then 'stdout' should have 'Build package: check_linux-stats.pl'
Then 'stdout' should have 'Build package: check_mem.pl'
Then 'stdout' should have 'Build package: check_memcached.pl'
Then 'stdout' should have 'Build package: check_mysqld.pl'
Then 'stdout' should have 'Build package: check_postfix-mailqueue'
Then 'stdout' should have 'Build package: check_puppet.rb'
Then 'stdout' should have 'Build package: pmp-check-lvm-snapshots'
Then 'stdout' should have 'Build package: pmp-check-mysql-deadlocks'
Then 'stdout' should have 'Build package: pmp-check-mysql-deleted-files'
Then 'stdout' should have 'Build package: pmp-check-mysql-file-privs'
Then 'stdout' should have 'Build package: pmp-check-mysql-innodb'
Then 'stdout' should have 'Build package: pmp-check-mysql-pidfile'
Then 'stdout' should have 'Build package: pmp-check-mysql-processlist'
Then 'stdout' should have 'Build package: pmp-check-mysql-replication-delay'
Then 'stdout' should have 'Build package: pmp-check-mysql-replication-running'
Then 'stdout' should have 'Build package: pmp-check-mysql-status'
Then 'stdout' should have 'Build package: pmp-check-pt-table-checksum'
Then 'stdout' should have 'Build package: pmp-check-unix-memory'

59 changes: 59 additions & 0 deletions vagrant/features/steps/amqp_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'mq'

# simple function to get at the number of messages on a queue and the
# number of consumers using it and store them in variables for later use
def get_details_of_queue(queue, host)
AMQP.start(:host => host) do
jobs = MQ.queue(queue)
jobs.status do |msgs, cns|
@messages = msgs
@count = cns
end
AMQP.stop{ EM.stop }
end
end

# set up some defaults so we can compare numbers without
# raising exceptions
Before do
@messages = 0
@consumers = 0
end

# Step definitions for testing various conditions on the queue
Given /I have a AMQP server on (.+)$/ do |host|
@host = host
end

And /I want to check on the (\w+) queue$/ do |queue|
get_details_of_queue(queue, @host)
end

Then /it should have less than (\d+) messages per consumer$/ do |messages|
@consumers.should > 0
messages.to_i.should < @messages/@consumers
end

Then /it should have less than (\d+) messages$/ do |messages|
@messages.should < messages.to_i
end

Then /it should have at least (\d+) messages$/ do |messages|
@messages.should >= messages.to_i
end

Then /it should have more than (\d+) messages$/ do |messages|
@messages.should > messages.to_i
end

Then /It should have more than (\d+) consumers$/ do |consumers|
@consumers.should > consumers.to_i
end

Then /It should have less than (\d+) consumers$/ do |consumers|
@consumers.should < consumers.to_i
end

Then /It should have (\d+) consumers$/ do |consumers|
@consumers.should == consumers.to_i
end
8 changes: 8 additions & 0 deletions vagrant/features/steps/benchmark_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Given /^I am benchmarking$/ do
@scenario_start_time = Time.now
end

Then /^the elapsed time should be less than (\d+) seconds$/ do |time|
(@scenario_start_time - Time.now).should > time.to_i * -1
end

80 changes: 80 additions & 0 deletions vagrant/features/steps/command_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Portions of this file originally from Chef (github.com/opscode/chef)

When /^I run '(.+)'$/ do |cmd|
status = Cucumber::Nagios::Command.popen4(cmd) do |p, i, o, e|
@stdout = o.gets(nil)
@stderr = e.gets(nil)
end
@status = status
end

###
# Then
###
Then /^it should exit '(.+)'$/ do |exit_code|
begin
@status.exitstatus.should eql(exit_code.to_i)
rescue
print_output
raise
end
end

Then /^it should exit from being signaled$/ do
begin
@status.signaled?.should == true
rescue
print_output
raise
end
end

def print_output
puts "--- run stdout:"
puts @stdout
puts "--- run stderr:"
puts @stderr
end

# Then 'stdout' should have 'foo'
Then /^'(.+)' should have '(.+)'$/ do |which, to_match|
self.instance_variable_get("@#{which}".to_sym).should match(/#{to_match}/m)
end

# Then 'stderr' should not have 'foo'
Then /^'(.+)' should not have '(.+)'$/ do |which, to_match|
self.instance_variable_get("@#{which}".to_sym).should_not match(/#{to_match}/m)
end

# Then 'my dog ate my homework' should appear on 'stdout' '5' times
Then /^'(.+)' should appear on '(.+)' '(.+)' times$/ do |to_match, which, count|
seen_count = 0
self.instance_variable_get("@#{which}".to_sym).split("\n").each do |line|
seen_count += 1 if line =~ /#{to_match}/
end
seen_count.should == count.to_i
end

17 changes: 17 additions & 0 deletions vagrant/features/steps/dns_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
When /^I lookup "([^\"]*)"$/ do |name|
s = Socket.getaddrinfo(name, nil)
@ip = s[0][3]
end

When /^I reverse lookup "([^\"]*)"$/ do |ip|
s = Socket.getaddrinfo(ip, nil)
@name = s[0][2]
end

Then /^the name should resolve to "([^\"]*)"$/ do |ip|
@ip.should == ip
end

Then /^the IP should resolve to "([^\"]*)"$/ do |name|
@name.downcase.should == name.downcase
end
Loading

0 comments on commit 62a8c22

Please sign in to comment.