Commit 4f1941f3 authored by John E. Vincent's avatar John E. Vincent

autotest and more specs

parent 6d5e76c0
require 'autotest/growl'
Autotest.add_hook(:initialize) {|at|
at.add_exception %r{^\.git} # ignore Version Control System
at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
at.clear_mappings # take out the default (test/test*rb)
at.add_mapping(%r{^noah\.rb$}) {|f, _|
Dir['spec/**/*.rb']
}
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
Dir['spec/**/*.rb']
}
nil
}
......@@ -10,6 +10,9 @@ group :development do
gem "rspec", "= 2.4.0"
gem "rcov", "= 0.9.9"
gem "rack-test", "= 0.5.7", :require => "rack/test"
gem "ZenTest", "= 4.4.2"
gem "autotest", "= 4.4.6"
gem "autotest-growl", "= 0.2.9", :require => "autotest/growl"
end
platforms :mri do
gem "yajl-ruby", "= 0.7.9", :require => "yajl"
......
GEM
remote: http://rubygems.org/
specs:
ZenTest (4.4.2)
autotest (4.4.6)
ZenTest (>= 4.4.1)
autotest-growl (0.2.9)
backports (1.18.2)
bouncy-castle-java (1.5.0145.2)
diff-lcs (1.1.2)
......@@ -64,6 +68,9 @@ PLATFORMS
ruby
DEPENDENCIES
ZenTest (= 4.4.2)
autotest (= 4.4.6)
autotest-growl (= 0.2.9)
haml (= 3.0.25)
jruby-openssl (= 0.7.3)
json-jruby (= 1.4.6)
......
Autotest.add_discovery { "rspec2" }
......@@ -252,7 +252,8 @@ class NoahApp < Sinatra::Base
content_type_mapping = {
:yaml => "text/x-yaml",
:json => "application/json",
:xml => "text/xml"
:xml => "text/xml",
:string => "text/plain"
}
get '/:appname/:element/?' do |appname, element|
......
......@@ -4,12 +4,51 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
describe "calling" do
describe "GET" do
it "all configurations should work"
it "named application should work"
it "named configuration for application should work"
it "named configuration should work with mime-type"
it "invalid application should not work"
it "invalid configuration for application should not work"
it "all configurations should work" do
get '/c'
last_response.should be_ok
last_response.should return_json
end
it "named application should work" do
get '/c/noah'
last_response.should be_ok
response = last_response.should return_json
response.is_a?(Array).should == true
response.first["name"].should == "redis"
response.first["format"].should == "string"
response.first["body"].should == "redis://127.0.0.1:6379/0"
response.first["application"].should == "noah"
end
it "named configuration for application should work" do
get '/c/noah/redis'
last_response.should be_ok
response = last_response.body
response.should == "redis://127.0.0.1:6379/0"
end
it "named configuration should work with mime-type" do
require 'yaml'
get '/c/myrailsapp1/database.yml'
last_response.should be_ok
last_response.headers["Content-Type"].should == "text/x-yaml;charset=utf-8"
response = YAML.load(last_response.body)
response.is_a?(Hash).should == true
response.keys.should == ["development"]
response["development"].keys.should == ["database", "adapter", "username", "password"]
response["development"].values.should == ["development_database", "mysql", "dev_user", "dev_password"]
end
it "invalid application should not work" do
get '/c/badapp'
last_response.should_not be_ok
last_response.status.should == 404
response = last_response.should return_json
end
it "invalid configuration for application should not work" do
get '/c/badapp/badconfig'
last_response.should_not be_ok
last_response.status.should == 404
response = last_response.should return_json
end
end
describe "PUT" do
......
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Using the Host API", :reset_redis => false, :populate_sample_data => true do
describe "calling" do
it "GET /h should work" do
get '/h'
last_response.should be_ok
last_response.should return_json
end
it "GET existing host should work" do
get '/h/localhost'
last_response.should be_ok
response = last_response.should return_json
services = response["services"]
response["name"].should == "localhost"
response["status"].should == "up"
services.size.should == 2
services.first["name"].should == "redis"
services.first["status"].should == "up"
services.first["host"].should == "localhost"
services.last["name"].should == "noah"
services.last["status"].should == "up"
services.last["host"].should == "localhost"
end
it "GET existing host's service should work" do
get '/h/localhost/noah'
last_response.should be_ok
response = last_response.should return_json
response["name"].should == "noah"
response["status"].should == "up"
response["host"].should == "localhost"
end
it "PUT new host should work" do
host_data = {:name => "host99.domain.com", :status => "down"}.to_json
put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
response["id"].nil?.should == false
response["name"].should == "host99.domain.com"
response["status"].should == "down"
response["new_record"].should == true
describe "GET" do
it "all hosts should work" do
get '/h'
last_response.should be_ok
last_response.should return_json
end
it "existing host should work" do
get '/h/localhost'
last_response.should be_ok
response = last_response.should return_json
services = response["services"]
response["name"].should == "localhost"
response["status"].should == "up"
services.size.should == 2
services.first["name"].should == "redis"
services.first["status"].should == "up"
services.first["host"].should == "localhost"
services.last["name"].should == "noah"
services.last["status"].should == "up"
services.last["host"].should == "localhost"
end
it "named service for host should work" do
get '/h/localhost/noah'
last_response.should be_ok
response = last_response.should return_json
response["name"].should == "noah"
response["status"].should == "up"
response["host"].should == "localhost"
end
end
it "PUT existing host should work" do
sleep 3
host_data = {:name => "host99.domain.com", :status => "pending"}.to_json
put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["new_record"].should == false
end
it "PUT host missing name parameter should not work" do
host_data = {:status => "pending"}.to_json
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Missing Parameters"
describe "PUT" do
it "new host should work" do
host_data = {:name => "host99.domain.com", :status => "down"}.to_json
put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
response["id"].nil?.should == false
response["name"].should == "host99.domain.com"
response["status"].should == "down"
response["new_record"].should == true
end
it "existing host should work" do
sleep 3
host_data = {:name => "host99.domain.com", :status => "pending"}.to_json
put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["new_record"].should == false
end
it "host missing name parameter should not work" do
host_data = {:status => "pending"}.to_json
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Missing Parameters"
end
it "host missing status parameter should not work" do
host_data = {:name => "host100.domain.com"}.to_json
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Missing Parameters"
end
it "host with invalid status parameter should not work" do
host_data = {:name => "host100.domain.com", :status => "fscked"}.to_json
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "[[:status, :not_member]]"
end
end
it "PUT host missing status parameter should not work" do
host_data = {:name => "host100.domain.com"}.to_json
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Missing Parameters"
end
it "PUT host with invalid status parameter should not work" do
host_data = {:name => "host100.domain.com", :status => "fscked"}.to_json
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "[[:status, :not_member]]"
end
it "DELETE existing host should work" do
h = Host.find(:name => "localhost").first
svc_size = h.services.size
host_data = {:name => "localhost"}
delete '/h/localhost', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
response["id"].should == h.id
response["name"].should == "localhost"
response["service_count"].should == svc_size.to_s
end
it "DELETE invalid host should not work" do
host_data = {:name => "invalid_host.asdf.com"}
delete '/h/invalid_host.asdf.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
last_response.status.should == 404
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Resource not found"
describe "DELETE" do
it "existing host should work" do
h = Host.find(:name => "localhost").first
svc_size = h.services.size
host_data = {:name => "localhost"}
delete '/h/localhost', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
response["id"].should == h.id
response["name"].should == "localhost"
response["service_count"].should == svc_size.to_s
end
it "invalid host should not work" do
host_data = {:name => "invalid_host.asdf.com"}
delete '/h/invalid_host.asdf.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
last_response.status.should == 404
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Resource not found"
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment