mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
rackspace: keypairs - add unit tests
This commit is contained in:
parent
969ae676a9
commit
70229ffbf9
6 changed files with 88 additions and 20 deletions
|
@ -89,7 +89,7 @@ module Fog
|
|||
'cidr' => '192.168.0.0/24'
|
||||
}
|
||||
|
||||
key_pair1 = {
|
||||
key_pair = {
|
||||
'public_key' => "ssh-rsa ".concat(Fog::Mock.random_letters(372)).concat(" Generated by Nova\n"),
|
||||
'private_key' => "-----BEGIN RSA PRIVATE KEY-----\n".concat(Fog::Mock.random_letters(1635)).concat("\n-----END RSA PRIVATE KEY-----\n"),
|
||||
'user_id' => user_id,
|
||||
|
@ -97,14 +97,6 @@ module Fog
|
|||
'fingerprint' => "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"
|
||||
}
|
||||
|
||||
key_pair2 = {
|
||||
'public_key' => "ssh-rsa ".concat(Fog::Mock.random_letters(372)).concat(" Generated by Nova\n"),
|
||||
'private_key' => "-----BEGIN RSA PRIVATE KEY-----\n".concat(Fog::Mock.random_letters(1635)).concat("\n-----END RSA PRIVATE KEY-----\n"),
|
||||
'user_id' => user_id,
|
||||
'name' => Fog::Mock.random_letters(32),
|
||||
'fingerprint' => "11:11:11:11:11:11:11:11:11:11:11:11:11:11:11:11"
|
||||
}
|
||||
|
||||
#Block Storage
|
||||
volume_type1_id = Fog::Mock.random_numbers(3).to_s
|
||||
volume_type2_id = Fog::Mock.random_numbers(3).to_s
|
||||
|
@ -127,7 +119,8 @@ module Fog
|
|||
:images => Hash.new { |h,k| h[k] = image unless k == NOT_FOUND_ID },
|
||||
:networks => Hash.new { |h,k| h[k] = network unless k == NOT_FOUND_ID },
|
||||
:keys => [],
|
||||
:keypairs => [{'keypair' => key_pair1}, {'keypair' => key_pair2}],
|
||||
:keypair => key_pair,
|
||||
:keypairs => [],
|
||||
:servers => {},
|
||||
|
||||
#Block Storage
|
||||
|
|
|
@ -34,13 +34,13 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_keypair(name, public_key=nil)
|
||||
|
||||
k = self.data[:keypairs][0]
|
||||
k['keypair']['name'] = name
|
||||
k = self.data[:keypair]
|
||||
k['name'] = name
|
||||
self.data[:keypairs] << { 'keypair' => k }
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = k
|
||||
response.body = { 'keypair' => k }
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,8 +10,7 @@ module Fog
|
|||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# *'success'<~Bool>: true or false for success
|
||||
#
|
||||
def delete_keypair(key_name)
|
||||
request(
|
||||
:method => 'DELETE',
|
||||
|
@ -21,6 +20,17 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_keypair(name)
|
||||
if self.data[:keypairs].select { |k| name.include? k['keypair']['name'] }.empty?
|
||||
raise Fog::Compute::RackspaceV2::NotFound
|
||||
else
|
||||
self.data[:keypairs].reject! { |k| name.include? k['keypair']['name'] }
|
||||
response(:status => 202)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,6 +24,18 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_keypair(name)
|
||||
key = self.data[:keypairs].select { |k| name.include? k['keypair']['name'] }.first
|
||||
if key.nil?
|
||||
raise Fog::Compute::RackspaceV2::NotFound
|
||||
end
|
||||
|
||||
response(:body => key, :status => 200)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,9 +26,7 @@ module Fog
|
|||
def list_keypairs
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"keypairs" => self.data[:keypairs]
|
||||
}
|
||||
response.body = { 'keypairs' => self.data[:keypairs] }
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
55
tests/rackspace/requests/compute_v2/keypair_tests.rb
Normal file
55
tests/rackspace/requests/compute_v2/keypair_tests.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
Shindo.tests('Fog::Compute::RackspaceV2 | keypair_tests', ['rackspace']) do
|
||||
|
||||
keypair_format = {
|
||||
'name' => String,
|
||||
'public_key' => String,
|
||||
'fingerprint' => String,
|
||||
}
|
||||
|
||||
create_keypair_format = {
|
||||
'keypair' => keypair_format.merge({
|
||||
'user_id' => String,
|
||||
'private_key' => String
|
||||
})
|
||||
}
|
||||
|
||||
list_keypair_format = {
|
||||
'keypairs' => [ 'keypair' => keypair_format ]
|
||||
}
|
||||
|
||||
get_keypair_format = {
|
||||
'keypair' => keypair_format
|
||||
}
|
||||
|
||||
service = Fog::Compute.new(:provider => 'Rackspace', :version => 'V2')
|
||||
keypair_name = Fog::Mock.random_letters(32)
|
||||
|
||||
tests('success') do
|
||||
tests('#create_keypair').formats(create_keypair_format) do
|
||||
service.create_keypair(keypair_name).body
|
||||
end
|
||||
|
||||
tests('#list_keypairs').formats(list_keypair_format) do
|
||||
service.list_keypairs.body
|
||||
end
|
||||
|
||||
tests('#get_keypair').formats(get_keypair_format) do
|
||||
service.get_keypair(keypair_name).body
|
||||
end
|
||||
|
||||
tests('#delete_keypair') do
|
||||
service.delete_keypair(keypair_name).body
|
||||
end
|
||||
end
|
||||
|
||||
unknown_keypair_name = Fog::Mock.random_letters(32)
|
||||
tests('failure') do
|
||||
tests('#get_unknown_keypair').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
service.get_keypair(unknown_keypair_name).body
|
||||
end
|
||||
|
||||
tests('#delete_unknown_keypair').raises(Fog::Compute::RackspaceV2::NotFound) do
|
||||
service.delete_keypair(unknown_keypair_name).body
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue