1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[digitalocean|compute] added destroy_ssh_key request and tests

This commit is contained in:
Sergio Rubio 2013-03-25 21:47:45 +01:00
parent 2dbf7eff37
commit 9397b368d3
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,37 @@
module Fog
module Compute
class DigitalOcean
class Real
#
# Delete a SSH public key from your account
#
# @see https://www.digitalocean.com/api#ssh_keys
#
def destroy_ssh_key(id)
request(
:expects => [200],
:method => 'GET',
:path => "ssh_keys/#{id}/destroy"
)
end
end
class Mock
def destroy_ssh_key(id)
response = Excon::Response.new
response.status = 200
if self.data[:ssh_keys].reject! { |k| k['id'] == id }
response.body = { "status" => "OK" }
else
response.body = { "status" => "ERROR" }
end
response
end
end
end
end
end

View file

@ -0,0 +1,23 @@
Shindo.tests('Fog::Compute[:digitalocean] | destroy_ssh_key request', ['digitalocean', 'compute']) do
service = Fog::Compute[:digitalocean]
tests('success') do
test('#destroy_ssh_key') do
key = service.create_ssh_key 'fookey', 'fookey'
service.destroy_ssh_key(key.body['ssh_key']['id']).body['status'] == 'OK'
end
end
tests('failures') do
test 'delete invalid key' do
# DigitalOcean API returns 500 with this sometimes
# so mark it as pending in real mode
pending unless Fog.mocking?
service.destroy_ssh_key('00000000000').body['status'] == 'ERROR'
end
end
end