Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Bug 928240 - --from-code is not supported on clients where the latest…
Browse files Browse the repository at this point in the history
… API version is < 1.3
  • Loading branch information
smarterclayton committed Mar 28, 2013
1 parent 0c82e2e commit 9c0930f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/rhc/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class SSLVersionRejected < SSLConnectionFailed; end

class MultipleCartridgeCreationNotSupported < Exception; end

class InitialGitUrlNotSupported < Exception; end

class SslCertificatesNotSupported < Exception; end

class AuthorizationsNotSupported < Exception
Expand Down
6 changes: 5 additions & 1 deletion lib/rhc/rest/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ def add_application(name, options)
options.each{ |key, value| payload[key.to_sym] = value }

cartridges = Array(payload.delete(:cartridge)).concat(Array(payload.delete(:cartridges))).compact.uniq
if (client.api_version_negotiated >= 1.3)
if client.api_version_negotiated >= 1.3
payload[:cartridges] = cartridges
else
raise RHC::Rest::MultipleCartridgeCreationNotSupported, "The server only supports creating an application with a single web cartridge." if cartridges.length > 1
payload[:cartridge] = cartridges.first
end

if client.api_version_negotiated < 1.3 && payload[:initial_git_url]
raise RHC::Rest::InitialGitUrlNotSupported, "The server does not support creating applications from a source repository."
end

options = {:timeout => options[:scale] && 0 || nil}
rest_method "ADD_APPLICATION", payload, options
end
Expand Down
10 changes: 10 additions & 0 deletions spec/rhc/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module MockRestResponse

it{ domain.add_application('foo', :cartridges => ['bar']).should be_true }
it{ expect{ domain.add_application('foo', :cartridges => ['bar', 'other']) }.to raise_error(RHC::Rest::MultipleCartridgeCreationNotSupported) }
it{ expect{ domain.add_application('foo', :initial_git_url => 'a_url') }.to raise_error(RHC::Rest::InitialGitUrlNotSupported) }
it{ domain.add_application('foo', :cartridges => 'bar').should be_true }
it{ domain.add_application('foo', :cartridge => 'bar').should be_true }
it{ domain.add_application('foo', :cartridge => ['bar']).should be_true }
Expand All @@ -66,6 +67,15 @@ module MockRestResponse
it{ domain.add_application('foo', :cartridges => cartridges).should be_true }
it{ domain.add_application('foo', :cartridge => cartridges).should be_true }
end

context "with a url" do
before do
stub_api_request(:post, 'broker/rest/domains/bar/applications', false).
with(:body => {:name => 'foo', :initial_git_url => 'a_url', :cartridges => []}.to_json).
to_return(:status => 201, :body => {:type => 'application', :data => {:id => '1'}}.to_json)
end
it{ domain.add_application('foo', :initial_git_url => 'a_url').should be_true }
end
end
end

Expand Down

0 comments on commit 9c0930f

Please sign in to comment.