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

refactor routes (minus ephemerals) to match patterns

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