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
it "GET /h should work" do
get '/h' 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
end end
it "GET /h/localhost" do it "GET existing host should work" do
get '/h/localhost' get '/h/localhost'
last_response.should be_ok last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json" response = last_response.should return_json
host = JSON.parse(last_response.body)
services = host["services"] services = response["services"]
host["name"].should == "localhost" response["name"].should == "localhost"
host["status"].should == "up" response["status"].should == "up"
services.size.should == 2 services.size.should == 2
services.first["name"].should == "redis" services.first["name"].should == "redis"
services.first["status"].should == "up" services.first["status"].should == "up"
...@@ -26,22 +28,22 @@ describe "NoahApp Host API", :reset_redis => false, :populate_sample_data => tru ...@@ -26,22 +28,22 @@ describe "NoahApp Host API", :reset_redis => false, :populate_sample_data => tru
services.last["host"].should == "localhost" services.last["host"].should == "localhost"
end end
it "GET /h/localhost/noah" do it "GET existing host's service should work" do
get '/h/localhost/noah' get '/h/localhost/noah'
last_response.should be_ok last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json" response = last_response.should return_json
service = JSON.parse(last_response.body)
service["name"].should == "noah" response["name"].should == "noah"
service["status"].should == "up" response["status"].should == "up"
service["host"].should == "localhost" response["host"].should == "localhost"
end end
it "PUT /h/:hostname - new host" do it "PUT new host should work" do
host_data = {:name => "host99.domain.com", :status => "down"}.to_json host_data = {:name => "host99.domain.com", :status => "down"}.to_json
put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json" put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json" response = last_response.should return_json
response = JSON.parse(last_response.body)
response["result"].should == "success" response["result"].should == "success"
response["id"].nil?.should == false response["id"].nil?.should == false
response["name"].should == "host99.domain.com" response["name"].should == "host99.domain.com"
...@@ -49,67 +51,70 @@ describe "NoahApp Host API", :reset_redis => false, :populate_sample_data => tru ...@@ -49,67 +51,70 @@ describe "NoahApp Host API", :reset_redis => false, :populate_sample_data => tru
response["new_record"].should == true response["new_record"].should == true
end end
it "PUT /h/:hostname - existing host" do it "PUT existing host should work" do
sleep 3 sleep 3
host_data = {:name => "localhost", :status => "pending"}.to_json host_data = {:name => "host99.domain.com", :status => "pending"}.to_json
put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json" put '/h/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json" response = last_response.should return_json
response = JSON.parse(last_response.body)
response["new_record"].should == false response["new_record"].should == false
end end
it "PUT /h/:hostname - missing name parameter" do it "PUT host missing name parameter should not work" do
host_data = {:status => "pending"}.to_json host_data = {:status => "pending"}.to_json
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json" put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok last_response.should_not be_ok
last_response.headers["Content-Type"].should == "application/json" response = last_response.should return_json
response = JSON.parse(last_response.body)
response["result"].should == "failure" response["result"].should == "failure"
response["error_message"].should == "Missing Parameters" response["error_message"].should == "Missing Parameters"
end end
it "PUT /h/:hostname - missing status parameter" do it "PUT host missing status parameter should not work" do
host_data = {:name => "host100.domain.com"}.to_json host_data = {:name => "host100.domain.com"}.to_json
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json" put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok last_response.should_not be_ok
last_response.headers["Content-Type"].should == "application/json" response = last_response.should return_json
response = JSON.parse(last_response.body)
response["result"].should == "failure" response["result"].should == "failure"
response["error_message"].should == "Missing Parameters" response["error_message"].should == "Missing Parameters"
end end
it "PUT /h/:hostname - invalid status parameter" do it "PUT host with invalid status parameter should not work" do
host_data = {:name => "host100.domain.com", :status => "fscked"}.to_json host_data = {:name => "host100.domain.com", :status => "fscked"}.to_json
put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json" put '/h/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok last_response.should_not be_ok
last_response.headers["Content-Type"].should == "application/json" response = last_response.should return_json
response = JSON.parse(last_response.body)
response["result"].should == "failure" response["result"].should == "failure"
response["error_message"].should == "[[:status, :not_member]]" response["error_message"].should == "[[:status, :not_member]]"
end end
it "DELETE /h/:hostname - existing host" do it "DELETE existing host should work" do
h = Host.find(:name => "localhost").first h = Host.find(:name => "localhost").first
svc_size = h.services.size svc_size = h.services.size
host_data = {:name => "localhost"} host_data = {:name => "localhost"}
delete '/h/localhost', host_data, "CONTENT_TYPE" => "application/json" delete '/h/localhost', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok last_response.should be_ok
last_response.headers["Content-Type"].should == "application/json" response = last_response.should return_json
response = JSON.parse(last_response.body)
response["result"].should == "success" response["result"].should == "success"
response["id"].should == h.id response["id"].should == h.id
response["name"].should == "localhost" response["name"].should == "localhost"
response["service_count"].should == svc_size.to_s response["service_count"].should == svc_size.to_s
end end
it "DELETE /h/:hostname - invalid host" do it "DELETE invalid host should not work" do
host_data = {:name => "invalid_host.asdf.com"} host_data = {:name => "invalid_host.asdf.com"}
delete '/h/invalid_host.asdf.com', host_data, "CONTENT_TYPE" => "application/json" delete '/h/invalid_host.asdf.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok last_response.should_not be_ok
last_response.status.should == 404 last_response.status.should == 404
response = JSON.parse(last_response.body) response = last_response.should return_json
response["result"].should == "failure" response["result"].should == "failure"
response["error_message"].should == "Resource not found" response["error_message"].should == "Resource not found"
end 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