Created
November 28, 2011 19:25
-
-
Save joemiller/1401633 to your computer and use it in GitHub Desktop.
infrastructure smoketest example (rspec)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
# simple wrapper around open-uri's open() that will | |
# fetch an HTTP or HTTPS resource including follow redirects. | |
# Returns a hash with 2 members: | |
# | |
# response[:meta] = the original open-uri response object. Use this to | |
# access metadata such as status code. See | |
# http://ruby-doc.org/stdlib-1.9.2/libdoc/open-uri/rdoc/OpenURI/Meta.html | |
# for a list of attributes and methods available. | |
# response[:body] = the response content as string | |
# | |
def get(url) | |
r = {} | |
resp = open(url) | |
r[:meta] = resp | |
r[:body] = resp.read | |
return r | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_processes_matching_regex( regex ) | |
cnt = 0 | |
`ps auxw`.split("\n").each do |l| | |
cnt += 1 if l.match regex | |
end | |
return cnt | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'spec_helper')) | |
describe "role: sms_gateway smoketests" do | |
it "should have a 1 process running with the words 'java' and 'sms-gateway'" do | |
count_processes_matching_regex( /java.+sms-gateway/ ).should == 1 | |
end | |
it "should be listening via http on port 5555" do | |
r = get( "http://localhost:5555/sms-gateway/" ) | |
r[:body].should include 'pageok' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment