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
def to_hash
arr = []
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
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')
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
get '/h'
last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json"
end
describe "calling" do
it "GET /h/localhost" do
get '/h/localhost'
last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json"
host = JSON.parse(last_response.body)
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 "GET /h should work" do
get '/h'
last_response.should be_ok
last_response.should return_json
end
it "PUT /h/:hostname - new host" 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
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 "GET existing host should work" do
get '/h/localhost'
last_response.should be_ok
response = last_response.should return_json
it "PUT /h/:hostname - existing host" do
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
services = response["services"]
it "PUT /h/:hostname - missing name parameter" do
host_data = {:status => "pending"}.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 == "Missing Parameters"
end
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 "PUT /h/:hostname - missing status parameter" 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
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 "GET existing host's service should work" do
get '/h/localhost/noah'
last_response.should be_ok
response = last_response.should return_json
it "DELETE /h/:hostname - existing host" 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
last_response.headers["Content-Type"].should == "application/json"
response = JSON.parse(last_response.body)
response["result"].should == "success"
response["id"].should == h.id
response["name"].should == "localhost"
response["service_count"].should == svc_size.to_s
end
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
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
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|
config.formatter = "documentation"
config.before(: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
Ohm::redis.flushdb
h = Host.create(:name => 'localhost', :status => "up")
......@@ -71,3 +72,10 @@ end
def app
NoahApp
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