Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix test pollution when lets are used in before(:all)

Change-Id: I6d09877aba43b916045d41625f951cb26c54bae3
  • Loading branch information...
commit 69f32c130c33744da066cb1b78d298637867539e 1 parent ffa9082
@kowshik kowshik authored
Showing with 359 additions and 342 deletions.
  1. +7 −7 spec/api/app_summary_spec.rb
  2. +21 −8 spec/api/helpers/collections.rb
  3. +27 −25 spec/api/helpers/creating_and_updating.rb
  4. +2 −3 spec/api/helpers/deleting.rb
  5. +1 −3 spec/api/helpers/enumeration.rb
  6. +10 −14 spec/api/helpers/invalid_resource.rb
  7. +6 −9 spec/api/helpers/querying.rb
  8. +3 −4 spec/api/helpers/reading.rb
  9. +24 −21 spec/api/legacy_apps_spec.rb
  10. +6 −6 spec/api/legacy_info_spec.rb
  11. +4 −4 spec/api/legacy_resource_match_spec.rb
  12. +9 −13 spec/api/organization_summary_spec.rb
  13. +4 −4 spec/api/resource_match_spec.rb
  14. +0 −1  spec/api/space_spec.rb
  15. +5 −5 spec/api/space_summary_spec.rb
  16. +5 −8 spec/api/spec_helper.rb
  17. +170 −168 spec/dea/dea_client_spec.rb
  18. +1 −3 spec/models/helpers/all_required_attributes.rb
  19. +8 −4 spec/models/helpers/serialization.rb
  20. +6 −7 spec/models/helpers/timestamps.rb
  21. +4 −4 spec/resource_pool/filesystem_pool_spec.rb
  22. +5 −5 spec/resource_pool/resource_pool_spec.rb
  23. +13 −16 spec/resource_pool/spec_helper.rb
  24. +17 −0 spec/rspec_let_monkey_patch.rb
  25. +1 −0  spec/spec_helper.rb
View
14 spec/api/app_summary_spec.rb
@@ -4,15 +4,15 @@
module VCAP::CloudController
describe VCAP::CloudController::AppSummary do
- let(:num_services) { 2 }
- let(:free_mem_size) { 128 }
-
let(:admin_headers) do
user = VCAP::CloudController::Models::User.make(:admin => true)
headers_for(user)
end
- before :all do
+ before(:all) do
+ @num_services = 2
+ @free_mem_size = 128
+
@system_domain = Models::Domain.new(:name => Sham.domain,
:owning_organization => nil)
@system_domain.save(:validate => false)
@@ -26,11 +26,11 @@ module VCAP::CloudController
:space => @space,
:production => false,
:instances => 1,
- :memory => free_mem_size,
+ :memory => @free_mem_size,
:state => "STARTED",
)
- num_services.times do
+ @num_services.times do
instance = Models::ServiceInstance.make(:space => @space)
@services << instance
Models::ServiceBinding.make(:app => @app, :service_instance => instance)
@@ -110,7 +110,7 @@ module VCAP::CloudController
end
it "should return num_services services" do
- decoded_response["services"].size.should == num_services
+ decoded_response["services"].size.should == @num_services
end
it "should return the correct info for a service" do
View
29 spec/api/helpers/collections.rb
@@ -18,14 +18,27 @@ def query_params_for_inline_depth(depth)
end
shared_context "collections" do |opts, attr, make|
- let(:obj) { opts[:model].make }
- let(:other_obj) { opts[:model].make }
- let(:add_method) { "add_#{child_name}" }
- let(:get_method) { "#{child_name}s" }
- let(:child_name) { attr.to_s.singularize }
- let(:headers) do
- user = VCAP::CloudController::Models::User.make(:admin => true)
- json_headers(headers_for(user))
+ define_method(:obj) do
+ @obj ||= opts[:model].make
+ end
+
+ define_method(:child_name) do
+ attr.to_s.singularize
+ end
+
+ def add_method
+ "add_#{child_name}"
+ end
+
+ def get_method
+ "#{child_name}s"
+ end
+
+ def headers
+ @header ||= begin
+ user = VCAP::CloudController::Models::User.make(:admin => true)
+ json_headers(headers_for(user))
+ end
end
before(:all) do
View
52 spec/api/helpers/creating_and_updating.rb
@@ -1,33 +1,34 @@
# Copyright (c) 2009-2012 VMware, Inc.
module VCAP::CloudController::ApiSpecHelper
-
shared_examples "creating and updating" do |opts|
describe "creating and updating" do
- let(:creation_opts) do
- # if the caller has supplied their own creation lambda, use it
- opts[:create_attribute_reset].call if opts[:create_attribute_reset]
-
- initial_obj = opts[:model].make
- attrs = creation_opts_from_obj(initial_obj, opts)
- initial_obj.destroy
-
- create_attribute = opts[:create_attribute]
- if create_attribute
- opts[:create_attribute_reset].call
- attrs.keys.each do |k|
- v = create_attribute.call k
- attrs[k] = v if v
+ define_method(:creation_opts) do
+ @creation_opts ||= begin
+ # if the caller has supplied their own creation lambda, use it
+ opts[:create_attribute_reset].call if opts[:create_attribute_reset]
+
+ initial_obj = opts[:model].make
+ attrs = creation_opts_from_obj(initial_obj, opts)
+ initial_obj.destroy
+
+ create_attribute = opts[:create_attribute]
+ if create_attribute
+ opts[:create_attribute_reset].call
+ attrs.keys.each do |k|
+ v = create_attribute.call k
+ attrs[k] = v if v
+ end
end
- end
- opts[:extra_attributes].each do |attr|
- if opts[:required_attributes].include?(attr)
- attrs[attr.to_s] = Sham.send(attr)
+ opts[:extra_attributes].each do |attr|
+ if opts[:required_attributes].include?(attr)
+ attrs[attr.to_s] = Sham.send(attr)
+ end
end
- end
- attrs
+ attrs
+ end
end
let(:non_synthetic_creation_opts) do
@@ -118,9 +119,11 @@ module VCAP::CloudController::ApiSpecHelper
req_attrs = req_attrs - ["id"] if verb == :put
req_attrs.each do |without_attr|
context "without the :#{without_attr.to_s} attribute" do
- let(:filtered_opts) do
- creation_opts.select do |k, v|
- k != without_attr.to_s and k != "#{without_attr}_id"
+ define_method(:filtered_opts) do
+ @filtered_opts ||= begin
+ creation_opts.select do |k, v|
+ k != without_attr.to_s and k != "#{without_attr}_id"
+ end
end
end
@@ -246,7 +249,6 @@ module VCAP::CloudController::ApiSpecHelper
it_behaves_like "a vcap rest error response", /taken/
end
end
-
end
end
end
View
5 spec/api/helpers/deleting.rb
@@ -4,10 +4,9 @@ module VCAP::CloudController::ApiSpecHelper
shared_examples "deleting a valid object" do |opts|
describe "deleting a valid object" do
describe "DELETE #{opts[:path]}/:id" do
- let (:obj) { opts[:model].make }
-
before(:all) do
- delete "#{opts[:path]}/#{obj.guid}", {}, admin_headers
+ @obj = opts[:model].make
+ delete "#{opts[:path]}/#{@obj.guid}", {}, admin_headers
end
it "should return 204" do
View
4 spec/api/helpers/enumeration.rb
@@ -16,9 +16,7 @@ module VCAP::CloudController::ApiSpecHelper
path = "#{path}#{qp.join("&")}"
describe "GET #{path}" do
- before(:all) do
- get "#{path}", {}, json_headers(admin_headers)
- end
+ before(:all) { get "#{path}", {}, json_headers(admin_headers) }
it "should return 200" do
last_response.status.should == 200
View
24 spec/api/helpers/invalid_resource.rb
@@ -4,28 +4,24 @@ module VCAP::CloudController::ApiSpecHelper
shared_examples "operations on an invalid object" do |opts|
describe "operations on an invalid object" do
describe "POST #{opts[:path]}/:invalid_id/" do
- before(:all) do
- post "#{opts[:path]}/999999", {}, json_headers(admin_headers)
- end
+ before(:all) { post "#{opts[:path]}/999999", {}, json_headers(admin_headers) }
- it "should return 404" do
- last_response.status.should == 404
- end
+ it "should return 404" do
+ last_response.status.should == 404
+ end
- it_behaves_like "a vcap rest error response", /Unknown request/
+ it_behaves_like "a vcap rest error response", /Unknown request/
end
[:put, :delete, :get].each do |verb|
describe "#{verb.upcase} #{opts[:path]}/:invalid_id/" do
- before(:all) do
- send(verb, "#{opts[:path]}/999999", {}, json_headers(admin_headers))
- end
+ before(:all) { send(verb, "#{opts[:path]}/999999", {}, json_headers(admin_headers)) }
- it "should return 404" do
- last_response.status.should == 404
- end
+ it "should return 404" do
+ last_response.status.should == 404
+ end
- it_behaves_like "a vcap rest error response", "not be found: 999999"
+ it_behaves_like "a vcap rest error response", "not be found: 999999"
end
end
end
View
15 spec/api/helpers/querying.rb
@@ -3,21 +3,18 @@
module VCAP::CloudController::ApiSpecHelper
shared_examples "querying objects" do |opts|
describe "querying objects" do
- before(:all) do
- 5.times { opts[:model].make }
- end
+ before(:all) { 5.times { opts[:model].make } }
opts[:queryable_attributes].each do |attr|
describe "#{opts[:path]}?q=#{attr}:<val>" do
- let(:val) { Sham.send(attr) }
-
before(:all) do
- opts[:model].make(attr => val)
+ @val = Sham.send(attr)
+ opts[:model].make(attr => @val)
end
describe "with a matching value" do
before(:all) do
- get "#{opts[:path]}?q=#{attr}:#{val}", {}, json_headers(admin_headers)
+ get "#{opts[:path]}?q=#{attr}:#{@val}", {}, json_headers(admin_headers)
end
it "should return 200" do
@@ -30,9 +27,9 @@ module VCAP::CloudController::ApiSpecHelper
end
describe "with a non-existent value" do
- let(:non_existent_value) { Sham.send(attr) }
before(:all) do
- get "#{opts[:path]}?q=#{attr}:#{non_existent_value}", {}, json_headers(admin_headers)
+ @non_existent_value = Sham.send(attr)
+ get "#{opts[:path]}?q=#{attr}:#{@non_existent_value}", {}, json_headers(admin_headers)
end
it "should return 200" do
View
7 spec/api/helpers/reading.rb
@@ -4,10 +4,9 @@ module VCAP::CloudController::ApiSpecHelper
shared_examples "reading a valid object" do |opts|
describe "reading a valid object" do
describe "GET #{opts[:path]}/:id" do
- let (:obj) { opts[:model].make }
-
before(:all) do
- get "#{opts[:path]}/#{obj.guid}", {}, json_headers(admin_headers)
+ @obj = opts[:model].make
+ get "#{opts[:path]}/#{@obj.guid}", {}, json_headers(admin_headers)
end
it "should return 200" do
@@ -17,7 +16,7 @@ module VCAP::CloudController::ApiSpecHelper
include_examples "return a vcap rest encoded object"
it "should return the json encoded object in the response body" do
- expected = obj.to_hash
+ expected = @obj.to_hash
expected.each { |k, v| expected[k] = v.to_s if v.kind_of?(Time) }
# filter out the relation urls.
View
45 spec/api/legacy_apps_spec.rb
@@ -8,7 +8,7 @@ module VCAP::CloudController
let(:admin) { make_user_with_default_space(:admin => true) }
let(:app_name) { Sham.name }
- before(:all) do
+ before do
Models::Domain.default_serving_domain_name = DEFAULT_SERVING_DOMAIN_NAME
end
@@ -16,12 +16,12 @@ module VCAP::CloudController
HealthManagerClient.stub(:healthy_instances).and_return(1)
end
- after(:all) do
+ after do
Models::Domain.default_serving_domain_name = nil
end
describe "GET /apps" do
- before(:all) do
+ before do
@apps = []
7.times do
@apps << Models::App.make(:space => user.default_space,
@@ -56,7 +56,7 @@ module VCAP::CloudController
end
describe "GET /apps/:name" do
- before(:all) do
+ before do
# since we don't get the guid back, we use the mem attribute to
# distinguish between apps
@app_1 = Models::App.make(:space => user.default_space, :memory => 128)
@@ -89,7 +89,7 @@ module VCAP::CloudController
end
describe "GET /apps/:name_that_exists" do
- before(:all) do
+ before do
get "/apps/#{@app_2.name}", {}, headers_for(user)
end
@@ -115,7 +115,7 @@ module VCAP::CloudController
end
describe "GET /apps/:invalid_name" do
- before(:all) do
+ before do
get "/apps/name_does_not_exist", {}, headers_for(user)
end
@@ -128,7 +128,7 @@ module VCAP::CloudController
end
describe "GET /apps/name/crashes" do
- before(:all) do
+ before do
@app = Models::App.make(:space => user.default_space)
end
@@ -147,7 +147,7 @@ module VCAP::CloudController
end
describe "GET /apps/:name/instances/:instance_id/files/(:path)" do
- before(:all) do
+ before do
@app = Models::App.make(:space => user.default_space)
end
@@ -232,7 +232,7 @@ module VCAP::CloudController
end
describe "POST /apps" do
- before(:all) do
+ before do
["java", "ruby18"].each do |r|
unless Models::Runtime[:name => r]
Models::Runtime.make(:name => r)
@@ -262,7 +262,7 @@ module VCAP::CloudController
end
context "with all required parameters" do
- before(:all) do
+ before do
req = Yajl::Encoder.encode({
:name => app_name,
:staging => { :framework => "sinatra", :runtime => "ruby18" },
@@ -292,7 +292,7 @@ module VCAP::CloudController
end
context "with legacy yeti style framework and runtime [TEAM-61]" do
- before(:all) do
+ before do
req = Yajl::Encoder.encode({
:name => app_name,
:staging => { :model => "sinatra", :stack => "ruby18" }
@@ -314,7 +314,7 @@ module VCAP::CloudController
end
context "with an invalid framework" do
- before(:all) do
+ before do
req = Yajl::Encoder.encode({
:name => app_name,
:staging => { :framework => "funky", :runtime => "ruby18" },
@@ -336,7 +336,7 @@ module VCAP::CloudController
end
context "with an invalid runtime" do
- before(:all) do
+ before do
req = Yajl::Encoder.encode({
:name => app_name,
:staging => { :framework => "sinatra", :runtime => "cobol" },
@@ -358,7 +358,7 @@ module VCAP::CloudController
end
context "with a nil runtime" do
- before(:all) do
+ before do
req = Yajl::Encoder.encode({
:name => app_name,
:staging => { :framework => "grails" }
@@ -382,7 +382,7 @@ module VCAP::CloudController
context "with a valid route" do
let(:host) { Sham.host }
- before(:all) do
+ before do
req = Yajl::Encoder.encode({
:name => app_name,
:staging => { :framework => "grails" },
@@ -407,7 +407,7 @@ module VCAP::CloudController
let(:host) { Sham.host }
let(:domain) { Sham.domain }
- before(:all) do
+ before do
Models::Route.create(
:host => host,
:domain => Models::Domain.default_serving_domain,
@@ -440,15 +440,18 @@ module VCAP::CloudController
end
context "with an invalid route" do
- bad_domain_name = Sham.domain
+ taken_domain_name = Sham.domain
before(:all) do
- bad_domain = Models::Domain.make(:name => bad_domain_name)
+ Models::Domain.make(:name => taken_domain_name)
+ end
+
+ before do
req = Yajl::Encoder.encode({
:name => app_name,
:staging => { :framework => "grails" },
:uris => ["#{Sham.host}.#{DEFAULT_SERVING_DOMAIN_NAME}",
- "anotherroute.#{bad_domain_name}"]
+ "anotherroute.#{taken_domain_name}"]
})
post "/apps", req, headers_for(user)
@@ -464,7 +467,7 @@ module VCAP::CloudController
end
it_behaves_like "a vcap rest error response",
- /domain is invalid: #{bad_domain_name}/
+ /domain is invalid: #{taken_domain_name}/
end
end
@@ -827,7 +830,7 @@ module VCAP::CloudController
# until services get correct permission settings
describe "service binding" do
describe "PUT /apps/:name adding and removing bindings" do
- before(:all) do
+ before do
@app_obj = Models::App.make(:space => admin.default_space)
bound_instances = []
5.times do
View
12 spec/api/legacy_info_spec.rb
@@ -43,12 +43,12 @@ module VCAP::CloudController
:https => scenario_vars[:protocol] == "https")
end
- before(:all) do
+ before do
config_override(config_setting => true)
end
context "with no authorization header for #{scenario_vars[:user]}" do
- before(:all) do
+ before do
headers.delete("HTTP_AUTHORIZATION")
get "/info", {}, headers
end
@@ -57,7 +57,7 @@ module VCAP::CloudController
end
context "with invalid authorization header for #{scenario_vars[:user]}" do
- before(:all) do
+ before do
if headers["HTTP_AUTHORIZATION"]
headers["HTTP_AUTHORIZATION"] += "EXTRA STUFF"
end
@@ -68,7 +68,7 @@ module VCAP::CloudController
end
context "with a valid authorization header for #{scenario_vars[:user]}" do
- before(:all) do
+ before do
get "/info", {}, headers
end
@@ -140,7 +140,7 @@ module VCAP::CloudController
end
context "with 2 started apps with 2 instances, 5 stopped apps, and 3 service" do
- before(:all) do
+ before do
2.times do
Models::App.make(:space => current_user.default_space,
:state => "STARTED", :instances => 2, :memory => 128)
@@ -348,7 +348,7 @@ module VCAP::CloudController
end
describe "GET", "/info/services", "unauthenticated" do
- before :all do
+ before(:all) do
# poor man's reset_db
Models::Service.filter(:provider => "core").each do |svc|
svc.service_plans_dataset.filter(:name => "100").destroy
View
8 spec/api/legacy_resource_match_spec.rb
@@ -8,20 +8,20 @@ module VCAP::CloudController
include_context "resource pool", FilesystemPool
before(:all) do
- FilesystemPool.add_directory(tmpdir)
+ FilesystemPool.add_directory(@tmpdir)
end
describe "POST /resources" do
it "should return an empty list when no resources match" do
- resource_match_request(:post, "/resources", [], [dummy_descriptor])
+ resource_match_request(:post, "/resources", [], [@dummy_descriptor])
end
it "should return a resource that matches" do
- resource_match_request(:post, "/resources", [@descriptors.first], [dummy_descriptor])
+ resource_match_request(:post, "/resources", [@descriptors.first], [@dummy_descriptor])
end
it "should return many resources that match" do
- resource_match_request(:post, "/resources", @descriptors, [dummy_descriptor])
+ resource_match_request(:post, "/resources", @descriptors, [@dummy_descriptor])
end
end
end
View
22 spec/api/organization_summary_spec.rb
@@ -4,18 +4,13 @@
module VCAP::CloudController
describe VCAP::CloudController::OrganizationSummary do
- let(:num_spaces) { 2 }
- let(:num_services) { 2 }
- let(:num_prod_apps) { 3 }
- let(:num_free_apps) { 5 }
- let(:prod_mem_size) { 128 }
- let(:free_mem_size) { 1024 }
- let(:num_apps) { num_prod_apps + num_free_apps }
-
- let(:admin_headers) do
- user = VCAP::CloudController::Models::User.make(:admin => true)
- headers_for(user)
- end
+ num_spaces = 2
+ num_services = 2
+ num_prod_apps = 3
+ num_free_apps = 5
+ prod_mem_size = 128
+ free_mem_size = 1024
+ num_apps = num_prod_apps + num_free_apps
before :all do
@org = Models::Organization.make
@@ -51,7 +46,8 @@ module VCAP::CloudController
describe "GET /v2/organizations/:id/summary" do
before :all do
- get "/v2/organizations/#{@org.guid}/summary", {}, admin_headers
+ admin_user = VCAP::CloudController::Models::User.make(:admin => true)
+ get "/v2/organizations/#{@org.guid}/summary", {}, headers_for(admin_user)
end
it "should return 200" do
View
8 spec/api/resource_match_spec.rb
@@ -8,20 +8,20 @@ module VCAP::CloudController
include_context "resource pool", FilesystemPool
before(:all) do
- FilesystemPool.add_directory(tmpdir)
+ FilesystemPool.add_directory(@tmpdir)
end
describe "PUT /v2/resource_match" do
it "should return an empty list when no resources match" do
- resource_match_request(:put, "/v2/resource_match", [], [dummy_descriptor])
+ resource_match_request(:put, "/v2/resource_match", [], [@dummy_descriptor])
end
it "should return a resource that matches" do
- resource_match_request(:put, "/v2/resource_match", [@descriptors.first], [dummy_descriptor])
+ resource_match_request(:put, "/v2/resource_match", [@descriptors.first], [@dummy_descriptor])
end
it "should return many resources that match" do
- resource_match_request(:put, "/v2/resource_match", @descriptors, [dummy_descriptor])
+ resource_match_request(:put, "/v2/resource_match", @descriptors, [@dummy_descriptor])
end
end
end
View
1  spec/api/space_spec.rb
@@ -4,7 +4,6 @@
module VCAP::CloudController
describe VCAP::CloudController::Space do
-
it_behaves_like "a CloudController API", {
:path => "/v2/spaces",
:model => Models::Space,
View
10 spec/api/space_summary_spec.rb
@@ -4,11 +4,11 @@
module VCAP::CloudController
describe VCAP::CloudController::SpaceSummary do
- let(:num_services) { 2 }
- let(:num_started_apps) { 3 }
- let(:num_stopped_apps) { 5 }
- let(:mem_size) { 128 }
- let(:num_apps) { num_started_apps + num_stopped_apps }
+ num_services = 2
+ num_started_apps = 3
+ num_stopped_apps = 5
+ mem_size = 128
+ num_apps = num_started_apps + num_stopped_apps
let(:admin_headers) do
user = VCAP::CloudController::Models::User.make(:admin => true)
View
13 spec/api/spec_helper.rb
@@ -88,14 +88,11 @@ def entity
opts[k] ||= {}
end
- let(:admin_headers) do
- user = VCAP::CloudController::Models::User.make(:admin => true)
- headers_for(user)
- end
-
- before do
- # force creation of the admin user used in the headers
- admin_headers
+ def admin_headers
+ @admin_headers ||= begin
+ user = VCAP::CloudController::Models::User.make(:admin => true)
+ headers_for(user)
+ end
end
include_examples "uaa authenticated api", opts
View
338 spec/dea/dea_client_spec.rb
@@ -4,30 +4,32 @@
module VCAP::CloudController
describe VCAP::CloudController::DeaClient do
- let(:app) { Models::App.make }
- let(:message_bus) { double(:message_bus) }
- let(:dea_pool) { double(:dea_pool) }
+ include RSpec::Mocks::ExampleMethods # for double
before(:all) do
+ @app = Models::App.make
+ @message_bus = double(:message_bus)
+ @dea_pool = double(:dea_pool)
+
NUM_SVC_INSTANCES.times do
- instance = Models::ServiceInstance.make(:space => app.space)
- binding = Models::ServiceBinding.make(:app => app,
+ instance = Models::ServiceInstance.make(:space => @app.space)
+ binding = Models::ServiceBinding.make(:app => @app,
:service_instance => instance)
- app.add_service_binding(binding)
+ @app.add_service_binding(binding)
end
end
before(:each) do
- DeaClient.configure(config, message_bus, dea_pool)
+ DeaClient.configure(config, @message_bus, @dea_pool)
end
describe "start_app_message" do
NUM_SVC_INSTANCES = 3
it "should return a serialized dea message" do
- res = DeaClient.send(:start_app_message, app)
+ res = DeaClient.send(:start_app_message, @app)
res.should be_kind_of(Hash)
- res[:droplet].should == app.guid
+ res[:droplet].should == @app.guid
res[:runtime_info].should be_kind_of(Hash)
res[:runtime_info].should have_key(:name)
res[:services].should be_kind_of(Array)
@@ -40,8 +42,8 @@ module VCAP::CloudController
context "with an app enabled for console support" do
it "should enable console in the start message" do
- app.update(:console => true)
- res = DeaClient.send(:start_app_message, app)
+ @app.update(:console => true)
+ res = DeaClient.send(:start_app_message, @app)
res[:console].should == true
end
end
@@ -49,14 +51,14 @@ module VCAP::CloudController
describe "update_uris" do
it "does not update deas if app isn't staged" do
- app.update(:package_state => "PENDING")
- message_bus.should_not_receive(:publish)
- DeaClient.update_uris(app)
+ @app.update(:package_state => "PENDING")
+ @message_bus.should_not_receive(:publish)
+ DeaClient.update_uris(@app)
end
it "sends a dea update message" do
- app.update(:package_state => "STAGED")
- message_bus.should_receive(:publish).with(
+ @app.update(:package_state => "STAGED")
+ @message_bus.should_receive(:publish).with(
"dea.update",
json_match(
hash_including(
@@ -65,16 +67,16 @@ module VCAP::CloudController
)
),
)
- DeaClient.update_uris(app)
+ DeaClient.update_uris(@app)
end
end
describe "start_instances_with_message" do
it "should send a start messages to deas with message override" do
- app.instances = 2
+ @app.instances = 2
- dea_pool.should_receive(:find_dea).and_return("abc")
- message_bus.should_receive(:publish).with(
+ @dea_pool.should_receive(:find_dea).and_return("abc")
+ @message_bus.should_receive(:publish).with(
"dea.abc.start",
json_match(
hash_including(
@@ -84,20 +86,20 @@ module VCAP::CloudController
),
)
with_em_and_thread do
- DeaClient.start_instances_with_message(app, [1], :foo => "bar")
+ DeaClient.start_instances_with_message(@app, [1], :foo => "bar")
end
end
end
describe "start" do
it "should send start messages to deas" do
- app.instances = 2
- dea_pool.should_receive(:find_dea).and_return("abc")
- dea_pool.should_receive(:find_dea).and_return("def")
- message_bus.should_receive(:publish).with("dea.abc.start", kind_of(String))
- message_bus.should_receive(:publish).with("dea.def.start", kind_of(String))
+ @app.instances = 2
+ @dea_pool.should_receive(:find_dea).and_return("abc")
+ @dea_pool.should_receive(:find_dea).and_return("def")
+ @message_bus.should_receive(:publish).with("dea.abc.start", kind_of(String))
+ @message_bus.should_receive(:publish).with("dea.def.start", kind_of(String))
with_em_and_thread do
- DeaClient.start(app)
+ DeaClient.start(@app)
end
end
@@ -105,46 +107,46 @@ module VCAP::CloudController
config_override(
:cc_partition => "ngFTW",
)
- DeaClient.configure(config, message_bus, dea_pool)
+ DeaClient.configure(config, @message_bus, @dea_pool)
- app.instances = 1
- dea_pool.should_receive(:find_dea).and_return("abc")
- message_bus.should_receive(:publish).with("dea.abc.start", anything) do |_, json|
+ @app.instances = 1
+ @dea_pool.should_receive(:find_dea).and_return("abc")
+ @message_bus.should_receive(:publish).with("dea.abc.start", anything) do |_, json|
Yajl::Parser.parse(json).should include("cc_partition" => "ngFTW")
end
with_em_and_thread do
- DeaClient.start(app)
+ DeaClient.start(@app)
end
end
end
describe "stop_indices" do
it "should send stop messages to deas" do
- app.instances = 3
- message_bus.should_receive(:publish).with(
+ @app.instances = 3
+ @message_bus.should_receive(:publish).with(
"dea.stop",
json_match(
hash_including(
- "droplet" => app.guid,
+ "droplet" => @app.guid,
"indices" => [0, 2],
)
),
)
with_em_and_thread do
- DeaClient.stop_indices(app, [0,2])
+ DeaClient.stop_indices(@app, [0,2])
end
end
end
describe "stop_instances" do
it "should send stop messages to deas" do
- app.instances = 3
- message_bus.should_receive(:publish).with(
+ @app.instances = 3
+ @message_bus.should_receive(:publish).with(
"dea.stop",
json_match(
hash_including(
- "droplet" => app.guid,
+ "droplet" => @app.guid,
"instances" => ["a", "b"]
)
),
@@ -152,33 +154,33 @@ module VCAP::CloudController
Yajl::Parser.parse(payload).should_not include("version")
end
with_em_and_thread do
- DeaClient.stop_instances(app, ["a", "b"])
+ DeaClient.stop_instances(@app, ["a", "b"])
end
end
end
describe "stop" do
it "should send a stop messages to deas" do
- app.instances = 2
- message_bus.should_receive(:publish).with("dea.stop", kind_of(String))
+ @app.instances = 2
+ @message_bus.should_receive(:publish).with("dea.stop", kind_of(String))
with_em_and_thread do
- DeaClient.stop(app)
+ DeaClient.stop(@app)
end
end
end
describe "find_specific_instance" do
it "should find a specific instance" do
- app.should_receive(:guid).and_return(1)
+ @app.should_receive(:guid).and_return(1)
instance_json = "\"instance\""
encoded = Yajl::Encoder.encode({"droplet" => 1, "other_opt" => "value"})
- message_bus.should_receive(:request).
+ @message_bus.should_receive(:request).
with("dea.find.droplet", encoded, {:timeout=>2}).
and_return([instance_json])
with_em_and_thread do
- DeaClient.find_specific_instance(app, { :other_opt => "value" })
+ DeaClient.find_specific_instance(@app, { :other_opt => "value" })
.should == "instance"
end
end
@@ -186,8 +188,8 @@ module VCAP::CloudController
describe "find_instances" do
it "should use specified message options" do
- app.should_receive(:guid).and_return(1)
- app.should_receive(:instances).and_return(2)
+ @app.should_receive(:guid).and_return(1)
+ @app.should_receive(:instances).and_return(2)
instance_json = "\"instance\""
encoded = Yajl::Encoder.encode({
@@ -195,7 +197,7 @@ module VCAP::CloudController
"other_opt_0" => "value_0",
"other_opt_1" => "value_1",
})
- message_bus.should_receive(:request).
+ @message_bus.should_receive(:request).
with("dea.find.droplet", encoded, { :expected => 2, :timeout => 2 }).
and_return([instance_json, instance_json])
@@ -205,38 +207,38 @@ module VCAP::CloudController
}
with_em_and_thread do
- DeaClient.find_instances(app, message_options).
+ DeaClient.find_instances(@app, message_options).
should == ["instance", "instance"]
end
end
it "should use default values for expected instances and timeout if none are specified" do
- app.should_receive(:guid).and_return(1)
- app.should_receive(:instances).and_return(2)
+ @app.should_receive(:guid).and_return(1)
+ @app.should_receive(:instances).and_return(2)
instance_json = "\"instance\""
encoded = Yajl::Encoder.encode({ "droplet" => 1 })
- message_bus.should_receive(:request).
+ @message_bus.should_receive(:request).
with("dea.find.droplet", encoded, { :expected => 2, :timeout => 2 }).
and_return([instance_json, instance_json])
with_em_and_thread do
- DeaClient.find_instances(app).
+ DeaClient.find_instances(@app).
should == ["instance", "instance"]
end
end
it "should use the specified values for expected instances and timeout" do
- app.should_receive(:guid).and_return(1)
+ @app.should_receive(:guid).and_return(1)
instance_json = "\"instance\""
encoded = Yajl::Encoder.encode({ "droplet" => 1, "other_opt" => "value" })
- message_bus.should_receive(:request).
+ @message_bus.should_receive(:request).
with("dea.find.droplet", encoded, { :expected => 5, :timeout => 10 }).
and_return([instance_json, instance_json])
with_em_and_thread do
- DeaClient.find_instances(app, { :other_opt => "value" },
+ DeaClient.find_instances(@app, { :other_opt => "value" },
{ :expected => 5, :timeout => 10 }).
should == ["instance", "instance"]
end
@@ -247,18 +249,18 @@ module VCAP::CloudController
include Errors
it "should raise an error if the app is in stopped state" do
- app.should_receive(:stopped?).once.and_return(true)
+ @app.should_receive(:stopped?).once.and_return(true)
instance = 0
path = "test"
with_em_and_thread do
expect {
- DeaClient.get_file_uri_for_instance(app, path, instance)
+ DeaClient.get_file_uri_for_instance(@app, path, instance)
}.to raise_error { |error|
error.should be_an_instance_of Errors::FileError
- msg = "File error: Request failed for app: #{app.name}"
+ msg = "File error: Request failed for app: #{@app.name}"
msg << " path: #{path} as the app is in stopped state."
error.message.should == msg
@@ -267,18 +269,18 @@ module VCAP::CloudController
end
it "should raise an error if the instance is out of range" do
- app.instances = 5
+ @app.instances = 5
instance = 10
path = "test"
with_em_and_thread do
expect {
- DeaClient.get_file_uri_for_instance(app, path, instance)
+ DeaClient.get_file_uri_for_instance(@app, path, instance)
}.to raise_error { |error|
error.should be_an_instance_of Errors::FileError
- msg = "File error: Request failed for app: #{app.name}"
+ msg = "File error: Request failed for app: #{@app.name}"
msg << ", instance: #{instance} and path: #{path} as the instance is"
msg << " out of range."
@@ -288,8 +290,8 @@ module VCAP::CloudController
end
it "should return the file uri if the required instance is found via DEA v1" do
- app.instances = 2
- app.should_receive(:stopped?).once.and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).once.and_return(false)
instance = 1
path = "test"
@@ -297,7 +299,7 @@ module VCAP::CloudController
search_options = {
:indices => [instance],
:states => [:STARTING, :RUNNING, :CRASHED],
- :version => app.version,
+ :version => @app.version,
:path => "test",
}
@@ -308,10 +310,10 @@ module VCAP::CloudController
}
DeaClient.should_receive(:find_specific_instance).
- with(app, search_options).and_return(instance_found)
+ with(@app, search_options).and_return(instance_found)
with_em_and_thread do
- result = DeaClient.get_file_uri_for_instance(app, path, instance)
+ result = DeaClient.get_file_uri_for_instance(@app, path, instance)
result.file_uri_v1.should == "http://1.2.3.4/staged/test"
result.file_uri_v2.should be_nil
result.credentials.should == ["username", "password"]
@@ -319,8 +321,8 @@ module VCAP::CloudController
end
it "should return both file_uri_v2 and file_uri_v1 from DEA v2" do
- app.instances = 2
- app.should_receive(:stopped?).once.and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).once.and_return(false)
instance = 1
path = "test"
@@ -328,7 +330,7 @@ module VCAP::CloudController
search_options = {
:indices => [instance],
:states => [:STARTING, :RUNNING, :CRASHED],
- :version => app.version,
+ :version => @app.version,
:path => "test",
}
@@ -340,10 +342,10 @@ module VCAP::CloudController
}
DeaClient.should_receive(:find_specific_instance).
- with(app, search_options).and_return(instance_found)
+ with(@app, search_options).and_return(instance_found)
with_em_and_thread do
- info = DeaClient.get_file_uri_for_instance(app, path, instance)
+ info = DeaClient.get_file_uri_for_instance(@app, path, instance)
info.file_uri_v2.should == "file_uri_v2"
info.file_uri_v1.should == "http://1.2.3.4/staged/test"
info.credentials.should == ["username", "password"]
@@ -351,8 +353,8 @@ module VCAP::CloudController
end
it "should raise an error if the instance is not found" do
- app.instances = 2
- app.should_receive(:stopped?).once.and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).once.and_return(false)
instance = 1
path = "test"
@@ -360,20 +362,20 @@ module VCAP::CloudController
search_options = {
:indices => [instance],
:states => [:STARTING, :RUNNING, :CRASHED],
- :version => app.version,
+ :version => @app.version,
:path => "test",
}
DeaClient.should_receive(:find_specific_instance).
- with(app, search_options).and_return(nil)
+ with(@app, search_options).and_return(nil)
with_em_and_thread do
expect {
- DeaClient.get_file_uri_for_instance(app, path, instance)
+ DeaClient.get_file_uri_for_instance(@app, path, instance)
}.to raise_error { |error|
error.should be_an_instance_of Errors::FileError
- msg = "File error: Request failed for app: #{app.name}"
+ msg = "File error: Request failed for app: #{@app.name}"
msg << ", instance: #{instance} and path: #{path} as the instance is"
msg << " not found."
@@ -387,18 +389,18 @@ module VCAP::CloudController
include Errors
it "should raise an error if the app is in stopped state" do
- app.should_receive(:stopped?).once.and_return(true)
+ @app.should_receive(:stopped?).once.and_return(true)
instance_id = "abcdef"
path = "test"
with_em_and_thread do
expect {
- DeaClient.get_file_uri_for_instance_id(app, path, instance_id)
+ DeaClient.get_file_uri_for_instance_id(@app, path, instance_id)
}.to raise_error { |error|
error.should be_an_instance_of Errors::FileError
- msg = "File error: Request failed for app: #{app.name}"
+ msg = "File error: Request failed for app: #{@app.name}"
msg << " path: #{path} as the app is in stopped state."
error.message.should == msg
@@ -407,8 +409,8 @@ module VCAP::CloudController
end
it "should return the file uri if the required instance is found via DEA v1" do
- app.instances = 2
- app.should_receive(:stopped?).once.and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).once.and_return(false)
instance_id = "abcdef"
path = "test"
@@ -426,10 +428,10 @@ module VCAP::CloudController
}
DeaClient.should_receive(:find_specific_instance).
- with(app, search_options).and_return(instance_found)
+ with(@app, search_options).and_return(instance_found)
with_em_and_thread do
- result = DeaClient.get_file_uri_for_instance_id(app, path, instance_id)
+ result = DeaClient.get_file_uri_for_instance_id(@app, path, instance_id)
result.file_uri_v1.should == "http://1.2.3.4/staged/test"
result.file_uri_v2.should be_nil
result.credentials.should == ["username", "password"]
@@ -437,8 +439,8 @@ module VCAP::CloudController
end
it "should return both file_uri_v2 and file_uri_v1 from DEA v2" do
- app.instances = 2
- app.should_receive(:stopped?).once.and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).once.and_return(false)
instance_id = "abcdef"
path = "test"
@@ -457,10 +459,10 @@ module VCAP::CloudController
}
DeaClient.should_receive(:find_specific_instance).
- with(app, search_options).and_return(instance_found)
+ with(@app, search_options).and_return(instance_found)
with_em_and_thread do
- info = DeaClient.get_file_uri_for_instance_id(app, path, instance_id)
+ info = DeaClient.get_file_uri_for_instance_id(@app, path, instance_id)
info.file_uri_v2.should == "file_uri_v2"
info.file_uri_v1.should == "http://1.2.3.4/staged/test"
info.credentials.should == ["username", "password"]
@@ -468,8 +470,8 @@ module VCAP::CloudController
end
it "should raise an error if the instance_id is not found" do
- app.instances = 2
- app.should_receive(:stopped?).once.and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).once.and_return(false)
instance_id = "abcdef"
path = "test"
@@ -481,15 +483,15 @@ module VCAP::CloudController
}
DeaClient.should_receive(:find_specific_instance).
- with(app, search_options).and_return(nil)
+ with(@app, search_options).and_return(nil)
with_em_and_thread do
expect {
- DeaClient.get_file_uri_for_instance_id(app, path, instance_id)
+ DeaClient.get_file_uri_for_instance_id(@app, path, instance_id)
}.to raise_error { |error|
error.should be_an_instance_of Errors::FileError
- msg = "File error: Request failed for app: #{app.name}"
+ msg = "File error: Request failed for app: #{@app.name}"
msg << ", instance_id: #{instance_id} and path: #{path} as the instance_id is"
msg << " not found."
@@ -503,15 +505,15 @@ module VCAP::CloudController
include Errors
it "should raise an error if the app is not allowed to be in stopped state" do
- app.should_receive(:stopped?).once.and_return(true)
+ @app.should_receive(:stopped?).once.and_return(true)
with_em_and_thread do
expect {
- DeaClient.find_stats(app)
+ DeaClient.find_stats(@app)
}.to raise_error { |error|
error.should be_an_instance_of Errors::StatsError
- msg = "Stats error: Request failed for app: #{app.name}"
+ msg = "Stats error: Request failed for app: #{@app.name}"
msg << " as the app is in stopped state."
error.message.should == msg
@@ -520,21 +522,21 @@ module VCAP::CloudController
end
it "should return an empty hash if the app is allowed to be in stopped state" do
- app.should_receive(:stopped?).once.and_return(true)
+ @app.should_receive(:stopped?).once.and_return(true)
with_em_and_thread do
- DeaClient.find_stats(app, :allow_stopped_state => true).should == {}
+ DeaClient.find_stats(@app, :allow_stopped_state => true).should == {}
end
end
it "should return the stats for all instances" do
- app.instances = 2
- app.should_receive(:stopped?).once.and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).once.and_return(false)
search_options = {
:include_stats => true,
:states => [:RUNNING],
- :version => app.version,
+ :version => @app.version,
}
stats = double("mock stats")
@@ -551,10 +553,10 @@ module VCAP::CloudController
}
DeaClient.should_receive(:find_instances).
- with(app, search_options).and_return([instance_0, instance_1])
+ with(@app, search_options).and_return([instance_0, instance_1])
with_em_and_thread do
- app_stats = DeaClient.find_stats(app)
+ app_stats = DeaClient.find_stats(@app)
app_stats.should == {
0 => {
:state => "RUNNING",
@@ -569,13 +571,13 @@ module VCAP::CloudController
end
it "should return filler stats for instances that have not responded" do
- app.instances = 2
- app.should_receive(:stopped?).once.and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).once.and_return(false)
search_options = {
:include_stats => true,
:states => [:RUNNING],
- :version => app.version,
+ :version => @app.version,
}
stats = double("mock stats")
@@ -588,10 +590,10 @@ module VCAP::CloudController
Time.should_receive(:now).once.and_return(1)
DeaClient.should_receive(:find_instances).
- with(app, search_options).and_return([instance])
+ with(@app, search_options).and_return([instance])
with_em_and_thread do
- app_stats = DeaClient.find_stats(app)
+ app_stats = DeaClient.find_stats(@app)
app_stats.should == {
0 => {
:state => "RUNNING",
@@ -606,13 +608,13 @@ module VCAP::CloudController
end
it "should return filler stats for instances with out of range indices" do
- app.instances = 2
- app.should_receive(:stopped?).once.and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).once.and_return(false)
search_options = {
:include_stats => true,
:states => [:RUNNING],
- :version => app.version,
+ :version => @app.version,
}
stats = double("mock stats")
@@ -637,12 +639,12 @@ module VCAP::CloudController
Time.should_receive(:now).and_return(1)
DeaClient.should_receive(:find_instances).
- with(app, search_options).and_return([instance_0,
+ with(@app, search_options).and_return([instance_0,
instance_1,
instance_2])
with_em_and_thread do
- app_stats = DeaClient.find_stats(app)
+ app_stats = DeaClient.find_stats(@app)
app_stats.should == {
0 => {
:state => "RUNNING",
@@ -661,25 +663,25 @@ module VCAP::CloudController
include Errors
it "should raise an error if the app is in stopped state" do
- app.should_receive(:stopped?).once.and_return(true)
+ @app.should_receive(:stopped?).once.and_return(true)
- expected_msg = "Instances error: Request failed for app: #{app.name}"
+ expected_msg = "Instances error: Request failed for app: #{@app.name}"
expected_msg << " as the app is in stopped state."
with_em_and_thread do
expect {
- DeaClient.find_all_instances(app)
+ DeaClient.find_all_instances(@app)
}.to raise_error(Errors::InstancesError, expected_msg)
end
end
it "should return flapping instances" do
- app.instances = 2
- app.should_receive(:stopped?).and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).and_return(false)
search_options = {
:state => :FLAPPING,
- :version => app.version
+ :version => @app.version
}
flapping_instances = {
@@ -690,14 +692,14 @@ module VCAP::CloudController
}
HealthManagerClient.should_receive(:find_status).
- with(app, search_options).and_return(flapping_instances)
+ with(@app, search_options).and_return(flapping_instances)
# Should not find starting or running instances if all instances are
# flapping.
DeaClient.should_not_receive(:find_instances)
with_em_and_thread do
- app_instances = DeaClient.find_all_instances(app)
+ app_instances = DeaClient.find_all_instances(@app)
app_instances.should == {
0 => {
:state => "FLAPPING",
@@ -712,12 +714,12 @@ module VCAP::CloudController
end
it "should ignore out of range indices of flapping instances" do
- app.instances = 2
- app.should_receive(:stopped?).and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).and_return(false)
search_options = {
:state => :FLAPPING,
- :version => app.version,
+ :version => @app.version,
}
flapping_instances = {
@@ -728,21 +730,21 @@ module VCAP::CloudController
}
HealthManagerClient.should_receive(:find_status).
- with(app, search_options).and_return(flapping_instances)
+ with(@app, search_options).and_return(flapping_instances)
search_options = {
:states => [:STARTING, :RUNNING],
- :version => app.version,
+ :version => @app.version,
}
DeaClient.should_receive(:find_instances).
- with(app, search_options, { :expected => 2 }).
+ with(@app, search_options, { :expected => 2 }).
and_return([])
Time.should_receive(:now).twice.and_return(1)
with_em_and_thread do
- app_instances = DeaClient.find_all_instances(app)
+ app_instances = DeaClient.find_all_instances(@app)
app_instances.should == {
0 => {
:state => "DOWN",
@@ -757,12 +759,12 @@ module VCAP::CloudController
end
it "should return starting or running instances" do
- app.instances = 3
- app.should_receive(:stopped?).and_return(false)
+ @app.instances = 3
+ @app.should_receive(:stopped?).and_return(false)
search_options = {
:state => :FLAPPING,
- :version => app.version,
+ :version => @app.version,
}
flapping_instances = {
@@ -772,11 +774,11 @@ module VCAP::CloudController
}
HealthManagerClient.should_receive(:find_status).
- with(app, search_options).and_return(flapping_instances)
+ with(@app, search_options).and_return(flapping_instances)
search_options = {
:states => [:STARTING, :RUNNING],
- :version => app.version,
+ :version => @app.version,
}
starting_instance = {
@@ -800,11 +802,11 @@ module VCAP::CloudController
}
DeaClient.should_receive(:find_instances).
- with(app, search_options, { :expected => 2 }).
+ with(@app, search_options, { :expected => 2 }).
and_return([starting_instance, running_instance])
with_em_and_thread do
- app_instances = DeaClient.find_all_instances(app)
+ app_instances = DeaClient.find_all_instances(@app)
app_instances.should == {
0 => {
:state => "FLAPPING",
@@ -831,20 +833,20 @@ module VCAP::CloudController
end
it "should ignore out of range indices of starting or running instances" do
- app.instances = 2
- app.should_receive(:stopped?).and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).and_return(false)
search_options = {
:state => :FLAPPING,
- :version => app.version,
+ :version => @app.version,
}
HealthManagerClient.should_receive(:find_status).
- with(app, search_options)
+ with(@app, search_options)
search_options = {
:states => [:STARTING, :RUNNING],
- :version => app.version,
+ :version => @app.version,
}
starting_instance = {
@@ -867,13 +869,13 @@ module VCAP::CloudController
}
DeaClient.should_receive(:find_instances).
- with(app, search_options, { :expected => 2 }).
+ with(@app, search_options, { :expected => 2 }).
and_return([starting_instance, running_instance])
Time.should_receive(:now).twice.and_return(1)
with_em_and_thread do
- app_instances = DeaClient.find_all_instances(app)
+ app_instances = DeaClient.find_all_instances(@app)
app_instances.should == {
0 => {
:state => "DOWN",
@@ -888,30 +890,30 @@ module VCAP::CloudController
end
it "should return fillers for instances that have not responded" do
- app.instances = 2
- app.should_receive(:stopped?).and_return(false)
+ @app.instances = 2
+ @app.should_receive(:stopped?).and_return(false)
search_options = {
:state => :FLAPPING,
- :version => app.version,
+ :version => @app.version,
}
HealthManagerClient.should_receive(:find_status).
- with(app, search_options)
+ with(@app, search_options)
search_options = {
:states => [:STARTING, :RUNNING],
- :version => app.version,
+ :version => @app.version,
}
DeaClient.should_receive(:find_instances).
- with(app, search_options, { :expected => 2 }).
+ with(@app, search_options, { :expected => 2 }).
and_return([])
Time.should_receive(:now).twice.and_return(1)
with_em_and_thread do
- app_instances = DeaClient.find_all_instances(app)
+ app_instances = DeaClient.find_all_instances(@app)
app_instances.should == {
0 => {
:state => "DOWN",
@@ -929,38 +931,38 @@ module VCAP::CloudController
describe "change_running_instances" do
context "increasing the instance count" do
it "should issue a start command with extra indices" do
- dea_pool.should_receive(:find_dea).and_return("abc")
- dea_pool.should_receive(:find_dea).and_return("def")
- dea_pool.should_receive(:find_dea).and_return("efg")
- message_bus.should_receive(:publish).with("dea.abc.start", kind_of(String))
- message_bus.should_receive(:publish).with("dea.def.start", kind_of(String))
- message_bus.should_receive(:publish).with("dea.efg.start", kind_of(String))
-
- app.instances = 4
- app.save
+ @dea_pool.should_receive(:find_dea).and_return("abc")
+ @dea_pool.should_receive(:find_dea).and_return("def")
+ @dea_pool.should_receive(:find_dea).and_return("efg")
+ @message_bus.should_receive(:publish).with("dea.abc.start", kind_of(String))
+ @message_bus.should_receive(:publish).with("dea.def.start", kind_of(String))
+ @message_bus.should_receive(:publish).with("dea.efg.start", kind_of(String))
+
+ @app.instances = 4
+ @app.save
with_em_and_thread do
- DeaClient.change_running_instances(app, 3)
+ DeaClient.change_running_instances(@app, 3)
end
end
end
context "decreasing the instance count" do
it "should stop the higher indices" do
- message_bus.should_receive(:publish).with("dea.stop", kind_of(String))
- app.instances = 5
- app.save
+ @message_bus.should_receive(:publish).with("dea.stop", kind_of(String))
+ @app.instances = 5
+ @app.save
with_em_and_thread do
- DeaClient.change_running_instances(app, -2)
+ DeaClient.change_running_instances(@app, -2)
end
end
end
context "with no changes" do
it "should do nothing" do
- app.instances = 9
- app.save
+ @app.instances = 9
+ @app.save
with_em_and_thread do
- DeaClient.change_running_instances(app, 0)
+ DeaClient.change_running_instances(@app, 0)
end
end
end
View
4 spec/models/helpers/all_required_attributes.rb
@@ -3,9 +3,7 @@
module VCAP::CloudController::ModelSpecHelper
shared_examples "creation with all required attributes" do
describe "with all required attributes" do
- before(:all) do
- @obj = described_class.make
- end
+ before(:all) { @obj = described_class.make }
it "should succeed" do
@obj.should be_valid
View
12 spec/models/helpers/serialization.rb
@@ -6,21 +6,25 @@ module VCAP::CloudController::ModelSpecHelper
@obj = described_class.make
end
- it "should be seriazable to a hash and not include sensitive information" do
+ it "should be serializable to a hash and not include sensitive information" do
hash = @obj.to_hash
hash.should be_a_kind_of(Hash)
+
opts[:sensitive_attributes].each do |attr|
hash.should_not include(attr.to_s)
hash.should_not include(attr.to_sym)
end
end
- it "should be seriazable to json and not include sensitive information" do
- hash = @obj.to_hash
+ it "should be serializable to json and not include sensitive information" do
json = @obj.to_json
json.should be_a_kind_of(String)
+
parsed_hash = Yajl::Parser.new.parse(json)
- parsed_hash.keys.should == hash.keys
+ opts[:sensitive_attributes].each do |attr|
+ parsed_hash.should_not include(attr.to_s)
+ parsed_hash.should_not include(attr.to_sym)
+ end
end
end
end
View
13 spec/models/helpers/timestamps.rb
@@ -2,20 +2,19 @@
module VCAP::CloudController::ModelSpecHelper
shared_examples "timestamps" do |opts|
- let(:obj) { described_class.make }
-
before(:all) do
- @orig_created_at = obj.created_at
- obj.updated_at.should be_nil
- obj.save
+ @obj = described_class.make
+ @created_at = @obj.created_at
+ @obj.updated_at.should be_nil
+ @obj.save
end
it "should not update the created_at timestamp" do
- obj.created_at.should == @orig_created_at
+ @obj.created_at.should == @created_at
end
it "should have a recent updated_at timestamp" do
- obj.updated_at.should be_recent
+ @obj.updated_at.should be_recent
end
end
end
View
8 spec/resource_pool/filesystem_pool_spec.rb
@@ -8,21 +8,21 @@ module VCAP::CloudController
describe "#match_resources" do
before(:all) do
- FilesystemPool.add_directory(tmpdir)
+ FilesystemPool.add_directory(@tmpdir)
end
it "should return an empty list when no resources match" do
- res = FilesystemPool.match_resources([dummy_descriptor])
+ res = FilesystemPool.match_resources([@dummy_descriptor])
res.should == []
end
it "should return a resource that matches" do
- res = FilesystemPool.match_resources([@descriptors.first, dummy_descriptor])
+ res = FilesystemPool.match_resources([@descriptors.first, @dummy_descriptor])
res.should == [@descriptors.first]
end
it "should return many resources that match" do
- res = FilesystemPool.match_resources(@descriptors + [dummy_descriptor])
+ res = FilesystemPool.match_resources(@descriptors + [@dummy_descriptor])
res.should == @descriptors
end
end
View
10 spec/resource_pool/resource_pool_spec.rb
@@ -9,7 +9,7 @@ module VCAP::CloudController
describe "#match_resources" do
it "should raise NotImplementedError" do
lambda {
- ResourcePool.match_resources([dummy_descriptor])
+ ResourcePool.match_resources([@dummy_descriptor])
}.should raise_error(NotImplementedError)
end
end
@@ -17,7 +17,7 @@ module VCAP::CloudController
describe "#resource_known?" do
it "should raise NotImplementedError" do
lambda {
- ResourcePool.resource_known?(dummy_descriptor)
+ ResourcePool.resource_known?(@dummy_descriptor)
}.should raise_error(NotImplementedError)
end
end
@@ -25,15 +25,15 @@ module VCAP::CloudController
describe "#add_path" do
it "should raise NotImplementedError" do
lambda {
- ResourcePool.add_path(tmpdir)
+ ResourcePool.add_path(@tmpdir)
}.should raise_error(NotImplementedError)
end
end
describe "#add_path" do
it "should walk the fs tree and add only allowable files" do
- ResourcePool.should_receive(:add_path).exactly(total_allowed_files).times
- ResourcePool.add_directory(tmpdir)
+ ResourcePool.should_receive(:add_path).exactly(@total_allowed_files).times
+ ResourcePool.add_directory(@tmpdir)
end
end
end
View
29 spec/resource_pool/spec_helper.rb
@@ -4,31 +4,28 @@
module VCAP::CloudController::ResourcePoolSpecHelper
shared_context "resource pool" do |klass = described_class|
- let(:tmpdir) { Dir.mktmpdir }
- let(:num_dirs) { 3 }
- let(:num_unique_allowed_files_per_dir) { 7 }
- let(:file_duplication_factor) { 2 }
- let(:num_dup_files) { 7 }
- let(:max_file_size) { 1098 } # this is arbitrary
- let(:total_allowed_files) do
- num_dirs * num_unique_allowed_files_per_dir * file_duplication_factor
- end
+ before(:all) do
+ num_dirs = 3
+ num_unique_allowed_files_per_dir = 7
+ file_duplication_factor = 2
+ max_file_size = 1098 # this is arbitrary
- let(:dummy_descriptor) do
- { "sha1" => Digest::SHA1.hexdigest("abc"), "size" => 1}
- end
+ @total_allowed_files =
+ num_dirs * num_unique_allowed_files_per_dir * file_duplication_factor
+
+ @dummy_descriptor = { "sha1" => Digest::SHA1.hexdigest("abc"), "size" => 1}
+ @tmpdir = Dir.mktmpdir
- before(:all) do
cfg = { :resource_pool => { :maximum_size => max_file_size }}
klass.configure(cfg)
@descriptors = []
num_dirs.times do
dirname = SecureRandom.uuid
- Dir.mkdir("#{tmpdir}/#{dirname}")
+ Dir.mkdir("#{@tmpdir}/#{dirname}")
num_unique_allowed_files_per_dir.times do
basename = SecureRandom.uuid
- path = "#{tmpdir}/#{dirname}/#{basename}"
+ path = "#{@tmpdir}/#{dirname}/#{basename}"
contents = SecureRandom.uuid
descriptor = {
@@ -51,7 +48,7 @@ module VCAP::CloudController::ResourcePoolSpecHelper
end
after(:all) do
- FileUtils.rm_rf(tmpdir)
+ FileUtils.rm_rf(@tmpdir)
end
end
end
View
17 spec/rspec_let_monkey_patch.rb
@@ -0,0 +1,17 @@
+require "rspec/version"
+
+unless RSpec::Version::STRING == "2.10.0"
+ throw "Make sure monkey patches below are still needed"
+end
+
+RSpec::Core::Let::ExampleMethods.class_eval do
+ def __memoized
+ throw <<-MSG unless example
+ It appears that you are calling variable defined via let from before :all block.
+ This causes test pollution between individual examples since memoized variables
+ are not properly cleaned up.
+ MSG
+
+ @__memoized ||= {}
+ end
+end
View
1  spec/spec_helper.rb
@@ -10,6 +10,7 @@
require "steno"
require "cloud_controller"
+require "rspec_let_monkey_patch"
module VCAP::CloudController
class SpecEnvironment
Please sign in to comment.
Something went wrong with that request. Please try again.