class Object

Constants

BASE_URL
CMWG_NAMESPACE
COLL_URL
CURL_LOADED
DATA_DIR
DEFAULT_CONFIG
INSTANCE_ID
MULTIPART_LOADED
NS
REXML_FORMATTERS

Public Class Methods

__name__() click to toggle source

Destroy test instance when all test are done

# File tests/drivers/gogrid/instances_test.rb, line 29
def self.__name__
  # record_retries below calls this
  "instances_test_class"
end
create_test_instance() click to toggle source
# File tests/drivers/gogrid/instances_test.rb, line 19
def self.create_test_instance
  driver = Deltacloud::new(:gogrid, credentials)
  VCR.use_cassette "instances_create_test_instance" do
    @@instance = driver.instance(:id => INSTANCE_ID)
    @@instance ||= driver.create_instance(fixed_image_id,
                                          :name=> INSTANCE_ID)
  end
end
destroy_test_instance() click to toggle source
# File tests/drivers/gogrid/instances_test.rb, line 34
def self.destroy_test_instance
  driver = Deltacloud::new(:gogrid, credentials)

  # Go fast when running off a recording
  opts = record_retries('', :time_between_retry => 60)
  @@instance.wait_for!(driver, opts) do |i|
    i.actions.include?(:destroy)
  end

  VCR.use_cassette "instances_destroy_test_instance" do
    driver.destroy_instance(@@instance.id)
    @@instance = nil
  end
end
standard_index_operation(opts={}) click to toggle source
# File lib/deltacloud/helpers/rabbit_helper.rb, line 19
def self.standard_index_operation(opts={})
  collection_name = @collection_name
  operation :index, :with_capability => opts[:capability] || collection_name do
    control { filter_all collection_name }
  end
end
standard_show_operation(opts={}) click to toggle source
# File lib/deltacloud/helpers/rabbit_helper.rb, line 26
def self.standard_show_operation(opts={})
  collection_name = @collection_name
  operation :show, :with_capability => opts[:capability] || collection_name do
    control { show collection_name.to_s.singularize.intern }
  end
end

Public Instance Methods

app() click to toggle source
# File tests/ec2/server_test.rb, line 9
def app; Deltacloud::EC2::API; end
blob_name_google() click to toggle source
# File tests/drivers/google/buckets_test.rb, line 26
def blob_name_google
  "testblobk1ds91kVdelmegoogel"
end
bucket_name_google() click to toggle source
# File tests/drivers/google/buckets_test.rb, line 22
def bucket_name_google
  "testbucki2rpux3wdelmegoogel"
end
check(obj) click to toggle source
# File tests/cimi/model/schema_spec.rb, line 95
def check(obj)
  obj.wont_be_nil
  obj[:meter].href.must_equal 'http://example.org/'
end
check_empty_struct(obj) click to toggle source
# File tests/cimi/model/schema_spec.rb, line 178
def check_empty_struct(obj)
  obj.wont_be_nil
  obj[:struct].wont_be_nil
  obj[:struct].scalar.must_be_nil
  obj[:struct].href.must_be_nil
end
check_struct(obj, opts = {}) click to toggle source
# File tests/cimi/model/schema_spec.rb, line 167
def check_struct(obj, opts = {})
  obj.wont_be_nil
  obj[:struct].wont_be_nil
  obj[:struct].scalar.must_equal "v1"
  if opts[:nil_href]
    obj[:struct].href.must_be_nil
  else
    obj[:struct].href.must_equal "http://example.org/"
  end
end
check_structs(obj) click to toggle source
# File tests/cimi/model/schema_spec.rb, line 235
def check_structs(obj)
  obj.wont_be_nil
  obj[:structs].size.must_equal 2
  obj[:structs][0].scalar.must_equal "v1"
  obj[:structs][0].href.must_equal "http://example.org/1"
  obj[:structs][1].scalar.must_equal "v2"
  obj[:structs][1].href.must_equal "http://example.org/2"
end
create_resources() click to toggle source

Setup resources we need for the tests

# File tests/drivers/ec2/common.rb, line 32
def create_resources
  VCR.use_cassette "create_resources" do
    driver = Deltacloud::new(:ec2, credentials)
    @@ec2 = driver.client
    @@vpc = @@ec2.create_vpc("172.16.0.0/16").first
    @@subnet = @@ec2.create_subnet(@@vpc[:vpc_id], "172.16.3.0/24", "us-east-1b").first
  end
end
created_blob_local_file() click to toggle source
# File tests/drivers/google/common.rb, line 12
def created_blob_local_file
  File.join(File.dirname(__FILE__),"data","deltacloud_blob_test.png")
end
credentials() click to toggle source
# File tests/drivers/google/common.rb, line 5
def credentials
  {
    :user => 'GOOG4PBMMHEB2BTY6Q7U',
    :password => '7NxqwXy85xmaWB6o1RZ66IxqP+Rmbu8UFiFdpcSw'
  }
end
destroy_resources() click to toggle source
# File tests/drivers/ec2/common.rb, line 41
def destroy_resources
  VCR.use_cassette "destroy_resources" do
    @@ec2.delete_subnet(@@subnet[:subnet_id]) if @@subnet
    @@ec2.delete_vpc(@@vpc[:vpc_id]) if @@vpc
  end
end
fixed_image_id() click to toggle source
# File tests/drivers/gogrid/common.rb, line 9
def fixed_image_id
  # A fixed image we use throughout the tests; if GoGrid ever removes it
  # we need to change it here
  "9928"
end
formats() click to toggle source
# File tests/test_helper.rb, line 63
def formats; [ 'application/xml', 'application/json', 'text/html' ]; end
get_current_memory_usage() click to toggle source

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

# File lib/deltacloud/core_ext/base.rb, line 16
def get_current_memory_usage
  %xps -o rss= -p #{Process.pid}`.to_i
end
headers() click to toggle source
# File tests/test_helper.rb, line 59
def headers; last_response.headers; end
ids(coll) click to toggle source
# File tests/cimi/collections/machines_test.rb, line 46
def ids(coll)
  xml.xpath("/c:Machine/c:#{coll}/c:id", NS)
end
json() click to toggle source
# File tests/test_helper.rb, line 62
def json; JSON::parse(response_body); end
library_present?(name) click to toggle source

See if we can require name and return true if the library is there, false otherwise. Note that, as a side effect, the library will be loaded

# File bin/deltacloudd, line 28
def library_present?(name)
  begin
    require name
    true
  rescue LoadError
    false
  end
end
machine(*expand) click to toggle source
# File tests/cimi/collections/machines_test.rb, line 39
def machine(*expand)
  url = '/machines/inst1'
  url += "?$expand=#{expand.join(",")}" unless expand.empty?
  get root_url url
  status.must_equal 200
end
machines(*select) click to toggle source
# File tests/cimi/collections/machine_images_test.rb, line 37
def machines(*select)
  url = "/machine_images"
  url += "?$select=#{select.join(",")}" unless select.empty?
  get root_url url
  status.must_equal 200
end
openstack_image_id() click to toggle source
# File tests/drivers/openstack/common.rb, line 12
def openstack_image_id
  'bf7ce59a-d9f9-45d4-9313-f45b16436602'
end
parse_xml(xml, opts = {}) click to toggle source
# File tests/cimi/spec_helper.rb, line 28
def parse_xml(xml, opts = {})
  opts[:force_content] = true
  opts[:keep_root] = true unless opts.has_key?(:keep_root)
  XmlSimple.xml_in(xml, opts)
end
profile_memory(&block) click to toggle source
# File lib/deltacloud/core_ext/base.rb, line 20
def profile_memory(&block)
  before = get_current_memory_usage
  file, line, _ = caller[0].split(':')
  if block_given?
    instance_eval(&block)
    puts "[#{file}:#{line}: #{(get_current_memory_usage - before) / 1024} MB (consumed)]"
  else
    before = 0
    puts "[#{file}:#{line}: #{(get_current_memory_usage - before) / 1024} MB (all)]"
  end
end
raise_error(id) click to toggle source
# File tests/drivers/base/exceptions_test.rb, line 31
def raise_error(id); ExceptionTestClass.new.raise_exception(id); end
record_retries(name='', opts = {}) click to toggle source
# File tests/test_helper.rb, line 36
def record_retries(name='', opts = {})
  opts[:before] = Proc.new { |r, &block|
    VCR.use_cassette("#{__name__}-#{name.empty? ? '' : "#{name}-"}#{r}", &block)
  }
  if VCR.configuration.default_cassette_options[:record] == :none
    opts[:time_between_retry] = 0
  end
  opts
end
response_body() click to toggle source
# File tests/test_helper.rb, line 60
def response_body; last_response.body; end
root_url(url='') click to toggle source
# File tests/test_helper.rb, line 64
def root_url(url=''); Deltacloud.default_frontend.root_url + url; end
run_frontend(frontend=:deltacloud) click to toggle source
# File tests/test_helper.rb, line 48
def run_frontend(frontend=:deltacloud)
  Rack::Builder.new {
    use Rack::MatrixParams
    map Deltacloud[frontend].root_url do
      use Rack::MatrixParams
      run Deltacloud[frontend].klass
    end
  }.to_app
end
should_properly_serialize_model(model_class, xml, json) click to toggle source
# File tests/cimi/spec_helper.rb, line 106
def should_properly_serialize_model(model_class, xml, json)
  # Roundtrip in same format
  model_class.from_xml(xml).must_serialize_to xml, :fmt => :xml
  model_class.from_json(json).must_serialize_to json, :fmt => :json
  # Roundtrip crossing format
  model_class.from_xml(xml).must_serialize_to json, :fmt => :json
  model_class.from_json(json).must_serialize_to xml, :fmt => :xml
end
status() click to toggle source
# File tests/test_helper.rb, line 58
def status; last_response.status; end
to_dom(model) click to toggle source
# File tests/cimi/model/collection_spec.rb, line 100
def to_dom(model)
  doc = Nokogiri::XML(model.to_xml)
  doc.root.add_namespace("c", doc.namespaces["xmlns"])
  doc
end
to_json(model) click to toggle source
# File tests/cimi/model/collection_spec.rb, line 106
def to_json(model)
  JSON.parse(model.to_json)
end
xml() click to toggle source
# File tests/test_helper.rb, line 61
def xml; Nokogiri::XML(response_body); end