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

last few tests for the night

parent 82be084e
...@@ -39,15 +39,11 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_ ...@@ -39,15 +39,11 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
end end
it "invalid application should not work" do it "invalid application should not work" do
get '/c/badapp' get '/c/badapp'
last_response.should_not be_ok last_response.should be_missing
last_response.status.should == 404
response = last_response.should return_json
end end
it "invalid configuration for application should not work" do it "invalid configuration for application should not work" do
get '/c/badapp/badconfig' get '/c/badapp/badconfig'
last_response.should_not be_ok last_response.should be_missing
last_response.status.should == 404
response = last_response.should return_json
end end
end end
...@@ -78,18 +74,12 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_ ...@@ -78,18 +74,12 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
it "new configuration with missing format should not work" do it "new configuration with missing format should not work" do
config_data = {:body => "a string"}.to_json config_data = {:body => "a string"}.to_json
put '/c/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json" put '/c/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok last_response.should be_invalid
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Missing Parameters"
end end
it "new configuration with missing body should not work" do it "new configuration with missing body should not work" do
config_data = {:body => "a string"}.to_json config_data = {:body => "a string"}.to_json
put '/c/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json" put '/c/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok last_response.should be_invalid
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Missing Parameters"
end end
end end
......
...@@ -66,21 +66,13 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t ...@@ -66,21 +66,13 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
it "host missing name parameter should not work" do it "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 be_invalid
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Missing Parameters"
end end
it "host missing status parameter should not work" do it "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 be_invalid
response = last_response.should return_json
response["result"].should == "failure"
response["error_message"].should == "Missing Parameters"
end end
it "host with invalid status parameter should not work" do it "host with invalid status parameter should not work" do
......
...@@ -7,6 +7,10 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data = ...@@ -7,6 +7,10 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
it "all services should work" it "all services should work"
it "all named services should work" it "all named services should work"
it "named service for host should work" it "named service for host should work"
it "missing service for host should not work" do
get '/s/foobar/baz'
last_response.should be_missing
end
end end
describe "PUT" do describe "PUT" do
...@@ -19,8 +23,27 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data = ...@@ -19,8 +23,27 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
end end
describe "DELETE" do describe "DELETE" do
it "existing host should work" before(:all) do
it "invalid host should not work" @h = Host.create(:name => "h1", :status => "up")
@h.services << Service.create(:name => "s1", :status => "up", :host => @h)
@h.save
@s = @h.services.first
end
it "existing host should work" do
delete "/s/#{@s.name}/#{@h.name}"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
response["action"].should == "delete"
response["id"].should == @s.id
response["host"].should == @h.name
response["service"].should == @s.name
end
it "invalid host should not work" do
delete "/s/#{@s.name}/#{@h.name}"
last_response.should be_missing
end
end end
end end
......
...@@ -92,4 +92,13 @@ RSpec::Matchers.define :be_missing do ...@@ -92,4 +92,13 @@ RSpec::Matchers.define :be_missing do
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
RSpec::Matchers.define :be_invalid do
match do |last_response|
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
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