Commit 6d5e76c0 authored by John E. Vincent's avatar John E. Vincent

new pending specs

parent c762688d
...@@ -23,7 +23,8 @@ class Host < Ohm::Model ...@@ -23,7 +23,8 @@ class Host < Ohm::Model
def to_hash def to_hash
arr = [] arr = []
services.sort.each {|s| arr << s.to_hash} services.sort.each {|s| arr << s.to_hash}
super.merge(:name => name, :status => status, :updated_at => updated_at, :services => arr) h = {:name => name, :status => status, :created_at => created_at, :updated_at => updated_at, :services => arr}
super.merge(h)
end end
def is_new? def is_new?
......
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Using the Application API", :reset_redis => false, :populate_sample_data => true do
describe "calling" do
describe "GET" do
it "all applications should work"
it "named application should work"
it "named configuration for application should work"
it "named configuration should work with mime-type"
it "invalud application should not work"
it "invalid configuration for application should not work"
end
describe "PUT" do
it "new application should work"
it "new application with missing name should not work"
it "existing application should work"
end
describe "DELETE" do
it "existing application should work"
it "invalid application should not work"
end
end
end
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Using the Configuration API", :reset_redis => false, :populate_sample_data => true do
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"
end
describe "PUT" do
it "new configuration should work"
it "existing configuration should work"
it "new configuration with missing format should not work"
it "new configuration with missing body should not work"
end
describe "DELETE" do
it "existing configuration should work"
it "invalid configuration should not work"
end
end
end
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "NoahApp Host API", :reset_redis => false, :populate_sample_data => true do describe "Using the Host API", :reset_redis => false, :populate_sample_data => true do
it "GET /h" do describe "calling" do
get '/h'
last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json"
end
it "GET /h/localhost" do it "GET /h should work" do
get '/h/localhost' get '/h'
last_response.should be_ok last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json" last_response.should return_json
host = JSON.parse(last_response.body) end
services = host["services"]
host["name"].should == "localhost"
host["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 /h/localhost/noah" do
get '/h/localhost/noah'
last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json"
service = JSON.parse(last_response.body)
service["name"].should == "noah"
service["status"].should == "up"
service["host"].should == "localhost"
end
it "PUT /h/:hostname - new host" do it "GET existing host should work" do
host_data = {:name => "host99.domain.com", :status => "down"}.to_json get '/h/localhost'
put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json" last_response.should be_ok
last_response.should be_ok response = last_response.should return_json
last_response.headers["Content-Type"].should == "application/json"
response = JSON.parse(last_response.body)
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 "PUT /h/:hostname - existing host" do services = response["services"]
sleep 3
host_data = {:name => "localhost", :status => "pending"}.to_json
put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json"
response = JSON.parse(last_response.body)
response["new_record"].should == false
end
it "PUT /h/:hostname - missing name parameter" do response["name"].should == "localhost"
host_data = {:status => "pending"}.to_json response["status"].should == "up"
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json" services.size.should == 2
last_response.should_not be_ok services.first["name"].should == "redis"
last_response.headers["Content-Type"].should == "application/json" services.first["status"].should == "up"
response = JSON.parse(last_response.body) services.first["host"].should == "localhost"
response["result"].should == "failure" services.last["name"].should == "noah"
response["error_message"].should == "Missing Parameters" services.last["status"].should == "up"
end services.last["host"].should == "localhost"
end
it "PUT /h/:hostname - missing status parameter" do it "GET existing host's service should work" do
host_data = {:name => "host100.domain.com"}.to_json get '/h/localhost/noah'
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json" last_response.should be_ok
last_response.should_not be_ok response = last_response.should return_json
last_response.headers["Content-Type"].should == "application/json"
response = JSON.parse(last_response.body)
response["result"].should == "failure"
response["error_message"].should == "Missing Parameters"
end
it "PUT /h/:hostname - invalid status parameter" 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
last_response.headers["Content-Type"].should == "application/json"
response = JSON.parse(last_response.body)
response["result"].should == "failure"
response["error_message"].should == "[[:status, :not_member]]"
end
it "DELETE /h/:hostname - existing host" do response["name"].should == "noah"
h = Host.find(:name => "localhost").first response["status"].should == "up"
svc_size = h.services.size response["host"].should == "localhost"
host_data = {:name => "localhost"} end
delete '/h/localhost', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok it "PUT new host should work" do
last_response.headers["Content-Type"].should == "application/json" host_data = {:name => "host99.domain.com", :status => "down"}.to_json
response = JSON.parse(last_response.body) put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
response["result"].should == "success" last_response.should be_ok
response["id"].should == h.id response = last_response.should return_json
response["name"].should == "localhost"
response["service_count"].should == svc_size.to_s response["result"].should == "success"
end response["id"].nil?.should == false
response["name"].should == "host99.domain.com"
response["status"].should == "down"
response["new_record"].should == true
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"
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"
end
it "DELETE /h/:hostname - invalid host" 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 = JSON.parse(last_response.body)
response["result"].should == "failure"
response["error_message"].should == "Resource not found"
end end
end end
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Using the Service API", :reset_redis => false, :populate_sample_data => true do
describe "calling" do
describe "GET" do
it "all services should work"
it "all named services should work"
it "named service for host should work"
end
describe "PUT" do
it "new service should work"
it "new service without host should not work"
it "new service with invalid status should not work"
it "new service with missing name should not work"
it "new service with missing status should not work"
it "existing service should work"
end
describe "DELETE" do
it "existing host should work"
it "invalid host should not work"
end
end
end
...@@ -19,6 +19,7 @@ RSpec.configure do |config| ...@@ -19,6 +19,7 @@ RSpec.configure do |config|
config.formatter = "documentation" config.formatter = "documentation"
config.before(:each, :reset_redis => true) { Ohm::redis.flushdb } config.before(:each, :reset_redis => true) { Ohm::redis.flushdb }
config.after(:each, :reset_redis => true) {Ohm::redis.flushdb } config.after(:each, :reset_redis => true) {Ohm::redis.flushdb }
config.after(:all, :populate_sample_data => true) {Ohm::redis.flushdb }
config.before(:all, :populate_sample_data => true) do config.before(:all, :populate_sample_data => true) do
Ohm::redis.flushdb Ohm::redis.flushdb
h = Host.create(:name => 'localhost', :status => "up") h = Host.create(:name => 'localhost', :status => "up")
...@@ -71,3 +72,10 @@ end ...@@ -71,3 +72,10 @@ end
def app def app
NoahApp NoahApp
end end
RSpec::Matchers.define :return_json do |attribute|
match do |last_response|
last_response.headers["Content-Type"].should == "application/json"
response = JSON.parse(last_response.body)
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