Commit 41913163 authored by John E. Vincent's avatar John E. Vincent

refactor routes (minus ephemerals) to match patterns

parent 88e0d993
module Noah
PROTECTED_PATHS = %w[a c h s w]
PROTECTED_PATHS = %w[applications configurations hosts services watches]
end
begin
require 'yajl'
......
class Noah::App
# Application URIs
get '/a/:appname/:config/?' do |appname, config|
get '/applications/:appname/:config/?' do |appname, config|
app = Noah::Application.find(:name => appname).first
if app.nil?
halt 404
......@@ -10,7 +10,7 @@ class Noah::App
end
end
get '/a/:appname/?' do |appname|
get '/applications/:appname/?' do |appname|
app = Noah::Application.find(:name => appname).first
if app.nil?
halt 404
......@@ -19,7 +19,7 @@ class Noah::App
end
end
put '/a/:appname/watch' do |appname|
put '/applications/:appname/watch' do |appname|
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (a = Noah::Application.find(:name => appname).first) : (raise "Missing Parameters")
......@@ -27,7 +27,7 @@ class Noah::App
w.to_json
end
put '/a/:appname/?' do |appname|
put '/applications/:appname/?' do |appname|
required_params = ["name"]
data = JSON.parse(request.body.read)
if data.keys.sort == required_params.sort && data['name'] == appname
......@@ -45,7 +45,7 @@ class Noah::App
end
end
delete '/a/:appname/?' do |appname|
delete '/applications/:appname/?' do |appname|
app = Noah::Application.find(:name => appname).first
if app.nil?
halt 404
......@@ -58,7 +58,7 @@ class Noah::App
end
end
get '/a/?' do
get '/applications/?' do
apps = []
Noah::Application.all.sort.each {|a| apps << a.to_hash}
if apps.empty?
......
......@@ -6,7 +6,7 @@ class Noah::App
:string => "text/plain"
}
# Configuration URIs
get '/c/:appname/:element/?' do |appname, element|
get '/configurations/:appname/:element/?' do |appname, element|
a = Noah::Application.find(:name => appname).first
if a.nil?
halt 404
......@@ -17,7 +17,7 @@ class Noah::App
end
end
get '/c/:appname/?' do |appname|
get '/configurations/:appname/?' do |appname|
config = []
a = Noah::Application.find(:name => appname).first
if a.nil?
......@@ -28,7 +28,7 @@ class Noah::App
end
end
get '/c/?' do
get '/configurations/?' do
configs = []
Noah::Configuration.all.sort.each {|c| configs << c.to_hash}
if configs.empty?
......@@ -38,7 +38,7 @@ class Noah::App
end
end
put '/c/:configname/watch' do |configname|
put '/configurations/:configname/watch' do |configname|
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (c = Noah::Configuration.find(:name => configname).first) : (raise "Missing Parameters")
......@@ -46,7 +46,7 @@ class Noah::App
w.to_json
end
put '/c/:appname/:element?' do |appname, element|
put '/configurations/:appname/:element?' do |appname, element|
app = Noah::Application.find_or_create(:name => appname)
config = Noah::Configuration.find_or_create(:name => element, :application_id => app.id)
required_params = ["format", "body"]
......@@ -63,7 +63,7 @@ class Noah::App
end
end
delete '/c/:appname/:element?' do |appname, element|
delete '/configurations/:appname/:element?' do |appname, element|
app = Noah::Application.find(:name => appname).first
if app
config = Noah::Configuration.find(:name=> element, :application_id => app.id).first
......
......@@ -2,7 +2,7 @@ class Noah::App
# Host URIs
# GET named {Service} for named {Host}
get '/h/:hostname/:servicename/?' do |hostname, servicename|
get '/hosts/:hostname/:servicename/?' do |hostname, servicename|
h = host_service(hostname, servicename)
if h.nil?
halt 404
......@@ -14,7 +14,7 @@ class Noah::App
# GET named {Host}
# @param :hostname name of {Host}
# @return [JSON] representation of {Host}
get '/h/:hostname/?' do |hostname|
get '/hosts/:hostname/?' do |hostname|
h = host(:name => hostname)
if h.nil?
halt 404
......@@ -24,7 +24,7 @@ class Noah::App
end
# GET all {Hosts}
get '/h/?' do
get '/hosts/?' do
hosts.map {|h| h.to_hash}
if hosts.size == 0
halt 404
......@@ -33,7 +33,7 @@ class Noah::App
end
end
put '/h/:hostname/watch' do |hostname|
put '/hosts/:hostname/watch' do |hostname|
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (h = Noah::Host.find(:name => hostname).first) : (raise "Missing Parameters")
......@@ -41,7 +41,7 @@ class Noah::App
w.to_json
end
put '/h/:hostname/?' do |hostname|
put '/hosts/:hostname/?' do |hostname|
required_params = ["name", "status"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort && data['name'] == hostname) ? (host = Noah::Host.find_or_create(:name => data['name'], :status => data['status'])) : (raise "Missing Parameters")
......@@ -53,7 +53,7 @@ class Noah::App
end
end
delete '/h/:hostname/?' do |hostname|
delete '/hosts/:hostname/?' do |hostname|
host = Noah::Host.find(:name => hostname).first
if host
services = []
......
......@@ -2,7 +2,7 @@ class Noah::App
# Service URIs
# get named {Service} for named {Host}
get '/s/:servicename/:hostname/?' do |servicename, hostname|
get '/services/:servicename/:hostname/?' do |servicename, hostname|
hs = host_service(hostname, servicename)
if hs.nil?
halt 404
......@@ -11,7 +11,7 @@ class Noah::App
end
end
get '/s/:servicename/?' do |servicename|
get '/services/:servicename/?' do |servicename|
s = services(:name => servicename)
s.map {|x| x.to_hash}
if s.empty?
......@@ -21,7 +21,7 @@ class Noah::App
end
end
get '/s/?' do
get '/services/?' do
if services.empty?
halt 404
else
......@@ -30,7 +30,7 @@ class Noah::App
end
end
put '/s/:servicename/watch' do |servicename|
put '/services/:servicename/watch' do |servicename|
required_params = ["endpoint"]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (s = Noah::Service.find(:name => servicename).first) : (raise "Missing Parameters")
......@@ -38,7 +38,7 @@ class Noah::App
w.to_json
end
put '/s/:servicename/?' do |servicename|
put '/services/:servicename/?' do |servicename|
required_params = ["status", "host", "name"]
data = JSON.parse(request.body.read)
if data.keys.sort == required_params.sort
......@@ -57,7 +57,7 @@ class Noah::App
end
end
delete '/s/:servicename/:hostname/?' do |servicename, hostname|
delete '/services/:servicename/:hostname/?' do |servicename, hostname|
host = Noah::Host.find(:name => hostname).first || (halt 404)
service = Noah::Service.find(:name => servicename, :host_id => host.id).first || (halt 404)
if host && service
......
class Noah::App
get '/w/:name' do |name|
get '/watches/:name' do |name|
w = Noah::Watcher.find_by_name(name)
w.nil? ? (halt 404) : w.to_json
end
get '/w/?' do
get '/watches/?' do
w = Noah::Watcher.all.sort_by(:pattern)
if w.size == 0
halt 404
......@@ -14,7 +14,7 @@ class Noah::App
end
end
put '/w/?' do
put '/watches/?' do
required_params = %w[endpoint pattern]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (pattern, endpoint = data['pattern'],data['endpoint']) : (raise "Missing Parameters")
......@@ -28,7 +28,7 @@ class Noah::App
end
end
delete '/w/?' do
delete '/watches/?' do
required_params = %w[endpoint pattern]
data = JSON.parse(request.body.read)
(data.keys.sort == required_params.sort) ? (pattern, endpoint = data['pattern'],data['endpoint']) : (raise "Missing Parameters")
......
......@@ -11,13 +11,13 @@ describe "Using the Application API", :reset_redis => false do
describe "GET" do
it "all applications should work" do
get '/a'
get '/applications'
last_response.should be_ok
response = last_response.should return_json
response.is_a?(Array).should == true
end
it "named application should work" do
get '/a/rspec_sample_app'
get '/applications/rspec_sample_app'
last_response.should be_ok
response = last_response.should return_json
......@@ -30,7 +30,7 @@ describe "Using the Application API", :reset_redis => false do
c["format"].should == @c.format
end
it "named configuration for application should work" do
get "/a/#{@a.name}/#{@c.name}"
get "/applications/#{@a.name}/#{@c.name}"
last_response.should be_ok
response = last_response.should return_json
......@@ -41,11 +41,11 @@ describe "Using the Application API", :reset_redis => false do
response["application"].should == @a.name
end
it "invalid application should not work" do
get "/a/should_not_exist"
get "/applications/should_not_exist"
last_response.should be_missing
end
it "invalid configuration for application should not work" do
get "/a/should_not_exist/should_not_exist"
get "/applications/should_not_exist/should_not_exist"
last_response.should be_missing
end
end
......@@ -55,7 +55,7 @@ describe "Using the Application API", :reset_redis => false do
@appdata = {:name => "should_now_exist"}
end
it "new application should work" do
put "/a/#{@appdata[:name]}", @appdata.to_json, "CONTENT_TYPE" => "application/json"
put "/applications/#{@appdata[:name]}", @appdata.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
......@@ -66,13 +66,13 @@ describe "Using the Application API", :reset_redis => false do
Noah::Application.find(:name => @appdata[:name]).first.is_new?.should == true
end
it "new application with missing name should not work" do
put "/a/should_not_work", '{"foo":"bar"}', "CONTENT_TYPE" => "application/json"
put "/applications/should_not_work", '{"foo":"bar"}', "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
it "existing application should work" do
sleep 3
put "/a/#{@appdata[:name]}", @appdata.to_json, "CONTENT_TYPE" => "application/json"
put "/applications/#{@appdata[:name]}", @appdata.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
......@@ -89,7 +89,7 @@ describe "Using the Application API", :reset_redis => false do
@appdata = {:name => "should_now_exist"}
end
it "existing application should work" do
delete "/a/#{@appdata[:name]}"
delete "/applications/#{@appdata[:name]}"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
......@@ -99,7 +99,7 @@ describe "Using the Application API", :reset_redis => false do
response["configurations"].should == "0"
end
it "invalid application should not work" do
delete "/a/should_not_work"
delete "/applications/should_not_work"
last_response.should be_missing
end
end
......
......@@ -5,12 +5,12 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
describe "GET" do
it "all configurations should work" do
get '/c'
get '/configurations'
last_response.should be_ok
last_response.should return_json
end
it "named application should work" do
get '/c/noah'
get '/configurations/noah'
last_response.should be_ok
response = last_response.should return_json
......@@ -21,14 +21,14 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
response.first["application"].should == "noah"
end
it "named configuration for application should work" do
get '/c/noah/redis'
get '/configurations/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'
get '/configurations/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)
......@@ -38,11 +38,11 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
response["development"].values.sort.should == ["dev_password", "dev_user", "development_database", "mysql"]
end
it "invalid application should not work" do
get '/c/badapp'
get '/configurations/badapp'
last_response.should be_missing
end
it "invalid configuration for application should not work" do
get '/c/badapp/badconfig'
get '/configurations/badapp/badconfig'
last_response.should be_missing
end
end
......@@ -50,7 +50,7 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
describe "PUT" do
it "new configuration should work" do
config_data = {:format => "string", :body => "sample_config_entry"}.to_json
put '/c/newapp/newconfig', config_data, "CONTENT_TYPE" => "application/json"
put '/configurations/newapp/newconfig', config_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
......@@ -62,7 +62,7 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
it "existing configuration should work" do
config_data = {:format => "string", :body => "sample_config_entry"}.to_json
sleep 3
put '/c/newapp/newconfig', config_data, "CONTENT_TYPE" => "application/json"
put '/configurations/newapp/newconfig', config_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
......@@ -73,12 +73,12 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
end
it "new configuration with missing format should not work" do
config_data = {:body => "a string"}.to_json
put '/c/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json"
put '/configurations/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
it "new configuration with missing body should not work" do
config_data = {:body => "a string"}.to_json
put '/c/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json"
put '/configurations/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
end
......@@ -93,7 +93,7 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
end
it "existing configuration should work" do
delete "/c/#{@a.name}/#{@c.name}"
delete "/configurations/#{@a.name}/#{@c.name}"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
......@@ -103,7 +103,7 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
response["item"].should == @c.name
end
it "invalid configuration should not work" do
delete "/c/#{@a.name}/#{@c.name}"
delete "/configurations/#{@a.name}/#{@c.name}"
last_response.should be_missing
end
end
......
......@@ -5,13 +5,13 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
describe "GET" do
it "all hosts should work" do
get '/h'
get '/hosts'
last_response.should be_ok
last_response.should return_json
end
it "existing host should work" do
get '/h/localhost'
get '/hosts/localhost'
last_response.should be_ok
response = last_response.should return_json
......@@ -29,7 +29,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
end
it "named service for host should work" do
get '/h/localhost/noah'
get '/hosts/localhost/noah'
last_response.should be_ok
response = last_response.should return_json
......@@ -42,7 +42,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
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"
put '/hosts/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
......@@ -56,7 +56,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
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"
put '/hosts/host99.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
......@@ -65,19 +65,19 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
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"
put '/hosts/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
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"
put '/hosts/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
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"
put '/hosts/host100.domain.com', host_data, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
......@@ -96,7 +96,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
end
it "existing host should work" do
svc_size = @h.services.size
delete "/h/#{@h.name}"
delete "/hosts/#{@h.name}"
last_response.should be_ok
response = last_response.should return_json
......@@ -107,7 +107,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
end
it "invalid host should not work" do
delete "/h/#{@h.name}"
delete "/hosts/#{@h.name}"
last_response.should be_missing
end
end
......
......@@ -13,13 +13,13 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
describe "GET" do
it "all services should work" do
get '/s'
get '/services'
last_response.should be_ok
response = last_response.should return_json
response.is_a?(Array).should == true
end
it "all named services should work" do
get "/s/#{@sample_service[:name]}"
get "/services/#{@sample_service[:name]}"
last_response.should be_ok
response = last_response.should return_json
response.is_a?(Array).should == true
......@@ -30,7 +30,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
s["host"].should == @h.name
end
it "named service for host should work" do
get "/s/#{@sample_service[:name]}/#{@sample_host[:name]}"
get "/services/#{@sample_service[:name]}/#{@sample_host[:name]}"
last_response.should be_ok
response = last_response.should return_json
response["id"].should == @s.id
......@@ -39,7 +39,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
response["host"].should == @h.name
end
it "missing service for host should not work" do
get '/s/foobar/baz'
get '/services/foobar/baz'
last_response.should be_missing
end
end
......@@ -49,7 +49,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
@payload = {:name => 'another_rspec_service', :status => 'up', :host => @h.name}
end
it "new service should work" do
put "/s/#{@payload[:name]}/", @payload.to_json, "CONTENT_TYPE" => "application/json"
put "/services/#{@payload[:name]}/", @payload.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
......@@ -61,26 +61,26 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
Noah::Service.find(:name => @payload[:name]).first.is_new?.should == true
end
it "new service without host should not work" do
put "/s/foobar", {:name => "foobar", :status => "up"}.to_json, "CONTENT_TYPE" => "application/json"
put "/services/foobar", {:name => "foobar", :status => "up"}.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
it "new service with invalid status should not work" do
put "/s/foobar", {:name => "foobar", :status => "fsck", :host => @h.name}.to_json, "CONTENT_TYPE" => "application/json"
put "/services/foobar", {:name => "foobar", :status => "fsck", :host => @h.name}.to_json, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
response["error_message"].should == "Status must be up, down or pending"
end
it "new service with missing name should not work" do
put "/s/foobar", {:status => "fsck", :host => @h.name}.to_json, "CONTENT_TYPE" => "application/json"
put "/services/foobar", {:status => "fsck", :host => @h.name}.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
it "new service with missing status should not work" do
put "/s/foobar", {:name => "foobar", :host => @h.name}.to_json, "CONTENT_TYPE" => "application/json"
put "/services/foobar", {:name => "foobar", :host => @h.name}.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
it "existing service should work" do
sleep 3
put "/s/#{@payload[:name]}", {:name => @payload[:name], :status => "down", :host => @payload[:host]}.to_json, "CONTENT_TYPE" => "application/json"
put "/services/#{@payload[:name]}", {:name => @payload[:name], :status => "down", :host => @payload[:host]}.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response["result"].should == "success"
......@@ -101,7 +101,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
@s = @h.services.first
end
it "existing host should work" do
delete "/s/#{@s.name}/#{@h.name}"
delete "/services/#{@s.name}/#{@h.name}"
last_response.should be_ok
response = last_response.should return_json
......@@ -112,7 +112,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
response["service"].should == @s.name
end
it "invalid host should not work" do
delete "/s/#{@s.name}/#{@h.name}"
delete "/services/#{@s.name}/#{@h.name}"
last_response.should be_missing
end
end
......
......@@ -22,7 +22,7 @@ describe "Using the Watcher API", :reset_redis => true do
describe "GET" do
it "all watches should work" do
get '/w'
get '/watches'
last_response.should be_ok
response = last_response.should return_json
response.is_a?(Array).should == true
......@@ -30,8 +30,8 @@ describe "Using the Watcher API", :reset_redis => true do
end
it "named watch should work" do
w = Noah::Watcher.create(:pattern => '//noah/application/myapp', :endpoint => 'http://localhost/webhook')
get "/w/#{w.name}"
w = Noah::Watcher.create(:pattern => '//noah/application/myapp', :endpoint => 'http://localhost/watchersebhook')
get "/watches/#{w.name}"
last_response.should be_ok
response = last_response.should return_json
response['pattern'].should == w.pattern
......@@ -39,15 +39,15 @@ describe "Using the Watcher API", :reset_redis => true do
end
it "invalid watch should not work" do
get '/w/asdfasdfasdfasdfasdfsdf'
get '/watches/asdfasdfasdfasdfasdfsdf'
last_response.should be_missing
end
end
describe "PUT" do
it "new watch should work" do
data = {:pattern => "//noah/application", :endpoint => "http://myendpoint/webhook"}
put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
data = {:pattern => "//noah/application", :endpoint => "http://myendpoint/watchersebhook"}
put '/watches', data.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response['pattern'].should == data[:pattern]
......@@ -58,30 +58,30 @@ describe "Using the Watcher API", :reset_redis => true do
end
it "new watch without pattern should not work" do
data = {:endpoint => "http://myendpoint/webhook"}
put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
data = {:endpoint => "http://myendpoint/watchersebhook"}
put '/watches', data.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
it "new watch without endpoint should not work" do
data = {:pattern => "//noah/application"}
put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
put '/watches', data.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
it "new watch that supercedes existing should not work" do
Noah::Watcher.create(:endpoint => 'http://myendpoint/webhook', :pattern => '//noah/application/foo')
data = {:endpoint => "http://myendpoint/webhook", :pattern => '//noah/application'}
put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
Noah::Watcher.create(:endpoint => 'http://myendpoint/watchersebhook', :pattern => '//noah/application/foo')
data = {:endpoint => "http://myendpoint/watchersebhook", :pattern => '//noah/application'}
put '/watches', data.to_json, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
response['error_message'].should == 'Pattern would overwrite existing'
end
it "new watch that subsets an existing should not work" do
Noah::Watcher.create(:endpoint => 'http://myendpoint/webhook', :pattern => '//noah/application')
data = {:endpoint => "http://myendpoint/webhook", :pattern => '//noah/application/foo'}
put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
Noah::Watcher.create(:endpoint => 'http://myendpoint/watchersebhook', :pattern => '//noah/application')
data = {:endpoint => "http://myendpoint/watchersebhook", :pattern => '//noah/application/foo'}
put '/watches', data.to_json, "CONTENT_TYPE" => "application/json"
last_response.should_not be_ok
response = last_response.should return_json
response['error_message'].should == 'Pattern is already provided'
......@@ -90,9 +90,9 @@ describe "Using the Watcher API", :reset_redis => true do
describe "DELETE" do
it "delete an existing watch should work" do
data = {:endpoint => "http://myendpoint/webhookd", :pattern => '//noah/application/d'}
data = {:endpoint => "http://myendpoint/watchersebhookd", :pattern => '//noah/application/d'}
w = Noah::Watcher.create(data)
delete '/w', data.to_json, "CONTENT_TYPE" => "application/json"
delete '/watches', data.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_ok
response = last_response.should return_json
response['pattern'].should == data[:pattern]
......@@ -103,19 +103,19 @@ describe "Using the Watcher API", :reset_redis => true do
it "delete an invalid watch should not work" do
data = {:endpoint => 'missing', :pattern => '//noah/application/dag'}
delete '/w', data.to_json, "CONTENT_TYPE" => "application/json"
delete '/watches', data.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_missing
end
it "delete without pattern should not work" do
data = {:endpoint => "invalid"}
delete '/w', data.to_json, "CONTENT_TYPE" => "application/json"
delete '/watches', data.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
it "delete without endpoint should not work" do
data = {:pattern => "//noah/invalid"}
delete '/w', data.to_json, "CONTENT_TYPE" => "application/json"
delete '/watches', data.to_json, "CONTENT_TYPE" => "application/json"
last_response.should be_invalid
end
end
......
......@@ -14,42 +14,42 @@
%h2 Hosts
%ul
%li
%a{:href => "h/"} All registered Hosts
%a{:href => "hosts/"} All registered Hosts
%li
%a{:href => "h/localhost"} localhost (this server)
%a{:href => "hosts/localhost"} localhost (this server)
%li
%a{:href => "h/localhost/noah"} localhost noah service
%a{:href => "hosts/localhost/noah"} localhost noah service
#header
%h2 Services
%ul
%li
%a{:href => "s/"} All registered Services
%a{:href => "services/"} All registered Services
%li
%a{:href => "s/http"} All hosts providing 'http'
%a{:href => "services/http"} All hosts providing 'http'
%li
%a{:href => "s/noah/localhost"} localhost noah service
%a{:href => "services/noah/localhost"} localhost noah service
#header
%h2 Applications
%ul
%li
%a{:href => "a/"} All registered Applications
%a{:href => "applications/"} All registered Applications
%li
%a{:href => "a/noah"} Noah Application entry
%a{:href => "applications/noah"} Noah Application entry
%li
%a{:href => "a/noah/redis"} Noah Redis configuration entry
%a{:href => "applications/noah/redis"} Noah Redis configuration entry
#header
%h2 Configurations
%ul
%li
%a{:href => "c/"} All registered Configurations
%a{:href => "configurations/"} All registered Configurations
%li
%a{:href => "c/noah"} Noah Configuration entry
%a{:href => "configurations/noah"} Noah Configuration entry
%li
%a{:href => "c/myrailsapp1"} myrailsapp1 Configuration entry
%a{:href => "configurations/myrailsapp1"} myrailsapp1 Configuration entry
%li
%a{:href => "c/myrestapp1"} myrestapp1 Configuration entry
%a{:href => "configurations/myrestapp1"} myrestapp1 Configuration entry
%li
%a{:href => "c/myrailsapp1/database.yml"} database.yml file for myrailsapp1 (should return the proper content-type)
%a{:href => "configurations/myrailsapp1/database.yml"} database.yml file for myrailsapp1 (should return the proper content-type)
%li
%a{:href => "c/myrestapp1/config.json"} config.json file for myrestapp1
%a{:href => "configurations/myrestapp1/config.json"} config.json file for myrestapp1
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