mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[digitalocean|compute] added SshKey model, collection and related tests
This commit is contained in:
parent
7cb11d85bf
commit
db487f9b32
4 changed files with 123 additions and 0 deletions
28
lib/fog/digitalocean/models/compute/ssh_key.rb
Normal file
28
lib/fog/digitalocean/models/compute/ssh_key.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class DigitalOcean
|
||||
class SshKey < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :ssh_pub_key
|
||||
|
||||
def save
|
||||
requires :name, :ssh_pub_key
|
||||
|
||||
merge_attributes(service.create_ssh_key(name, ssh_pub_key).body['ssh_key'])
|
||||
true
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
|
||||
service.destroy_ssh_key id
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/digitalocean/models/compute/ssh_keys.rb
Normal file
27
lib/fog/digitalocean/models/compute/ssh_keys.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/digitalocean/models/compute/ssh_key'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class DigitalOcean
|
||||
class SshKeys < Fog::Collection
|
||||
|
||||
identity :href
|
||||
|
||||
model Fog::Compute::DigitalOcean::SshKey
|
||||
|
||||
def all
|
||||
data = service.list_ssh_keys.body['ssh_keys']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(uri)
|
||||
if data = service.get_ssh_key(uri)
|
||||
new(data.body)
|
||||
end
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
40
tests/digitalocean/models/compute/ssh_key_tests.rb
Normal file
40
tests/digitalocean/models/compute/ssh_key_tests.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
Shindo.tests("Fog::Compute[:digitalocean] | ssh_key model", ['digitalocean', 'compute']) do
|
||||
|
||||
service = Fog::Compute[:digitalocean]
|
||||
|
||||
tests('The ssh_key model should') do
|
||||
|
||||
test('#save') do
|
||||
@key = service.ssh_keys.create :name => 'fookey',
|
||||
:ssh_pub_key => 'fookey'
|
||||
@key.is_a? Fog::Compute::DigitalOcean::SshKey
|
||||
end
|
||||
tests('have the action') do
|
||||
test('reload') { @key.respond_to? 'reload' }
|
||||
%w{
|
||||
save
|
||||
destroy
|
||||
}.each do |action|
|
||||
test(action) { @key.respond_to? action }
|
||||
end
|
||||
end
|
||||
tests('have attributes') do
|
||||
attributes = [
|
||||
:id,
|
||||
:name,
|
||||
:ssh_pub_key
|
||||
]
|
||||
tests("The key model should respond to") do
|
||||
attributes.each do |attribute|
|
||||
test("#{attribute}") { @key.respond_to? attribute }
|
||||
end
|
||||
end
|
||||
end
|
||||
test('#destroy') do
|
||||
@key.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
28
tests/digitalocean/models/compute/ssh_keys_tests.rb
Normal file
28
tests/digitalocean/models/compute/ssh_keys_tests.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
Shindo.tests('Fog::Compute[:digitalocean] | ssh_keys collection', ['digitalocean']) do
|
||||
|
||||
service = Fog::Compute[:digitalocean]
|
||||
|
||||
tests('The ssh_keys collection') do
|
||||
key = service.ssh_keys.create :name => 'fookey',
|
||||
:ssh_pub_key => 'fookey'
|
||||
[:all, :get].each do |method|
|
||||
test("should respond to #{method}") do
|
||||
service.ssh_keys.respond_to? method
|
||||
end
|
||||
end
|
||||
|
||||
tests('should have Fog::Compute::DigitalOcean::SshKey inside') do
|
||||
service.ssh_keys.each do |s|
|
||||
test { s.kind_of? Fog::Compute::DigitalOcean::SshKey }
|
||||
end
|
||||
end
|
||||
|
||||
tests('should be able to get a model') do
|
||||
test('by instance id') do
|
||||
service.ssh_keys.get(key.id).kind_of? Fog::Compute::DigitalOcean::SshKey
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue