deltacloud-core 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/bin/deltacloudd +11 -5
- data/config.ru +3 -3
- data/deltacloud-core.gemspec +24 -18
- data/lib/cimi/collections/address_templates.rb +3 -3
- data/lib/cimi/collections/addresses.rb +6 -5
- data/lib/cimi/collections/entity_metadata.rb +0 -2
- data/lib/cimi/collections/machine_admins.rb +5 -5
- data/lib/cimi/collections/machine_configurations.rb +2 -2
- data/lib/cimi/collections/machine_images.rb +3 -3
- data/lib/cimi/collections/machines.rb +32 -10
- data/lib/cimi/collections/network_configurations.rb +4 -3
- data/lib/cimi/collections/network_templates.rb +4 -3
- data/lib/cimi/collections/networks.rb +8 -8
- data/lib/cimi/collections/routing_group_templates.rb +4 -3
- data/lib/cimi/collections/routing_groups.rb +4 -3
- data/lib/cimi/collections/volume_configurations.rb +3 -3
- data/lib/cimi/collections/volume_images.rb +3 -3
- data/lib/cimi/collections/volumes.rb +4 -3
- data/lib/cimi/collections/vsp_configurations.rb +4 -3
- data/lib/cimi/collections/vsp_templates.rb +4 -3
- data/lib/cimi/collections/vsps.rb +8 -7
- data/lib/cimi/helpers.rb +1 -1
- data/lib/cimi/helpers/cimi_helper.rb +11 -1
- data/lib/cimi/models.rb +4 -0
- data/lib/cimi/models/base.rb +11 -1
- data/lib/cimi/models/cloud_entry_point.rb +7 -14
- data/lib/cimi/models/disk.rb +40 -0
- data/lib/cimi/models/disk_collection.rb +38 -0
- data/lib/cimi/models/machine.rb +9 -43
- data/lib/cimi/models/machine_collection.rb +7 -4
- data/lib/cimi/models/machine_configuration.rb +8 -15
- data/lib/cimi/models/machine_configuration_collection.rb +6 -4
- data/lib/cimi/models/machine_image_collection.rb +6 -4
- data/lib/cimi/models/machine_template_collection.rb +6 -4
- data/lib/cimi/models/machine_volume.rb +42 -0
- data/lib/cimi/models/machine_volume_collection.rb +34 -0
- data/lib/cimi/models/network.rb +5 -9
- data/lib/cimi/models/network_collection.rb +6 -5
- data/lib/cimi/models/schema.rb +20 -0
- data/lib/cimi/models/volume_collection.rb +6 -4
- data/lib/cimi/models/volume_configuration_collection.rb +6 -4
- data/lib/cimi/models/volume_image_collection.rb +6 -4
- data/lib/cimi/models/volume_template_collection.rb +6 -4
- data/lib/deltacloud/api.rb +3 -3
- data/lib/deltacloud/collections/addresses.rb +1 -1
- data/lib/deltacloud/collections/firewalls.rb +4 -2
- data/lib/deltacloud/collections/keys.rb +1 -1
- data/lib/deltacloud/collections/load_balancers.rb +1 -1
- data/lib/deltacloud/collections/storage_volumes.rb +4 -4
- data/lib/deltacloud/drivers/base_driver.rb +12 -20
- data/lib/deltacloud/drivers/ec2/aws_vpc_monkey_patch.rb +294 -0
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +38 -6
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +4 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +40 -4
- data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +8 -7
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +422 -416
- data/lib/deltacloud/drivers/google/google_driver.rb +2 -1
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +30 -16
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +1 -0
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +3 -9
- data/lib/deltacloud/helpers/deltacloud_helper.rb +0 -2
- data/lib/deltacloud/models/firewall_rule.rb +2 -0
- data/lib/deltacloud/models/hardware_profile.rb +61 -59
- data/{tests/deprecated/core_ext/string.rb → lib/deltacloud/version.rb} +3 -15
- data/lib/deltacloud_rack.rb +1 -0
- data/lib/ec2/server.rb +5 -3
- data/lib/sinatra/rack_accept.rb +53 -53
- data/lib/sinatra/rack_etag.rb +1 -1
- data/tests/cimi/collections/cloud_entry_point_test.rb +11 -2
- data/tests/deltacloud/common.rb +1 -1
- data/tests/deltacloud/rack_test.rb +3 -3
- data/tests/drivers/base/base_driver_test.rb +6 -2
- data/tests/drivers/base/common.rb +1 -0
- data/tests/drivers/base/library_test.rb +6 -2
- data/tests/drivers/ec2/common.rb +34 -15
- data/tests/drivers/ec2/images_test.rb +2 -3
- data/tests/drivers/ec2/instance_test.rb +12 -2
- data/tests/drivers/ec2/keys_test.rb +2 -2
- data/tests/drivers/ec2/realms_test.rb +7 -3
- data/tests/drivers/ec2/storage_snapshots_test.rb +2 -3
- data/tests/drivers/gogrid/common.rb +24 -0
- data/tests/drivers/gogrid/hardware_profiles_test.rb +51 -0
- data/tests/drivers/gogrid/images_test.rb +57 -0
- data/tests/drivers/gogrid/instances_test.rb +92 -0
- data/tests/drivers/gogrid/realms_test.rb +45 -0
- data/tests/drivers/google/buckets_test.rb +105 -0
- data/tests/drivers/google/common.rb +20 -0
- data/tests/drivers/mock/common.rb +1 -0
- data/tests/drivers/mock/images_test.rb +3 -2
- data/tests/drivers/mock/instances_test.rb +3 -2
- data/tests/drivers/mock/keys_test.rb +3 -2
- data/tests/drivers/mock/realms_test.rb +3 -2
- data/tests/drivers/mock/storage_snapshots_test.rb +3 -2
- data/tests/drivers/mock/storage_volumes_test.rb +3 -2
- data/tests/drivers/models/address_test.rb +3 -3
- data/tests/drivers/models/base_test.rb +4 -2
- data/tests/drivers/models/blob_test.rb +3 -3
- data/tests/drivers/models/common.rb +3 -0
- data/tests/drivers/models/hardware_profile_test.rb +5 -4
- data/tests/drivers/models/instance_address_test.rb +3 -3
- data/tests/drivers/models/instance_profile_test.rb +3 -3
- data/tests/drivers/models/instance_test.rb +3 -3
- data/tests/drivers/models/keys_test.rb +3 -3
- data/tests/drivers/models/metrics_test.rb +3 -3
- data/tests/drivers/openstack/common.rb +26 -0
- data/tests/drivers/openstack/hardware_profiles_test.rb +46 -0
- data/tests/drivers/openstack/images_test.rb +50 -0
- data/tests/drivers/openstack/instances_test.rb +66 -0
- data/tests/drivers/openstack/keys_test.rb +61 -0
- data/tests/drivers/openstack/realms_test.rb +46 -0
- data/tests/drivers/rhevm/common.rb +2 -0
- data/tests/drivers/rhevm/images_test.rb +3 -4
- data/tests/drivers/rhevm/instance_test.rb +2 -2
- data/tests/drivers/rhevm/provider_test.rb +2 -2
- data/tests/drivers/rhevm/realms_test.rb +2 -3
- data/tests/ec2/common.rb +5 -4
- data/tests/ec2/server_test.rb +3 -2
- data/tests/helpers/rack/common.rb +3 -0
- data/tests/helpers/rack/rack_accept_test.rb +65 -0
- data/tests/helpers/rack/rack_date_test.rb +27 -0
- data/tests/helpers/rack/rack_driver_select_test.rb +53 -0
- data/tests/helpers/rack/rack_etag_test.rb +29 -0
- data/tests/helpers/rack/rack_matrix_params_test.rb +72 -0
- data/tests/test_helper.rb +44 -36
- data/views/hardware_profiles/index.html.haml +1 -1
- data/views/hardware_profiles/show.html.haml +2 -2
- data/views/hardware_profiles/show.xml.haml +2 -1
- data/views/images/show.html.haml +6 -5
- metadata +74 -117
- data/tests/deprecated/api/common.rb +0 -1
- data/tests/deprecated/api/driver_test.rb +0 -79
- data/tests/deprecated/api/library_test.rb +0 -6
- data/tests/deprecated/cimi/features/step_definitions/common_steps.rb +0 -59
- data/tests/deprecated/cimi/features/step_definitions/machine_images_steps.rb +0 -0
- data/tests/deprecated/cimi/features/step_definitions/machines_steps.rb +0 -100
- data/tests/deprecated/cimi/features/step_definitions/volumes_steps.rb +0 -115
- data/tests/deprecated/cimi/features/support/env.rb +0 -75
- data/tests/deprecated/common.rb +0 -279
- data/tests/deprecated/drivers/ec2/api_test.rb +0 -19
- data/tests/deprecated/drivers/ec2/common.rb +0 -23
- data/tests/deprecated/drivers/ec2/drivers_test.rb +0 -120
- data/tests/deprecated/drivers/ec2/hardware_profiles_test.rb +0 -224
- data/tests/deprecated/drivers/ec2/images_test.rb +0 -230
- data/tests/deprecated/drivers/ec2/instances_test.rb +0 -356
- data/tests/deprecated/drivers/ec2/keys_test.rb +0 -181
- data/tests/deprecated/drivers/ec2/realms_test.rb +0 -146
- data/tests/deprecated/drivers/fgcp/api_test.rb +0 -47
- data/tests/deprecated/drivers/fgcp/hardware_profiles_test.rb +0 -54
- data/tests/deprecated/drivers/fgcp/realms_test.rb +0 -42
- data/tests/deprecated/drivers/fgcp/setup.rb +0 -13
- data/tests/deprecated/drivers/google/api_test.rb +0 -19
- data/tests/deprecated/drivers/google/buckets_test.rb +0 -100
- data/tests/deprecated/drivers/google/common.rb +0 -54
- data/tests/deprecated/drivers/mock/api_test.rb +0 -10
- data/tests/deprecated/drivers/mock/buckets_test.rb +0 -195
- data/tests/deprecated/drivers/mock/common.rb +0 -7
- data/tests/deprecated/drivers/mock/drivers_test.rb +0 -123
- data/tests/deprecated/drivers/mock/hardware_profiles_test.rb +0 -224
- data/tests/deprecated/drivers/mock/images_test.rb +0 -197
- data/tests/deprecated/drivers/mock/instances_test.rb +0 -343
- data/tests/deprecated/drivers/mock/keys_test.rb +0 -161
- data/tests/deprecated/drivers/mock/realms_test.rb +0 -132
- data/tests/deprecated/drivers/mock/storage_snapshots_test.rb +0 -114
- data/tests/deprecated/drivers/mock/storage_volumes_test.rb +0 -122
- data/tests/deprecated/drivers/openstack/api_test.rb +0 -46
- data/tests/deprecated/drivers/openstack/common.rb +0 -21
- data/tests/deprecated/drivers/openstack/hardware_profiles_test.rb +0 -64
- data/tests/deprecated/drivers/openstack/images_test.rb +0 -46
- data/tests/deprecated/drivers/openstack/instances_test.rb +0 -208
- data/tests/deprecated/drivers/openstack/realms_test.rb +0 -40
- data/tests/deprecated/drivers/rackspace/api_test.rb +0 -46
- data/tests/deprecated/drivers/rackspace/buckets_test.rb +0 -150
- data/tests/deprecated/drivers/rackspace/common.rb +0 -16
- data/tests/deprecated/drivers/rackspace/hardware_profiles_test.rb +0 -58
- data/tests/deprecated/drivers/rackspace/images_test.rb +0 -45
- data/tests/deprecated/drivers/rackspace/instances_test.rb +0 -166
- data/tests/deprecated/drivers/rackspace/realms_test.rb +0 -41
- data/tests/deprecated/drivers/rhevm/api_test.rb +0 -45
- data/tests/deprecated/drivers/rhevm/common.rb +0 -21
- data/tests/deprecated/drivers/rhevm/hardware_profiles_test.rb +0 -58
- data/tests/deprecated/drivers/rhevm/images_test.rb +0 -48
- data/tests/deprecated/drivers/rhevm/instances_test.rb +0 -182
- data/tests/deprecated/drivers/rhevm/realms_test.rb +0 -40
- data/tests/deprecated/minitest_common.rb +0 -58
- data/tests/deprecated/minitest_common_api_test.rb +0 -115
- data/tests/deprecated/rabbit_test.rb +0 -52
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
|
4
|
+
require_relative 'common.rb'
|
5
|
+
|
6
|
+
describe 'OpenStackDriver Instances' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@driver = Deltacloud::new(:openstack, credentials)
|
10
|
+
VCR.insert_cassette __name__
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
VCR.eject_cassette
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'must throw error when wrong credentials' do
|
18
|
+
Proc.new do
|
19
|
+
@driver.backend.images(OpenStruct.new(:user => 'unknown+wrong', :password => 'wrong'))
|
20
|
+
end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'must return list of instances' do
|
24
|
+
@driver.instances.wont_be_empty
|
25
|
+
@driver.instances.first.must_be_kind_of Instance
|
26
|
+
end
|
27
|
+
|
28
|
+
# FIXME: The tests above will fail because of incompatibility
|
29
|
+
# in a way how OpenStack handle uuid/id.
|
30
|
+
# Please uncomment these tests if that will be fixed.
|
31
|
+
|
32
|
+
=begin
|
33
|
+
it 'must allow to filter instances' do
|
34
|
+
instances = @driver.instances :id => 'fef00348-9991-404c-b0d4-655d18f84345'
|
35
|
+
instances.wont_be_empty
|
36
|
+
instances.must_be_kind_of Array
|
37
|
+
instances.size.must_equal 1
|
38
|
+
puts instances.inspect
|
39
|
+
instances.first.id.must_equal 'fef00348-9991-404c-b0d4-655d18f84345'
|
40
|
+
@driver.instances(:id => 'unknown').must_be_empty
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'must allow to retrieve single instance' do
|
44
|
+
instance = @driver.instance :id => 'fef00348-9991-404c-b0d4-655d18f84345'
|
45
|
+
instance.wont_be_nil
|
46
|
+
instance.id.must_equal 'fef00348-9991-404c-b0d4-655d18f84345'
|
47
|
+
instance.name.must_equal 'test-3'
|
48
|
+
instance.state.wont_be_empty
|
49
|
+
instance.owner_id.must_equal 'admin'
|
50
|
+
instance.realm_id.wont_be_empty
|
51
|
+
instance.image_id.wont_be_empty
|
52
|
+
instance.instance_profile.wont_be_nil
|
53
|
+
@driver.instance(:id => 'unknown').must_be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'must allow to create and destroy an instance' do
|
57
|
+
instance = @driver.create_instance 'bf7ce59a-d9f9-45d4-9313-f45b16436602', :hwp_id => '1'
|
58
|
+
instance.wont_be_nil
|
59
|
+
instance.image_id.must_equal 'bf7ce59a-d9f9-45d4-9313-f45b16436602'
|
60
|
+
instance.name.wont_be_empty
|
61
|
+
instance.wait_for!(@driver, record_retries('inst_launch')) { |i| i.is_running? }
|
62
|
+
puts @driver.destroy_instance(instance.id).inspect
|
63
|
+
end
|
64
|
+
=end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
|
4
|
+
require_relative 'common.rb'
|
5
|
+
|
6
|
+
describe 'OpenStackDriver Keys' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@driver = Deltacloud::new(:openstack, credentials)
|
10
|
+
VCR.insert_cassette __name__
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
VCR.eject_cassette
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'must throw error when wrong credentials' do
|
18
|
+
Proc.new do
|
19
|
+
@driver.backend.images(OpenStruct.new(:user => 'unknown+wrong', :password => 'wrong'))
|
20
|
+
end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'must return list of keys' do
|
24
|
+
@driver.keys.wont_be_empty
|
25
|
+
@driver.keys.first.must_be_kind_of Key
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'must allow to filter keys' do
|
29
|
+
keys = @driver.keys :id => 'test1'
|
30
|
+
keys.wont_be_empty
|
31
|
+
keys.must_be_kind_of Array
|
32
|
+
keys.size.must_equal 1
|
33
|
+
keys.first.name.must_equal 'test1'
|
34
|
+
@driver.keys(:id => 'unknown').must_be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'must allow to retrieve single key' do
|
38
|
+
key = @driver.key :id => 'test2'
|
39
|
+
key.wont_be_nil
|
40
|
+
key.name.must_equal 'test2'
|
41
|
+
key.fingerprint.wont_be_empty
|
42
|
+
key.credential_type.must_equal :key
|
43
|
+
key.state.must_equal 'AVAILABLE'
|
44
|
+
@driver.key(:id => 'unknown').must_be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'must allow to create and destroy key' do
|
48
|
+
key = @driver.create_key(:key_name => 'test-unit-1')
|
49
|
+
key.wont_be_nil
|
50
|
+
key.id.must_equal 'test-unit-1'
|
51
|
+
key.fingerprint.wont_be_empty
|
52
|
+
key.pem_rsa_key.wont_be_empty
|
53
|
+
key.pem_rsa_key.must_match /^\-\-\-\-\-BEGIN RSA PRIVATE KEY/
|
54
|
+
# Should not allow duplicate keys to be created:
|
55
|
+
lambda {
|
56
|
+
@driver.create_key(:key_name => 'test-unit-1')
|
57
|
+
}.must_raise Deltacloud::ExceptionHandler::BackendError
|
58
|
+
@driver.destroy_key(:id => 'test-unit-1').must_equal true
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
|
4
|
+
require_relative 'common.rb'
|
5
|
+
|
6
|
+
describe 'OpenStackDriver Realms' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@driver = Deltacloud::new(:openstack, credentials)
|
10
|
+
VCR.insert_cassette __name__
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
VCR.eject_cassette
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'must throw error when wrong credentials' do
|
18
|
+
Proc.new do
|
19
|
+
@driver.backend.images(OpenStruct.new(:user => 'unknown+wrong', :password => 'wrong'))
|
20
|
+
end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'must return list of realms' do
|
24
|
+
@driver.realms.wont_be_empty
|
25
|
+
@driver.realms.first.must_be_kind_of Realm
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'must allow to filter realms' do
|
29
|
+
realms = @driver.realms :id => 'default'
|
30
|
+
realms.wont_be_empty
|
31
|
+
realms.must_be_kind_of Array
|
32
|
+
realms.size.must_equal 1
|
33
|
+
realms.first.id.must_equal 'default'
|
34
|
+
@driver.realms(:id => 'unknown').must_be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'must allow to retrieve single realm' do
|
38
|
+
realm = @driver.realm :id => 'default'
|
39
|
+
realm.wont_be_nil
|
40
|
+
realm.id.must_equal 'default'
|
41
|
+
realm.limit.wont_be_empty
|
42
|
+
realm.state.must_equal 'AVAILABLE'
|
43
|
+
@driver.realm(:id => 'unknown').must_be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
2
3
|
|
3
|
-
require_relative
|
4
|
-
require_relative 'common.rb'
|
4
|
+
require_relative 'common'
|
5
5
|
|
6
6
|
describe 'RhevmDriver Images' do
|
7
7
|
|
@@ -70,4 +70,3 @@ describe 'RhevmDriver Images' do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
73
|
-
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
2
3
|
|
3
|
-
require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
|
4
4
|
require_relative 'common.rb'
|
5
5
|
|
6
6
|
describe 'RhevmDriver Realms' do
|
@@ -40,4 +40,3 @@ describe 'RhevmDriver Realms' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
43
|
-
|
data/tests/ec2/common.rb
CHANGED
@@ -9,16 +9,17 @@ require_relative '../test_helper.rb'
|
|
9
9
|
#
|
10
10
|
|
11
11
|
Deltacloud::configure(:ec2) do |server|
|
12
|
-
server.root_url '/'
|
12
|
+
server.root_url '/ec2'
|
13
13
|
server.version '2012-04-01'
|
14
14
|
server.klass 'Deltacloud::EC2::API'
|
15
15
|
server.logger Rack::DeltacloudLogger.setup(ENV['API_LOG'], ENV['API_VERBOSE'])
|
16
16
|
server.default_driver :mock
|
17
17
|
end
|
18
18
|
|
19
|
-
Deltacloud.require_frontend! :ec2
|
20
|
-
|
21
19
|
Deltacloud[:ec2].require!
|
22
20
|
Deltacloud[:ec2].default_frontend!
|
23
21
|
|
24
|
-
|
22
|
+
# The root_url here is '/' because the application is not
|
23
|
+
# mounted and so by default Sinatra mounts it on '/'
|
24
|
+
|
25
|
+
def root_url; '/'; end
|
data/tests/ec2/server_test.rb
CHANGED
@@ -11,13 +11,14 @@ describe Deltacloud::EC2::API do
|
|
11
11
|
|
12
12
|
it 'has the config set property' do
|
13
13
|
Deltacloud::config[:ec2].must_be_kind_of Deltacloud::Server
|
14
|
-
|
14
|
+
Deltacloud[:ec2].root_url.must_equal '/ec2'
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'must do a redirection when no Action parameter' do
|
18
18
|
get root_url
|
19
19
|
status.must_equal 301
|
20
|
-
headers['Location'].
|
20
|
+
headers['Location'].wont_be_empty
|
21
|
+
headers['Location'].must_equal 'http://example.org/ec2'
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'must set the Connection header to close' do
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
require_relative '../../test_helper.rb'
|
4
|
+
require_relative './common.rb'
|
5
|
+
|
6
|
+
class TestAcceptApp < Sinatra::Base
|
7
|
+
use Rack::Accept
|
8
|
+
use Rack::MediaType
|
9
|
+
register Rack::RespondTo
|
10
|
+
helpers Rack::RespondTo::Helpers
|
11
|
+
get '/' do
|
12
|
+
respond_to do |format|
|
13
|
+
format.html { 'html' }
|
14
|
+
format.xml { 'xml' }
|
15
|
+
format.json { 'json' }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe TestAcceptApp do
|
21
|
+
|
22
|
+
before do
|
23
|
+
def app; TestAcceptApp; end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should return HTML when Accept header requests HTML media type' do
|
27
|
+
header 'Accept', 'text/html'
|
28
|
+
get '/'
|
29
|
+
headers['Content-Type'].must_equal 'text/html'
|
30
|
+
response_body.strip.must_equal 'html'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return HTML when Accept header is set by Firefox' do
|
34
|
+
header 'Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
|
35
|
+
get '/'
|
36
|
+
headers['Content-Type'].must_equal 'text/html'
|
37
|
+
response_body.strip.must_equal 'html'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return XML when Accept header requests XML media type' do
|
41
|
+
header 'Accept', 'application/xml'
|
42
|
+
get '/'
|
43
|
+
headers['Content-Type'].must_equal 'application/xml'
|
44
|
+
response_body.strip.must_equal 'xml'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should return JSON when Accept header requests JSON media type' do
|
48
|
+
header 'Accept', 'application/json'
|
49
|
+
get '/'
|
50
|
+
headers['Content-Type'].must_equal 'application/json'
|
51
|
+
response_body.strip.must_equal 'json'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return default media type when no Accept header is set' do
|
55
|
+
get '/'
|
56
|
+
headers['Content-Type'].must_equal 'application/xml'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should return error when unknown Accept header is set' do
|
60
|
+
header 'Accept', 'unknown/header'
|
61
|
+
get '/'
|
62
|
+
status.must_equal 406
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
require_relative '../../test_helper.rb'
|
4
|
+
require_relative './common.rb'
|
5
|
+
|
6
|
+
class TestDateApp < Sinatra::Base
|
7
|
+
use Rack::Date
|
8
|
+
get '/' do
|
9
|
+
'OK'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe TestDateApp do
|
14
|
+
|
15
|
+
before do
|
16
|
+
def app; TestDateApp; end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'add the Date header to all responses' do
|
20
|
+
get '/'
|
21
|
+
status.must_equal 200
|
22
|
+
response_body.wont_be_empty
|
23
|
+
headers['Date'].wont_be_empty
|
24
|
+
Time.parse(headers['Date']).must_be_instance_of Time
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
require_relative '../../test_helper.rb'
|
4
|
+
require_relative './common.rb'
|
5
|
+
|
6
|
+
class TestDriverApp < Sinatra::Base
|
7
|
+
use Rack::DriverSelect
|
8
|
+
get '/' do
|
9
|
+
headers 'Driver' => Thread.current[:driver]
|
10
|
+
headers 'Provider' => Thread.current[:provider]
|
11
|
+
'OK'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe TestDriverApp do
|
16
|
+
|
17
|
+
before do
|
18
|
+
def app; TestDriverApp; end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should set the driver correctly when using X-Deltacloud-Driver request header' do
|
22
|
+
header 'X-Deltacloud-Driver', 'ec2'
|
23
|
+
get '/'
|
24
|
+
headers['Driver'].wont_be_empty
|
25
|
+
headers['Driver'].must_equal 'ec2'
|
26
|
+
headers['Provider'].must_be_nil
|
27
|
+
header 'X-Deltacloud-Driver', 'test'
|
28
|
+
get '/'
|
29
|
+
headers['Driver'].wont_be_empty
|
30
|
+
headers['Driver'].must_equal 'test'
|
31
|
+
headers['Provider'].must_be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should set the provider correctly when using X-Deltacloud-Provider header' do
|
35
|
+
header 'X-Deltacloud-Provider', 'default'
|
36
|
+
get '/'
|
37
|
+
headers['Provider'].wont_be_empty
|
38
|
+
headers['Provider'].must_equal 'default'
|
39
|
+
header 'X-Deltacloud-Provider', 'http://someurl.com:8774/api;1234-1234-1235-1235'
|
40
|
+
get '/'
|
41
|
+
headers['Provider'].wont_be_nil
|
42
|
+
headers['Provider'].must_equal 'http://someurl.com:8774/api;1234-1234-1235-1235'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set both provider and driver' do
|
46
|
+
header 'X-Deltacloud-Provider', 'default'
|
47
|
+
header 'X-Deltacloud-Driver', 'test'
|
48
|
+
get '/'
|
49
|
+
headers['Provider'].must_equal 'default'
|
50
|
+
headers['Driver'].must_equal 'test'
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
require_relative '../../test_helper.rb'
|
4
|
+
require_relative './common.rb'
|
5
|
+
|
6
|
+
class TestEtagApp < Sinatra::Base
|
7
|
+
use Rack::ETag
|
8
|
+
get '/' do
|
9
|
+
params[:test]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe TestEtagApp do
|
14
|
+
|
15
|
+
before do
|
16
|
+
def app; TestEtagApp; end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'add the ETag header to all responses' do
|
20
|
+
get '/?test=1'
|
21
|
+
status.must_equal 200
|
22
|
+
response_body.wont_be_empty
|
23
|
+
headers['ETag'].wont_be_empty
|
24
|
+
headers['ETag'].must_equal 'c4ca4238a0b923820dcc509a6f75849b'
|
25
|
+
get '/?test=2'
|
26
|
+
headers['ETag'].must_equal 'c81e728d9d4c2f636f067f89cc14862c'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|