mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[bbg] request tests
This commit is contained in:
parent
c6bcbc7d40
commit
676fb4d760
9 changed files with 178 additions and 4 deletions
|
@ -16,7 +16,8 @@ module Fog
|
|||
attribute :ips
|
||||
attribute :status
|
||||
attribute :flavor_id
|
||||
attribute :image_id
|
||||
# attribute :image_id
|
||||
attribute :template
|
||||
|
||||
# Not reported by the API, but used at create time
|
||||
attr_accessor :name, :password, :hash, :text, :error
|
||||
|
@ -53,6 +54,13 @@ module Fog
|
|||
merge_attributes(data.body)
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def product=(new_product)
|
||||
@flavor_id = new_product['id']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ module Fog
|
|||
if server_id && server = connection.get_block(server_id).body
|
||||
new(server)
|
||||
end
|
||||
rescue Fog::BlueBox::NotFound
|
||||
rescue Fog::Bluebox::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
|
|
|
@ -24,11 +24,18 @@ module Fog
|
|||
'template' => template_id
|
||||
}.merge!(options)
|
||||
|
||||
query = ''
|
||||
for key, value in data
|
||||
query << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&"
|
||||
end
|
||||
query.chop!
|
||||
|
||||
request(
|
||||
:body => data.to_json,
|
||||
# :body => data.to_json,
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:path => '/api/blocks.json'
|
||||
:path => '/api/blocks.json',
|
||||
:query => query
|
||||
)
|
||||
end
|
||||
|
||||
|
|
26
tests/bluebox/helper.rb
Normal file
26
tests/bluebox/helper.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Bluebox
|
||||
|
||||
def self.[](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
credentials = Fog.credentials.reject do |k,v|
|
||||
![:bluebox_api_key, :bluebox_customer_id].include?(k)
|
||||
end
|
||||
hash[key] = case key
|
||||
when :blocks
|
||||
Fog::Bluebox.new(credentials)
|
||||
end
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
||||
module Formats
|
||||
|
||||
PRODUCT = {
|
||||
'cost' => Float,
|
||||
'description' => String,
|
||||
'id' => String
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
end
|
68
tests/bluebox/requests/block_tests.rb
Normal file
68
tests/bluebox/requests/block_tests.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
Shindo.tests('Bluebox | block requests', ['bluebox']) do
|
||||
|
||||
@block_format = {
|
||||
'cpu' => Float,
|
||||
'hostname' => String,
|
||||
'id' => String,
|
||||
'ips' => [{'address' => String}],
|
||||
'memory' => Integer,
|
||||
'product' => Bluebox::Formats::PRODUCT,
|
||||
'status' => String,
|
||||
'storage' => Integer,
|
||||
'template' => String,
|
||||
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@product_id = '94fd37a7-2606-47f7-84d5-9000deda52ae' # 1 GB
|
||||
@template_id = 'a00baa8f-b5d0-4815-8238-b471c4c4bf72' # Ubuntu 9.10 64bit
|
||||
@password = 'R8p6ikXOfCxoKy'
|
||||
|
||||
@block_id = nil
|
||||
|
||||
tests("create_block('#{@product_id}', '#{@template_id}', 'fog_block', 'password' => '#{@password}')").formats(@block_format) do
|
||||
data = Bluebox[:blocks].create_block(@product_id, @template_id, 'fog_block', 'password' => @password).body
|
||||
@block_id = data['id']
|
||||
data
|
||||
end
|
||||
|
||||
Bluebox[:blocks].servers.get(@block_id).wait_for { ready? }
|
||||
|
||||
tests("get_block('#{@block_id}')").formats(@block_format) do
|
||||
Bluebox[:blocks].get_block(@block_id).body
|
||||
end
|
||||
|
||||
tests("get_blocks").formats([@block_format.reject {|key,value| ['product', 'template'].include?(key)}]) do
|
||||
Bluebox[:blocks].get_blocks.body
|
||||
end
|
||||
|
||||
tests("reboot_block('#{@block_id}')").formats({'status' => String, 'text' => String}) do
|
||||
Bluebox[:blocks].reboot_block(@block_id).body
|
||||
end
|
||||
|
||||
Bluebox[:blocks].servers.get(@block_id).wait_for { ready? }
|
||||
|
||||
tests("destroy_block('#{@block_id})'").formats({'text' => String}) do
|
||||
Bluebox[:blocks].destroy_block(@block_id).body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("get_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::NotFound) do
|
||||
Bluebox[:blocks].get_block('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
tests("reboot_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::NotFound) do
|
||||
Bluebox[:blocks].reboot_block('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
tests("destroy_block('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::NotFound) do
|
||||
Bluebox[:blocks].destroy_block('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
25
tests/bluebox/requests/product_tests.rb
Normal file
25
tests/bluebox/requests/product_tests.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
Shindo.tests('Bluebox | product requests', ['bluebox']) do
|
||||
|
||||
tests('success') do
|
||||
|
||||
@product_id = '94fd37a7-2606-47f7-84d5-9000deda52ae' # 1 GB
|
||||
|
||||
tests("get_product('#{@product_id}')").formats(Bluebox::Formats::PRODUCT) do
|
||||
Bluebox[:blocks].get_product(@product_id).body
|
||||
end
|
||||
|
||||
tests("get_products").formats([Bluebox::Formats::PRODUCT]) do
|
||||
Bluebox[:blocks].get_products.body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("get_product('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::NotFound) do
|
||||
Bluebox[:blocks].get_product('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
32
tests/bluebox/requests/template_tests.rb
Normal file
32
tests/bluebox/requests/template_tests.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
Shindo.tests('Bluebox | template requests', ['bluebox']) do
|
||||
|
||||
@template_format = {
|
||||
'created' => String,
|
||||
'description' => String,
|
||||
'id' => String,
|
||||
'public' => Fog::Boolean
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
@template_id = 'a00baa8f-b5d0-4815-8238-b471c4c4bf72' # Ubuntu 9.10 64bit
|
||||
|
||||
tests("get_template('#{@template_id}')").formats(@template_format) do
|
||||
Bluebox[:blocks].get_template(@template_id).body
|
||||
end
|
||||
|
||||
tests("get_templates").formats([@template_format]) do
|
||||
Bluebox[:blocks].get_templates.body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("get_template('00000000-0000-0000-0000-000000000000')").raises(Fog::Bluebox::NotFound) do
|
||||
Bluebox[:blocks].get_template('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -35,6 +35,10 @@ module Shindo
|
|||
valid = true
|
||||
data = original_data.dup
|
||||
format = original_format.dup
|
||||
if format.is_a?(Array)
|
||||
data = {:element => data}
|
||||
format = {:element => format}
|
||||
end
|
||||
for key, value in format
|
||||
valid &&= data.has_key?(key)
|
||||
datum = data.delete(key)
|
||||
|
|
|
@ -16,6 +16,10 @@ Shindo.tests('test_helper', 'meta') do
|
|||
formats_kernel({:a => {:b => :c}}, {:a => {:b => Symbol}})
|
||||
end
|
||||
|
||||
test('when format of an array') do
|
||||
formats_kernel([{:a => :b}], [{:a => Symbol}])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('returns false') do
|
||||
|
|
Loading…
Add table
Reference in a new issue