Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor cc ipc tests, add method for unprovision

Test plan:
- Unit tests pass

Change-Id: I26fa4a405778c7f587275b5be84b9af9d7e1ad62
  • Loading branch information...
commit 5a9ba909c2747feef13222fc1022f46820cc2f4f 1 parent 918926b
mpage authored
View
10 cloud_controller_ipc/lib/vcap/cloud_controller/ipc/service_consumer_v1_client.rb
@@ -26,15 +26,15 @@ def provision_service(label, name, plan, plan_option=nil)
:plan => plan,
:plan_option => plan_option,
}
- perform_request(Net::HTTP::Post, "/services/v1/configurations", body_hash)
+ perform_request(Net::HTTP::Post, '/services/v1/configurations', body_hash)
end
- protected
-
- def build_uri(path, query=nil)
-
+ def unprovision_service(name)
+ perform_request(Net::HTTP::Delete, "/services/v1/configurations/#{name}")
end
+ protected
+
def perform_request(net_http_class, path, body_hash=nil)
req = net_http_class.new(path, initheaders=@headers)
req.body = Yajl::Encoder.encode(body_hash) if body_hash
View
2  cloud_controller_ipc/lib/vcap/cloud_controller/ipc/version.rb
@@ -1,7 +1,7 @@
module VCAP
module CloudController
module Ipc
- VERSION = '0.0.2'
+ VERSION = '0.0.3'
end
end
end
View
50 cloud_controller_ipc/spec/service_consumer_v1_client_spec.rb
@@ -7,44 +7,56 @@
@client = VCAP::CloudController::Ipc::ServiceConsumerV1Client.new(@host, @port)
end
- describe '#provision_service' do
- before :all do
- @uri = build_uri('/services/v1/configurations')
- @serv_req = {
- :label => 'fooservice-1.1',
- :name => 'test',
- :plan => 'free',
- :plan_option => nil,
- }
- end
-
- it 'should issue a post request to /services/v1/configurations with the correct request body' do
- stub_request(:post, @uri).with(:body => @serv_req)
- @client.provision_service(@serv_req[:label], @serv_req[:name], @serv_req[:plan])
+ describe '#perform_request' do
+ before :each do
+ @uri = build_uri('/test')
end
it 'should pass along the staging_task_id as a header field if supplied' do
client = VCAP::CloudController::Ipc::ServiceConsumerV1Client.new(@host, @port, :staging_task_id => '5')
stub_request(:post, @uri).with(:headers => {'X-Vcap-Staging-Task-Id' => '5'})
- client.provision_service(@serv_req[:label], @serv_req[:name], @serv_req[:plan], nil)
+ client.send(:perform_request, Net::HTTP::Post, '/test')
end
it 'should decode the response body on success' do
result = {'foo' => 'bar'}
enc_result = Yajl::Encoder.encode(result)
- stub_request(:post, @uri).with(:body => @serv_req).to_return(:status => 200, :body => enc_result)
- resp = @client.provision_service(@serv_req[:label], @serv_req[:name], @serv_req[:plan])
+ stub_request(:post, @uri).to_return(:status => 200, :body => enc_result)
+ resp = @client.send(:perform_request, Net::HTTP::Post, '/test')
resp[:result].should == result
end
it 'should return the response as an error on non-200 replies' do
- stub_request(:post, @uri).with(:body => @serv_req).to_return(:status => 400)
- resp = @client.provision_service(@serv_req[:label], @serv_req[:name], @serv_req[:plan])
+ stub_request(:post, @uri).to_return(:status => 400)
+ resp = @client.send(:perform_request, Net::HTTP::Post, '/test')
resp[:error].should_not be_nil
resp[:error].code.should == '400'
end
end
+ describe '#provision_service' do
+ it 'should issue a post request to /services/v1/configurations with the correct request body' do
+ uri = build_uri('/services/v1/configurations')
+ serv_req = {
+ :label => 'fooservice-1.1',
+ :name => 'test',
+ :plan => 'free',
+ :plan_option => nil,
+ }
+ stub_request(:post, uri).with(:body => serv_req)
+ @client.provision_service(serv_req[:label], serv_req[:name], serv_req[:plan])
+ end
+ end
+
+ describe '#unprovision_service' do
+ it 'should issue a delete request to /services/v1/configurations/:name' do
+ service_name = "test_service"
+ uri = build_uri("/services/v1/configurations/#{service_name}")
+ stub_request(:delete, uri)
+ @client.unprovision_service(service_name)
+ end
+ end
+
def build_uri(path, query=nil)
URI::HTTP.build(
:host => @host,
Please sign in to comment.
Something went wrong with that request. Please try again.