Parent

Included Modules

Class/Module Index [+]

Quicksearch

DeltacloudUnitTest::InstancesTest

Public Instance Methods

app() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 24
def app
  Sinatra::Application
end
test_create_key_returns_201() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 200
def test_create_key_returns_201
  post_url '/api/keys', {:name => Time.now.to_f.to_s}
  last_response.status.should == 201
end
test_inst1_has_correct_attributes() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 53
def test_inst1_has_correct_attributes
  get_auth_url '/api/instances', {}
  instance = (last_xml_response/'instances/instance[@id="inst1"]')
  test_instance_attributes(instance)
end
test_it_create_a_new_instance_using_image_id() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 85
def test_it_create_a_new_instance_using_image_id
  params = {
    :image_id => 'img1'
  }
  post_url '/api/instances', params
  last_response.status.should == 201
  last_response.headers['Location'].should_not == nil
  get_auth_url last_response.headers['Location'], {}
  (last_xml_response/'instance/name').should_not == nil
  add_created_instance (last_xml_response/'instance').first['id']
  test_instance_attributes(last_xml_response/'instance')
end
test_it_create_a_new_instance_using_image_id_and_name() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 98
def test_it_create_a_new_instance_using_image_id_and_name
  params = {
    :image_id => 'img1',
    :name => "unit_test_instance1"
  }
  post_url '/api/instances', params
  last_response.status.should == 201
  last_response.headers['Location'].should_not == nil
  get_auth_url last_response.headers['Location'], {}
  (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
  add_created_instance (last_xml_response/'instance').first['id']
  test_instance_attributes(last_xml_response/'instance')
end
test_it_create_a_new_instance_using_image_id_and_name_and_hwp_storage() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 126
def test_it_create_a_new_instance_using_image_id_and_name_and_hwp_storage
  params = {
    :image_id => 'img1',
    :name => "unit_test_instance2",
    :hwp_id => "m1-small",
    :hwp_storage => "160"
  }
  post_url '/api/instances', params
  last_response.status.should == 201
  last_response.headers['Location'].should_not == nil
  get_auth_url last_response.headers['Location'], {}
  (last_xml_response/'instance/name').text.should == 'unit_test_instance2'
  (last_xml_response/'instance/hardware_profile').first['id'].should == 'm1-small'
  add_created_instance (last_xml_response/'instance').first['id']
  test_instance_attributes(last_xml_response/'instance')
end
test_it_create_a_new_instance_using_image_id_and_name_and_hwp_storage_and_hwp_cpu() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 112
def test_it_create_a_new_instance_using_image_id_and_name_and_hwp_storage_and_hwp_cpu
  params = {
    :image_id => 'img1',
    :realm_id => '',
    :name => "unit_test_instance3",
    :hwp_id => "m1-large",
    :hwp_storage => '850',
    :hwp_memory => '7680.0',
    :hwp_cpu => "1.0",
  }
  post_url '/api/instances', params
  last_response.status.should == 400
end
test_it_has_correct_attributes_set() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 37
def test_it_has_correct_attributes_set
  get_auth_url '/api/images', {}
  (last_xml_response/'images/image').each do |image|
    image.attributes.keys.sort.should == [ 'href', 'id' ]
  end
end
test_it_has_unique_ids() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 44
def test_it_has_unique_ids
  get_auth_url '/api/instances', {}
  ids = []
  (last_xml_response/'instances/instance').each do |image|
    ids << image['id'].to_s
  end
  ids.sort.should == ids.sort.uniq
end
test_it_require_authentication() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 28
def test_it_require_authentication
  require_authentication?('/api/instances').should == true
end
test_it_responses_to_html() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 76
def test_it_responses_to_html
  get_auth_url '/api/instances', {}, { :format => :html }
  last_response.status.should == 200
  Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
  get_auth_url '/api/instances/inst1', {}, { :format => :html }
  last_response.status.should == 200
  Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
end
test_it_responses_to_json() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 65
def test_it_responses_to_json
  get_auth_url '/api/instances', {}, { :format => :json }
  JSON::parse(last_response.body).class.should == Hash
  JSON::parse(last_response.body)['instances'].class.should == Array

  get_auth_url '/api/instances/inst1', {}, { :format => :json }
  last_response.status.should == 200
  JSON::parse(last_response.body).class.should == Hash
  JSON::parse(last_response.body)['instance'].class.should == Hash
end
test_it_returns_instances() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 32
def test_it_returns_instances
  get_auth_url '/api/instances', {}
  (last_xml_response/'instances/instance').length.should > 0
end
test_it_returns_valid_realm() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 59
def test_it_returns_valid_realm
  get_auth_url '/api/instances/inst1', {}
  instance = (last_xml_response/'instance')
  test_instance_attributes(instance)
end
test_it_z0_stop_and_start_instance() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 143
def test_it_z0_stop_and_start_instance
  $created_instances.each do |instance_id|
    get_auth_url "/api/instances/#{instance_id}", {}
    stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
    stop_url.should_not == nil
    post_url stop_url
    last_response.status.should == 200
    instance = Nokogiri::XML(last_response.body)
    test_instance_attributes(instance)
    (instance/'state').text.should == 'STOPPED'
    get_auth_url "/api/instances/#{instance_id}", {}
    start_url = (last_xml_response/'actions/link[@rel="start"]').first['href']
    start_url.should_not == nil
    post_url start_url
    last_response.status.should == 200
    instance = Nokogiri::XML(last_response.body)
    test_instance_attributes(instance)
    (instance/'state').text.should == 'RUNNING'
  end
end
test_z0_reboot_instance() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 164
def test_z0_reboot_instance
  $created_instances.each do |instance_id|
    get_auth_url "/api/instances/#{instance_id}", {}
    reboot_url = (last_xml_response/'actions/link[@rel="reboot"]').first['href']
    reboot_url.should_not == nil
    post_url reboot_url
    last_response.status.should == 200
    instance = Nokogiri::XML(last_response.body)
    test_instance_attributes(instance)
    (instance/'state').text.should == 'RUNNING'
  end
end
test_z1_stop_created_instances() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 177
def test_z1_stop_created_instances
  $created_instances.each do |instance_id|
    get_auth_url "/api/instances/#{instance_id}", {}
    stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
    stop_url.should_not == nil
    post_url stop_url, {}
    last_response.status.should == 200
    instance = Nokogiri::XML(last_response.body)
    test_instance_attributes(instance)
    (instance/'state').text.should == 'STOPPED'
  end
end
test_z2_destroy_created_instances() click to toggle source
# File tests/drivers/mock/instances_test.rb, line 190
def test_z2_destroy_created_instances
  $created_instances.each do |instance_id|
    get_auth_url "/api/instances/#{instance_id}", {}
    destroy_url = (last_xml_response/'actions/link[@rel="destroy"]').first['href']
    destroy_url.should_not == nil
    delete_url destroy_url, {}
    last_response.status.should == 204
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.