[PATCH 6/6] adding test coverage for the config server
Dan Radez
dradez at redhat.com
Wed Dec 14 19:02:09 UTC 2011
---
configserver/src/.rspec | 2 +
configserver/src/common_config.rb | 25 ++++++
configserver/src/config.in.ru | 20 +----
configserver/src/spec/config_server_400s_spec.rb | 73 +++++++++++++++++
configserver/src/spec/config_server_spec.rb | 94 ++++++++++++++++++++++
configserver/src/spec/spec_helper.rb | 25 ++++++
6 files changed, 221 insertions(+), 18 deletions(-)
create mode 100644 configserver/src/.rspec
create mode 100644 configserver/src/common_config.rb
create mode 100644 configserver/src/spec/config_server_400s_spec.rb
create mode 100644 configserver/src/spec/config_server_spec.rb
create mode 100644 configserver/src/spec/spec_helper.rb
diff --git a/configserver/src/.rspec b/configserver/src/.rspec
new file mode 100644
index 0000000..42f3246
--- /dev/null
+++ b/configserver/src/.rspec
@@ -0,0 +1,2 @@
+--format nested
+--color
diff --git a/configserver/src/common_config.rb b/configserver/src/common_config.rb
new file mode 100644
index 0000000..557b467
--- /dev/null
+++ b/configserver/src/common_config.rb
@@ -0,0 +1,25 @@
+# This file has configs than both rack and rspec need that
+# it seems we cannot put in the same file
+
+require 'configserver'
+
+root_dir = File.dirname(__FILE__)
+version = ENV['AEOLUS_CONFSERVER_VERSION'] || '@VERSION@'
+storage_dir = ENV['STORAGE_DIR'] || '/tmp/audrey'
+instance_config_rng = ENV['INSTANCE_CONFIG_RNG'] ||
+ '/var/lib/aeolus-configserver/schema/instance-config.rng'
+
+proxy_type=ENV['PROXY_TYPE']
+# when apache is handling auth
+proxy_auth_file = ENV['PROXY_AUTH_FILE']
+
+set :app_log, ENV['APPLICATION_LOG']
+set :storage_dir, storage_dir
+set :instance_config_rng, instance_config_rng
+set :root, root_dir
+set :version, version
+set :proxy_type, proxy_type
+set :proxy_auth_file, proxy_auth_file
+set :app_file, File.join(root_dir, 'hello.rb')
+ConfigServer::Model.storage_dir = settings.storage_dir
+disable :run
diff --git a/configserver/src/config.in.ru b/configserver/src/config.in.ru
index 950f36f..493064c 100644
--- a/configserver/src/config.in.ru
+++ b/configserver/src/config.in.ru
@@ -1,24 +1,8 @@
-root_dir = File.dirname(__FILE__)
-version = ENV['AEOLUS_CONFSERVER_VERSION'] || '@VERSION@'
-storage_dir = ENV['STORAGE_DIR'] ||
- '/var/lib/aeolus-configserver'
-instance_config_rng = ENV['INSTANCE_CONFIG_RNG'] ||
- '/var/lib/aeolus-configserver/schema/instance-config.rng'
-
env = ENV['RACK_ENV'].to_sym
-proxy_type=ENV['PROXY_TYPE']
-# when apache is handling auth
-proxy_auth_file = ENV['PROXY_AUTH_FILE']
-require 'configserver'
+require 'common_config'
+
set :environment, env
-set :storage_dir, storage_dir
-set :instance_config_rng, instance_config_rng
-set :root, root_dir
-set :version, version
-set :proxy_type, proxy_type
-ConfigServer::Model.storage_dir = settings.storage_dir
-disable :run
require 'logger'
$LOGGER = Logger.new(ENV['APPLICATION_LOG'])
diff --git a/configserver/src/spec/config_server_400s_spec.rb b/configserver/src/spec/config_server_400s_spec.rb
new file mode 100644
index 0000000..4f36ba2
--- /dev/null
+++ b/configserver/src/spec/config_server_400s_spec.rb
@@ -0,0 +1,73 @@
+require 'spec_helper'
+
+describe 'Config Server 400s' do
+
+ before(:each) do
+ ApplicationHelper.class_eval { def authenticated?; true end }
+ end
+
+ it "should return 404 from get /notrealuri" do
+ get '/notrealuri'
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from get /ip/:version/:uuid" do
+ get '/ip/1/fakeUUID', {}, {'HTTP_ACCEPT' => "text/plain"}
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from get /configs/:version/:uuid when asked for text" do
+ get '/configs/1/fakeUUID', {}, {'HTTP_ACCEPT' => "text/plain"}
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from get /configs/:version/:uuid when asked for xml" do
+ get '/configs/1/fakeUUID', {}, {'HTTP_ACCEPT' => "application/xml"}
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from get /configs/:version/:uuid" do
+ get '/configs/1/fakeUUID'
+ last_response.status.should == 404
+ end
+
+ it "should return 400 from post /configs/:version/:uuid" do
+ post '/configs/1/aFakelUUID', {:data=>'Not Real Data'}
+ last_response.status.should == 400
+ end
+
+ it "should return 404 from delete /configs/:version/:uuid" do
+ delete '/configs/1/fakeUUID'
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from get /files/:version/:uuid" do
+ get '/files/1/fakeUUID'
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from get /files/INVALID_VERSION/:uuid" do
+ get '/files/invalid/fakeUUID'
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from put /files/:version/:uuid" do
+ put '/files/1/fakeUUID'
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from get /params/:version/:uuid when asked for xml" do
+ get '/params/1/fakeUUID', {}, {'HTTP_ACCEPT' => "application/xml"}
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from get /params/:version/:uuid when asked for text" do
+ get '/params/1/fakeUUID', {}, {'HTTP_ACCEPT' => "text/plain"}
+ last_response.status.should == 404
+ end
+
+ it "should return 404 from put /params/:version/:uuid" do
+ put '/params/1/fakeUUID'
+ last_response.status.should == 404
+ end
+end
diff --git a/configserver/src/spec/config_server_spec.rb b/configserver/src/spec/config_server_spec.rb
new file mode 100644
index 0000000..98cfeda
--- /dev/null
+++ b/configserver/src/spec/config_server_spec.rb
@@ -0,0 +1,94 @@
+require 'spec_helper'
+
+instance_uuid = '039901bc-1c51-11e1-bae2-0019b91a7f08'
+deployment_uuid = '038f5572-1c51-11e1-bae2-0019b91a7f08'
+# there's probably a better place to put this?
+data = '<instance-config id="039901bc-1c51-11e1-bae2-0019b91a7f08" name="apache" secret="TgAAgcBg2h7l8xt8G6vkXyMpLnTQdMaC3OBRuungdG"><deployable name="Wordpress Multi-Instance Deployable" id="038f5572-1c51-11e1-bae2-0019b91a7f08"/></instance-config>'
+
+describe 'Config Server' do
+
+ before(:all) do
+ ApplicationHelper.class_eval { def authenticated?; true end }
+ end
+
+ it "should return html from get /version" do
+ get '/version'
+ last_response.body.should.start_with? '<html>'
+ end
+
+ it "should return xml from get /version when asked for xml" do
+ get '/version', {}, {'HTTP_ACCEPT' => "application/xml"}
+ last_response.body.should.start_with? '<config-server>'
+ end
+
+ it "should return text from get /version when asked for text" do
+ get '/version', {}, {'HTTP_ACCEPT' => "text/plain"}
+ last_response.body.should.start_with? '<config-server>'
+ end
+
+ it "should return 200 from post /configs/:version/:uuid" do
+ post '/configs/1/' + instance_uuid, {:data=>data}
+ last_response.body.should == ''
+ end
+
+ it "should return 200 from get /configs/:version/:uuid" do
+ get '/configs/1/' + instance_uuid
+ last_response.should.be.ok
+ end
+
+ it "should return 200 from get /configs/:version/:uuid when asked for text" do
+ get '/configs/1/' + instance_uuid, {}, {'HTTP_ACCEPT' => "application/xml"}
+ last_response.should.be.ok
+ end
+
+ it "should return 200 from get /configs/:version/:uuid when asked for xml" do
+ get '/configs/1/' + instance_uuid, {}, {'HTTP_ACCEPT' => "text/plain"}
+ last_response.should.be.ok
+ end
+
+ it "should return 200 from put /params/:version/:uuid" do
+ put '/params/1/' + instance_uuid, {:audrey_data=>"||"}
+ last_response.should.be.ok
+ end
+
+ it "should return 200 from get /params/:version/:uuid" do
+ get '/params/1/' + instance_uuid, {}, {'HTTP_ACCEPT' => "application/xml"}
+ last_response.body.should == "<parameters>\n\n</parameters>"
+ end
+
+ it "should return 200 from get /params/:version/:uuid" do
+ get '/params/1/' + instance_uuid, {}, {'HTTP_ACCEPT' => "text/plain"}
+ last_response.body.should == '||'
+ end
+
+ it "should return 200 from get /ip/:version/:uuid" do
+ get '/ip/1/' + instance_uuid, {}, {'HTTP_ACCEPT' => "text/html"}
+ last_response.should.be.ok
+ end
+
+ it "should return 200 from get /ip/:version/:uuid" do
+ get '/ip/1/' + instance_uuid, {}, {'HTTP_ACCEPT' => "text/plain"}
+ last_response.should.be.ok
+ end
+
+ it "should return 200 from get /files/:version/:uuid" do
+ get '/files/1/' + instance_uuid
+ last_response.should.be.ok
+ end
+
+ it "should return 200 from put /files/:version/:uuid" do
+ put '/files/1/' + instance_uuid
+ last_response.should.be.ok
+ end
+
+ it "should return 200 from delete /configs/:version/:uuid" do
+ delete '/configs/1/' + instance_uuid
+ last_response.should.be.ok
+ end
+
+ it "should return 200 from delete /deployments/:version/:uuid" do
+ delete '/deployment/1/' + deployment_uuid
+ last_response.should.be.ok
+ end
+
+end
diff --git a/configserver/src/spec/spec_helper.rb b/configserver/src/spec/spec_helper.rb
new file mode 100644
index 0000000..5df4a79
--- /dev/null
+++ b/configserver/src/spec/spec_helper.rb
@@ -0,0 +1,25 @@
+require 'test/spec'
+require 'rspec'
+require 'rack/test'
+require 'ruby-debug'
+require 'logger'
+
+ENV['INSTANCE_CONFIG_RNG'] = '../schema/instance-config.rng'
+require 'common_config'
+# HACK, see config.in.ru for details
+set :oauth_ignore_post_body, false
+set :environment, :test
+
+$LOGGER = Logger.new('DEBUG')
+
+RSpec.configure do |conf|
+ conf.include Rack::Test::Methods
+ #conf.after(:all) do
+ # storage = :storage_dir.to_s
+ # FileUtils.rm_rf(Dir[storage])
+ #end
+end
+
+def app
+ Sinatra::Application
+end
--
1.7.7.4
More information about the aeolus-devel
mailing list