Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactor tests and set consumer_id on provision

  • Loading branch information...
commit 9aef1655ef60104566f4e2c88c98f9f6e6554781 1 parent 0f4c4cf
@csquared csquared authored
View
4 lib/addons-client/client.rb
@@ -6,14 +6,14 @@ def initialize(opts = {})
@consumer_id = opts.fetch :consumer_id, 'api-client@localhost'
end
- def provision!(slug)
+ def provision!(slug, opts = {})
addon_name, plan = slug.split(':')
raise UserError, "No add-on name given" unless addon_name
raise UserError, "No plan name given" unless plan
resource.post({
addon: addon_name,
plan: plan,
- consumer_id: "api-client@localhost"
+ consumer_id: opts.fetch(:consumer_id, "api-client@localhost")
})
end
View
12 test/client_settings_test.rb
@@ -3,7 +3,7 @@
class SettingsTest < Addons::Client::TestCase
def setup
super
- stub_request(:any, /^http:\/\/heroku/)
+ stub_request(:any, /api\/1\//)
end
def test_works_when_options_provided
@@ -16,6 +16,16 @@ def test_hashes_password
assert_requested :post, /heroku:#{password}/
end
+ def test_client_sets_username_password_and_salt
+ password = Digest::SHA1.hexdigest('salt:pass')
+ client = Addons::Client.new(:username => 'test',
+ :password => 'pass',
+ :salt => 'salt')
+ client.provision! 'foo:bar'
+ target_url = "http://test:#{password}@localhost:3000/api/1/resources"
+ assert_requested(:post, target_url)
+ end
+
def test_requires_api_password
Settings.delete :api_password
ENV['ADDONS_API_PASSWORD'] = nil
View
15 test/provision_test.rb
@@ -3,32 +3,35 @@
class ProvisionTest < Addons::Client::TestCase
def setup
super
- stub_request(:any, /resources$/)
+ stub_request(:any, target_url)
@client = Addons::Client.new(:username => 'test',
:password => 'pass',
:salt => 'salt')
end
+ def target_url
+ /resources$/
+ end
+
def test_provisions_from_cmd_line
- password = Digest::SHA1.hexdigest('salt:bacon')
addons_client! "provision memcache:5mb"
-
- target_url = "http://heroku:#{password}@localhost:3000/api/1/resources"
assert_requested(:post, target_url,
body: { addon: 'memcache', plan: '5mb',
consumer_id: 'api-client@localhost'})
end
def test_provisions_from_ruby
- password = Digest::SHA1.hexdigest('salt:pass')
@client.provision! 'foo:plizzan'
- target_url = "http://test:#{password}@localhost:3000/api/1/resources"
assert_requested(:post, target_url,
body: { addon: 'foo', plan: 'plizzan',
consumer_id: 'api-client@localhost'})
end
def test_sets_consumer_id
+ @client.provision! 'foo:bar', :consumer_id => 'app123@heroku.com'
+ assert_requested(:post, target_url,
+ body: { addon: 'foo', plan: 'bar',
+ consumer_id: 'app123@heroku.com'})
end
def test_sets_scheme
Please sign in to comment.
Something went wrong with that request. Please try again.