cloudfiles-sagamore 1.5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -0
- data/CHANGELOG +56 -0
- data/CONTRIBUTORS +34 -0
- data/COPYING +12 -0
- data/Gemfile +7 -0
- data/README.rdoc +81 -0
- data/Rakefile +21 -0
- data/TODO +0 -0
- data/cloudfiles.gemspec +69 -0
- data/lib/client.rb +618 -0
- data/lib/cloudfiles.rb +85 -0
- data/lib/cloudfiles/authentication.rb +52 -0
- data/lib/cloudfiles/connection.rb +286 -0
- data/lib/cloudfiles/container.rb +451 -0
- data/lib/cloudfiles/exception.rb +65 -0
- data/lib/cloudfiles/storage_object.rb +426 -0
- data/lib/cloudfiles/version.rb +3 -0
- data/test/cf-testunit.rb +157 -0
- data/test/cloudfiles_authentication_test.rb +44 -0
- data/test/cloudfiles_client_test.rb +797 -0
- data/test/cloudfiles_connection_test.rb +214 -0
- data/test/cloudfiles_container_test.rb +494 -0
- data/test/cloudfiles_storage_object_test.rb +211 -0
- data/test/test_helper.rb +6 -0
- metadata +112 -0
@@ -0,0 +1,214 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CloudfilesConnectionTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
CloudFiles::Authentication.expects(:new).returns(true)
|
8
|
+
@connection = CloudFiles::Connection.new('dummy_user', 'dummy_key')
|
9
|
+
@connection.storagescheme = "http"
|
10
|
+
@connection.storageport = 80
|
11
|
+
@connection.storagehost = "test.setup.example"
|
12
|
+
@connection.storagepath = "/dummypath/setup"
|
13
|
+
@connection.cdnmgmthost = "test.cdn.example"
|
14
|
+
@connection.cdnmgmtpath = "/dummycdnpath/setup"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initialize
|
18
|
+
assert_equal @connection.authuser, 'dummy_user'
|
19
|
+
assert_equal @connection.authkey, 'dummy_key'
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initalize_with_hash
|
23
|
+
CloudFiles::Authentication.expects(:new).returns(true)
|
24
|
+
@hash_connection = CloudFiles::Connection.new(:username => 'dummy_user', :api_key => 'dummy_key')
|
25
|
+
assert_equal @hash_connection.authuser, "dummy_user"
|
26
|
+
assert_equal @hash_connection.authkey, "dummy_key"
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_authok
|
30
|
+
# This would normally be set in CloudFiles::Authentication
|
31
|
+
assert_equal @connection.authok?, false
|
32
|
+
@connection.expects(:authok?).returns(true)
|
33
|
+
assert_equal @connection.authok?, true
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_snet
|
37
|
+
# This would normally be set in CloudFiles::Authentication
|
38
|
+
assert_equal @connection.snet?, false
|
39
|
+
@connection.expects(:snet?).returns(true)
|
40
|
+
assert_equal @connection.snet?, true
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_get_info
|
44
|
+
@connection.authok = true
|
45
|
+
response = {'x-account-bytes-used' => '9999', 'x-account-container-count' => '5'}
|
46
|
+
SwiftClient.stubs(:head_account).returns(response)
|
47
|
+
@connection.get_info
|
48
|
+
assert_equal @connection.bytes, 9999
|
49
|
+
assert_equal @connection.count, 5
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_get_info_fails
|
53
|
+
@connection.authok = true
|
54
|
+
SwiftClient.stubs(:head_account).raises(ClientException.new("foo", :http_status => 999))
|
55
|
+
assert_raises(CloudFiles::Exception::InvalidResponse) do
|
56
|
+
@connection.get_info
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_public_containers
|
61
|
+
response = [nil, [{"name" => 'foo'}, {"name" => "bar"}, {"name" => "baz"}]]
|
62
|
+
SwiftClient.stubs(:get_account).returns(response)
|
63
|
+
public_containers = @connection.public_containers
|
64
|
+
assert_equal public_containers.size, 3
|
65
|
+
assert_equal public_containers.first, 'foo'
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_public_containers_empty
|
69
|
+
response = [nil, []]
|
70
|
+
SwiftClient.stubs(:get_account).returns(response)
|
71
|
+
public_containers = @connection.public_containers
|
72
|
+
assert_equal public_containers.size, 0
|
73
|
+
assert_equal public_containers.class, Array
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_public_containers_exception
|
77
|
+
SwiftClient.stubs(:get_account).raises(ClientException.new("test_public_containers_exception", :http_status => 999))
|
78
|
+
assert_raises(CloudFiles::Exception::InvalidResponse) do
|
79
|
+
public_containers = @connection.public_containers
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_delete_container
|
84
|
+
SwiftClient.stubs(:delete_container).returns(nil)
|
85
|
+
response = @connection.delete_container("good_container")
|
86
|
+
assert_equal response, true
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_delete_nonempty_container
|
90
|
+
SwiftClient.stubs(:delete_container).raises(ClientException.new("test_delete_nonempty_container", :http_status => 409))
|
91
|
+
assert_raises(CloudFiles::Exception::NonEmptyContainer) do
|
92
|
+
response = @connection.delete_container("not_empty")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_delete_unknown_container
|
97
|
+
SwiftClient.stubs(:delete_container).raises(ClientException.new("test_delete_unknown_container", :http_status => 999))
|
98
|
+
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
99
|
+
response = @connection.delete_container("not_empty")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_create_container
|
104
|
+
response = [ { "content-type"=>"application/json; charset=utf-8", "x-container-object-count"=>"1", "date"=>"", "x-container-bytes-used"=>"0", "content-length"=>"0", "accept-ranges"=>"bytes", "x-trans-id"=>"foo" }, [ { "bytes"=>0, "name"=>"foo.jpg", "content_type"=>"image/jpeg", "hash"=>"foo", "last_modified"=>"" } ] ]
|
105
|
+
CloudFiles::Container.any_instance.stubs(:container_metadata).returns(response[0])
|
106
|
+
SwiftClient.stubs(:put_container).returns(nil)
|
107
|
+
container = @connection.create_container('good_container')
|
108
|
+
assert_equal container.name, 'good_container'
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_create_container_with_invalid_name
|
112
|
+
assert_raise(CloudFiles::Exception::Syntax) do
|
113
|
+
container = @connection.create_container('a'*300)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_create_container_name_filter
|
118
|
+
assert_raises(CloudFiles::Exception::Syntax) do
|
119
|
+
container = @connection.create_container('this/has/bad?characters')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_create_container_error
|
124
|
+
SwiftClient.stubs(:put_container).raises(ClientException.new("test_create_container_general_error", :http_status => 999))
|
125
|
+
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
126
|
+
container = @connection.create_container('foobar')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_container_exists_true
|
131
|
+
response = {"x-container-object-count"=>"0", "date"=>"Fri, 02 Sep 2011 20:27:15 GMT", "x-container-bytes-used"=>"0", "content-length"=>"0", "accept-ranges"=>"bytes", "x-trans-id"=>"foo"}
|
132
|
+
SwiftClient.stubs(:head_container).returns(response)
|
133
|
+
assert_equal @connection.container_exists?('this_container_exists'), true
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_container_exists_false
|
137
|
+
SwiftClient.stubs(:head_container).raises(ClientException.new("test_container_exists_false", :http_status => 404))
|
138
|
+
assert_equal @connection.container_exists?('this_does_not_exist'), false
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_fetch_exisiting_container
|
142
|
+
response = [ { "content-type"=>"application/json; charset=utf-8", "x-container-object-count"=>"1", "date"=>"", "x-container-bytes-used"=>"0", "content-length"=>"0", "accept-ranges"=>"bytes", "x-trans-id"=>"foo" }, [ { "bytes"=>0, "name"=>"foo.jpg", "content_type"=>"image/jpeg", "hash"=>"foo", "last_modified"=>"" } ] ]
|
143
|
+
CloudFiles::Container.any_instance.stubs(:container_metadata).returns(response[0])
|
144
|
+
container = @connection.container('good_container')
|
145
|
+
assert_equal container.name, 'good_container'
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_fetch_nonexistent_container
|
149
|
+
CloudFiles::Container.any_instance.stubs(:container_metadata).raises(CloudFiles::Exception::NoSuchContainer)
|
150
|
+
assert_raise(CloudFiles::Exception::NoSuchContainer) do
|
151
|
+
container = @connection.container('bad_container')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_containers
|
156
|
+
response = [nil, [{"name" => 'foo'}, {"name" => "bar"}, {"name" => "baz"}, {"name" => "boo"}]]
|
157
|
+
SwiftClient.stubs(:get_account).returns(response)
|
158
|
+
containers = @connection.containers
|
159
|
+
assert_equal containers.size, 4
|
160
|
+
assert_equal containers.first, 'foo'
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_containers_with_limit
|
164
|
+
response = [nil, [{"name" => 'foo'}]]
|
165
|
+
SwiftClient.stubs(:get_account).returns(response)
|
166
|
+
containers = @connection.containers(1)
|
167
|
+
assert_equal containers.size, 1
|
168
|
+
assert_equal containers.first, 'foo'
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_containers_with_marker
|
172
|
+
response = [nil, [{"name" => "boo"}]]
|
173
|
+
SwiftClient.stubs(:get_account).returns(response)
|
174
|
+
containers = @connection.containers(0, 'baz')
|
175
|
+
assert_equal containers.size, 1
|
176
|
+
assert_equal containers.first, 'boo'
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_no_containers_yet
|
180
|
+
response = [nil, []]
|
181
|
+
SwiftClient.stubs(:get_account).returns(response)
|
182
|
+
containers = @connection.containers
|
183
|
+
assert_equal containers.size, 0
|
184
|
+
assert_equal containers.class, Array
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_containers_bad_result
|
188
|
+
SwiftClient.stubs(:get_account).raises(ClientException.new("foo", :http_status => 999))
|
189
|
+
assert_raises(CloudFiles::Exception::InvalidResponse) do
|
190
|
+
containers = @connection.containers
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_containers_detail
|
195
|
+
response = [nil, [{"bytes"=>"42", "name"=>"CWX", "count"=>"3"}]]
|
196
|
+
SwiftClient.stubs(:get_account).returns(response)
|
197
|
+
details = @connection.containers_detail
|
198
|
+
assert_equal details['CWX'][:count], "3"
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_empty_containers_detail
|
202
|
+
response = [nil, []]
|
203
|
+
SwiftClient.stubs(:get_account).returns(response)
|
204
|
+
details = @connection.containers_detail
|
205
|
+
assert_equal details, {}
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_containers_detail_bad_response
|
209
|
+
SwiftClient.stubs(:get_account).raises(ClientException.new("foo", :http_status => 999))
|
210
|
+
assert_raises(CloudFiles::Exception::InvalidResponse) do
|
211
|
+
details = @connection.containers_detail
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,494 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CloudfilesContainerTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_object_creation
|
7
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => nil, :storageurl => nil, :authtoken => "dummy token")
|
8
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
|
9
|
+
SwiftClient.stubs(:head_container).returns(response)
|
10
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
11
|
+
assert_equal @container.name, 'test_container'
|
12
|
+
assert_equal @container.class, CloudFiles::Container
|
13
|
+
assert_equal @container.public?, false
|
14
|
+
assert_equal @container.cdn_url, nil
|
15
|
+
assert_equal @container.cdn_ttl, nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_object_creation_with_no_cdn_available
|
19
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => nil, :storageurl => nil, :authtoken => "dummy token")
|
20
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
|
21
|
+
SwiftClient.stubs(:head_container).returns(response)
|
22
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
23
|
+
assert_equal 'test_container', @container.name
|
24
|
+
assert_equal CloudFiles::Container, @container.class
|
25
|
+
assert_equal false, @container.public?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_object_creation_no_such_container
|
29
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => nil, :storageurl => nil, :authtoken => "dummy token")
|
30
|
+
SwiftClient.stubs(:head_container).raises(ClientException.new("foobar", :http_status => 404))
|
31
|
+
assert_raise(CloudFiles::Exception::NoSuchContainer) do
|
32
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_object_creation_with_cdn
|
37
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => nil, :storageurl => nil, :authtoken => "dummy token")
|
38
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-cdn-enabled' => 'True', 'x-cdn-uri' => 'http://cdn.test.example/container', 'x-ttl' => '86400'}
|
39
|
+
SwiftClient.stubs(:head_container).returns(response)
|
40
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
41
|
+
assert_equal @container.name, 'test_container'
|
42
|
+
assert_equal @container.cdn_enabled, true
|
43
|
+
assert_equal @container.public?, true
|
44
|
+
assert_equal @container.cdn_url, 'http://cdn.test.example/container'
|
45
|
+
assert_equal @container.cdn_ttl, 86400
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_to_s
|
49
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => nil, :storageurl => nil, :authtoken => "dummy token")
|
50
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-cdn-enabled' => 'True', 'x-cdn-uri' => 'http://cdn.test.example/container', 'x-ttl' => '86400'}
|
51
|
+
SwiftClient.stubs(:head_container).returns(response)
|
52
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
53
|
+
assert_equal @container.to_s, 'test_container'
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_make_private_succeeds
|
57
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => nil, :storageurl => nil, :authtoken => "dummy token", :container_metadata => {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'})
|
58
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-cdn-enabled' => 'True', 'x-cdn-uri' => 'http://cdn.test.example/container', 'x-ttl' => '86400'}
|
59
|
+
SwiftClient.stubs(:head_container).returns(response)
|
60
|
+
SwiftClient.stubs(:post_container).returns(nil)
|
61
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
62
|
+
assert_nothing_raised do
|
63
|
+
@container.make_private
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_make_private_fails
|
68
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => nil, :storageurl => nil, :authtoken => "dummy token", :container_metadata => {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'})
|
69
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-cdn-enabled' => 'True', 'x-cdn-uri' => 'http://cdn.test.example/container', 'x-ttl' => '86400'}
|
70
|
+
SwiftClient.stubs(:head_container).returns(response)
|
71
|
+
SwiftClient.stubs(:post_container).raises(ClientException.new("test_make_private_fails", :http_status => 404))
|
72
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
73
|
+
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
74
|
+
@container.make_private
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_make_public_succeeds
|
79
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
80
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-cdn-enabled' => 'True', 'x-cdn-uri' => 'http://cdn.test.example/container', 'x-ttl' => '86400'}
|
81
|
+
SwiftClient.stubs(:put_container).returns(nil)
|
82
|
+
SwiftClient.stubs(:head_container).returns(response)
|
83
|
+
CloudFiles::Container.any_instance.stubs(:post_with_headers).returns(nil)
|
84
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
85
|
+
assert_nothing_raised do
|
86
|
+
@container.make_public
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_make_public_fixnum_ttl_deprication_warning_and_succeeds
|
91
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
92
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-cdn-enabled' => 'True', 'x-cdn-uri' => 'http://cdn.test.example/container', 'x-ttl' => '86400'}
|
93
|
+
SwiftClient.stubs(:put_container).returns(nil)
|
94
|
+
SwiftClient.stubs(:head_container).returns(response)
|
95
|
+
CloudFiles::Container.any_instance.stubs(:post_with_headers).returns(nil)
|
96
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
97
|
+
assert_nothing_raised do
|
98
|
+
@container.make_public(:ttl => 123)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_make_public_fails
|
103
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
104
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-cdn-enabled' => 'True', 'x-cdn-uri' => 'http://cdn.test.example/container', 'x-ttl' => '86400'}
|
105
|
+
SwiftClient.stubs(:head_container).returns(response)
|
106
|
+
SwiftClient.stubs(:put_container).raises(ClientException.new("test_make_public_fails", :http_status => 404))
|
107
|
+
CloudFiles::Container.any_instance.stubs(:post_with_headers).returns(nil)
|
108
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
109
|
+
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
110
|
+
@container.make_public
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_empty_is_false
|
115
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
116
|
+
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
|
117
|
+
SwiftClient.stubs(:head_container).returns(response)
|
118
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
119
|
+
assert_equal @container.empty?, false
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_empty_is_true
|
123
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
124
|
+
response = {'x-container-bytes-used' => '0', 'x-container-object-count' => '0'}
|
125
|
+
SwiftClient.stubs(:head_container).returns(response)
|
126
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
127
|
+
assert_equal @container.empty?, true
|
128
|
+
end
|
129
|
+
|
130
|
+
def build_acl_test_state(opts={})
|
131
|
+
@connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
132
|
+
|
133
|
+
@response = {
|
134
|
+
'x-container-bytes-used' => '0',
|
135
|
+
'x-container-object-count' => '0',
|
136
|
+
}.merge(opts.fetch(:response, {}))
|
137
|
+
|
138
|
+
@response.stubs(:code).returns(opts.fetch(:code, '204'))
|
139
|
+
if opts[:code] =~ /^![2]0/
|
140
|
+
SwiftClient.stubs(:head_container).raises(ClientException.new("acl_test_state", :http_status => opts.fetch(:code, 204)))
|
141
|
+
else
|
142
|
+
SwiftClient.stubs(:head_container).returns(@response)
|
143
|
+
end
|
144
|
+
@container = CloudFiles::Container.new(@connection, 'test_container')
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_read_acl_is_set_from_headers
|
148
|
+
@connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
149
|
+
@response = {'x-container-bytes-used' => '0','x-container-object-count' => '0', 'x-container-read' => '.r:*'}
|
150
|
+
SwiftClient.stubs(:head_container).returns(@response)
|
151
|
+
@container = CloudFiles::Container.new(@connection, 'test_container')
|
152
|
+
assert_equal @response["x-container-read"], @container.read_acl
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_set_read_acl_fails
|
156
|
+
@connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
157
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
158
|
+
SwiftClient.stubs(:post_container).raises(ClientException.new("test_set_read_acl_fails", :http_status => 404))
|
159
|
+
@container = CloudFiles::Container.new(@connection, 'test_container')
|
160
|
+
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
161
|
+
@container.set_read_acl('.r:*')
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_set_read_acl_succeeds
|
166
|
+
@connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
167
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0', 'x-container-write' => '.r:*'})
|
168
|
+
SwiftClient.stubs(:post_container).returns(true)
|
169
|
+
@container = CloudFiles::Container.new(@connection, 'test_container')
|
170
|
+
assert_equal @container.set_read_acl('.r:*'), true
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_write_acl_is_set_from_headers
|
174
|
+
@connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
175
|
+
@response = {'x-container-bytes-used' => '0','x-container-object-count' => '0', 'x-container-write' => '.r:*'}
|
176
|
+
SwiftClient.stubs(:head_container).returns(@response)
|
177
|
+
@container = CloudFiles::Container.new(@connection, 'test_container')
|
178
|
+
assert_equal @response["x-container-write"], @container.write_acl
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_set_write_acl_fails
|
182
|
+
@connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
183
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
184
|
+
SwiftClient.stubs(:post_container).raises(ClientException.new("test_set_write_acl_fails", :http_status => 404))
|
185
|
+
@container = CloudFiles::Container.new(@connection, 'test_container')
|
186
|
+
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
187
|
+
@container.set_write_acl('.r:*')
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_set_write_acl_succeeds
|
192
|
+
@connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://cdn.test.example/container', :storageurl => nil, :authtoken => "dummy token")
|
193
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0', 'x-container-write' => '.r:*'})
|
194
|
+
SwiftClient.stubs(:post_container).returns(true)
|
195
|
+
@container = CloudFiles::Container.new(@connection, 'test_container')
|
196
|
+
assert_equal @container.set_write_acl('.r:*'), true
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_log_retention_is_true
|
200
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
201
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0', 'x-container-object-count' => '0', 'x-cdn-enabled' => 'True', 'x-log-retention' => 'True'})
|
202
|
+
@container = CloudFiles::Container.new(connection, 'test_container')
|
203
|
+
assert_equal @container.log_retention?, true
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_object_fetch
|
207
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
208
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
209
|
+
SwiftClient.stubs(:head_object).returns({'last-modified' => 'Wed, 28 Jan 2009 16:16:26 GMT'})
|
210
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
211
|
+
object = @container.object('good_object')
|
212
|
+
assert_equal object.class, CloudFiles::StorageObject
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_create_object
|
216
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
217
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
218
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
219
|
+
object = @container.create_object('new_object')
|
220
|
+
assert_equal object.class, CloudFiles::StorageObject
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_object_exists_true
|
224
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
225
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
226
|
+
SwiftClient.stubs(:head_object).returns({'last-modified' => 'Wed, 28 Jan 2009 16:16:26 GMT'})
|
227
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
228
|
+
assert_equal @container.object_exists?('good_object'), true
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_object_exists_false
|
232
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
233
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
234
|
+
SwiftClient.stubs(:head_object).raises(ClientException.new("test_object_exists_false", :http_status => 404))
|
235
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
236
|
+
assert_equal @container.object_exists?('bad_object'), false
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_delete_object_succeeds
|
240
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
241
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
242
|
+
SwiftClient.stubs(:delete_object).returns(nil)
|
243
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
244
|
+
assert_nothing_raised do
|
245
|
+
@container.delete_object('good_object')
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_delete_invalid_object_fails
|
250
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
251
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
252
|
+
SwiftClient.stubs(:delete_object).raises(ClientException.new('test_delete_invalid_object_fails', :http_status => 404))
|
253
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
254
|
+
assert_raise(CloudFiles::Exception::NoSuchObject) do
|
255
|
+
@container.delete_object('nonexistent_object')
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_delete_invalid_response_code_fails
|
260
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
261
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
262
|
+
SwiftClient.stubs(:delete_object).raises(ClientException.new('test_delete_invalid_object_fails', :http_status => 999))
|
263
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
264
|
+
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
265
|
+
@container.delete_object('broken_object')
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_fetch_objects
|
270
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
271
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
272
|
+
SwiftClient.stubs(:get_container).returns([{'x-container-bytes-used' => '10','x-container-object-count' => '1'}, [{'name' => 'foo'},{'name' => 'bar'},{'name' => 'baz'}]])
|
273
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
274
|
+
|
275
|
+
objects = @container.objects
|
276
|
+
assert_equal objects.class, Array
|
277
|
+
assert_equal objects.size, 3
|
278
|
+
assert_equal objects.first, 'foo'
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_fetch_objects_fails
|
282
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
283
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
284
|
+
SwiftClient.stubs(:get_container).raises(ClientException.new("test_fetch_object_fails", :http_status => 500))
|
285
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
286
|
+
|
287
|
+
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
288
|
+
objects = @container.objects
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_fetch_objects_with_limit
|
293
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
294
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
295
|
+
SwiftClient.stubs(:get_container).returns([{'x-container-bytes-used' => '10','x-container-object-count' => '1'}, [{'name' => 'foo'}]])
|
296
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
297
|
+
|
298
|
+
objects = @container.objects(:limit => 1)
|
299
|
+
assert_equal objects.class, Array
|
300
|
+
assert_equal objects.size, 1
|
301
|
+
assert_equal objects.first, 'foo'
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_fetch_objects_with_marker
|
305
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
306
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
307
|
+
SwiftClient.stubs(:get_container).returns([{'x-container-bytes-used' => '10','x-container-object-count' => '1'}, [{'name' => 'bar'}]])
|
308
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
309
|
+
|
310
|
+
objects = @container.objects(:marker => 'foo')
|
311
|
+
assert_equal objects.class, Array
|
312
|
+
assert_equal objects.size, 1
|
313
|
+
assert_equal objects.first, 'bar'
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_fetch_objects_with_deprecated_offset_param
|
317
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
318
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
319
|
+
SwiftClient.stubs(:get_container).returns([{'x-container-bytes-used' => '10','x-container-object-count' => '1'}, [{'name' => 'bar'}]])
|
320
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
321
|
+
|
322
|
+
objects = @container.objects(:offset => 'foo')
|
323
|
+
assert_equal objects.class, Array
|
324
|
+
assert_equal objects.size, 1
|
325
|
+
assert_equal objects.first, 'bar'
|
326
|
+
end
|
327
|
+
|
328
|
+
def object_detail_body(skip_kisscam=false)
|
329
|
+
lines = []
|
330
|
+
lines << {'name' => 'kisscam.mov', 'hash' => '96efd5a0d78b74cfe2a911c479b98ddd', 'bytes' => '9196332', 'content_type' => 'video/quicktime', 'last_modified' => '2008-12-18T10:34:43.867648'} unless skip_kisscam
|
331
|
+
lines << {'name' => 'penaltybox.mov', 'hash' => 'd2a4c0c24d8a7b4e935bee23080e0685', 'bytes' => '24944966', 'content_type' => 'video/quicktime', 'last_modified' => '2008-12-18T10:35:19.273927'}
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_fetch_objects_detail
|
335
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
336
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '2'})
|
337
|
+
SwiftClient.stubs(:get_container).returns([{'x-container-bytes-used' => '10','x-container-object-count' => '2'}, object_detail_body])
|
338
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
339
|
+
|
340
|
+
details = @container.objects_detail
|
341
|
+
assert_equal details.size, 2
|
342
|
+
assert_equal details['kisscam.mov'][:bytes], '9196332'
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_fetch_objects_details_with_limit
|
346
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
347
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '2'})
|
348
|
+
SwiftClient.stubs(:get_container).returns([{'x-container-bytes-used' => '10','x-container-object-count' => '2'}, object_detail_body])
|
349
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
350
|
+
|
351
|
+
details = @container.objects_detail(:limit => 2)
|
352
|
+
assert_equal details.size, 2
|
353
|
+
assert_equal details['kisscam.mov'][:bytes], '9196332'
|
354
|
+
end
|
355
|
+
|
356
|
+
def test_fetch_objects_detail_with_marker
|
357
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
358
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
359
|
+
SwiftClient.stubs(:get_container).returns([{'x-container-bytes-used' => '10','x-container-object-count' => '1'}, object_detail_body(true)])
|
360
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
361
|
+
|
362
|
+
details = @container.objects_detail(:marker => 'kisscam.mov')
|
363
|
+
assert_equal details.size, 1
|
364
|
+
assert_equal details['penaltybox.mov'][:bytes], '24944966'
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_fetch_objects_detail_with_deprecated_offset_param
|
368
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
369
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '10','x-container-object-count' => '1'})
|
370
|
+
SwiftClient.stubs(:get_container).returns([{'x-container-bytes-used' => '10','x-container-object-count' => '1'}, object_detail_body(true)])
|
371
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
372
|
+
|
373
|
+
details = @container.objects_detail(:offset => 'kisscam.mov')
|
374
|
+
assert_equal details.size, 1
|
375
|
+
assert_equal details['penaltybox.mov'][:bytes], '24944966'
|
376
|
+
end
|
377
|
+
|
378
|
+
|
379
|
+
def test_fetch_object_detail_empty
|
380
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
381
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
382
|
+
SwiftClient.stubs(:get_container).returns([{'x-container-bytes-used' => '0','x-container-object-count' => '0'}, {}])
|
383
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
384
|
+
|
385
|
+
details = @container.objects_detail
|
386
|
+
assert_equal details, {}
|
387
|
+
end
|
388
|
+
|
389
|
+
def test_fetch_object_detail_error
|
390
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
391
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
392
|
+
SwiftClient.stubs(:get_container).raises(ClientException.new('test_fetch_object_detail_error', :http_status => 999))
|
393
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
394
|
+
|
395
|
+
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
396
|
+
details = @container.objects_detail
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
def test_setting_log_retention
|
401
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
402
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
403
|
+
SwiftClient.stubs(:post_container).returns(true)
|
404
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
405
|
+
|
406
|
+
assert(@container.log_retention='false')
|
407
|
+
end
|
408
|
+
|
409
|
+
def test_setting_log_retention_fails
|
410
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
411
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
412
|
+
SwiftClient.stubs(:post_container).raises(ClientException.new("test_setting_log_retention_fails", :http_status => 500))
|
413
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
414
|
+
|
415
|
+
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
416
|
+
@container.log_retention='false'
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
def test_purge_from_cdn_succeeds
|
421
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
422
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
423
|
+
SwiftClient.stubs(:delete_container).returns(nil)
|
424
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
425
|
+
|
426
|
+
assert_nothing_raised do
|
427
|
+
@container.purge_from_cdn
|
428
|
+
@container.purge_from_cdn("small.fox@hole.org")
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
def test_purge_from_cdn_fails
|
433
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
434
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
435
|
+
SwiftClient.stubs(:delete_container).raises(ClientException.new("test_purge_from_cdn_fails", :http_status => 500))
|
436
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
437
|
+
|
438
|
+
assert_raise(CloudFiles::Exception::Connection) do
|
439
|
+
@container.purge_from_cdn
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
def test_cdn_metadata_fails
|
444
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
445
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
446
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
447
|
+
SwiftClient.stubs(:head_container).raises(ClientException.new("test_cdn_metadata_fails", :http_status => 404))
|
448
|
+
assert_raise(CloudFiles::Exception::NoSuchContainer) do
|
449
|
+
@container.cdn_metadata
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
def test_cdn_metadata_no_cdn
|
454
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
455
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '0'})
|
456
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
457
|
+
assert_equal @container.cdn_metadata, {}
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_bytes
|
461
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
462
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '99','x-container-object-count' => '10'})
|
463
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
464
|
+
assert_equal @container.bytes, 99
|
465
|
+
end
|
466
|
+
|
467
|
+
def test_count
|
468
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => false, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
469
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '10'})
|
470
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
471
|
+
assert_equal @container.count, 10
|
472
|
+
end
|
473
|
+
|
474
|
+
def test_cdn_ssl_url
|
475
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
476
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '10', 'x-cdn-ssl-uri' => 'https://ssl.cdn.test.example/container', "x-cdn-enabled" => 'True'})
|
477
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
478
|
+
assert_equal @container.cdn_ssl_url, 'https://ssl.cdn.test.example/container'
|
479
|
+
end
|
480
|
+
|
481
|
+
def test_cdn_url
|
482
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
483
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '10', 'x-cdn-uri' => 'http://cdn.test.example/container', "x-cdn-enabled" => 'True'})
|
484
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
485
|
+
assert_equal @container.cdn_url, 'http://cdn.test.example/container'
|
486
|
+
end
|
487
|
+
|
488
|
+
def test_metadata
|
489
|
+
connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdnmgmthost => 'cdm.test.example', :cdnmgmtpath => '/dummy/path', :cdnmgmtport => 443, :cdnmgmtscheme => 'https', :cdn_available? => true, :cdnurl => 'http://foo.test.example/container', :storageurl => 'http://foo.test.example/container', :authtoken => "dummy token")
|
490
|
+
SwiftClient.stubs(:head_container).returns({'x-container-bytes-used' => '0','x-container-object-count' => '10', 'x-container-meta-foo' => 'bar'})
|
491
|
+
@container = CloudFiles::Container.new(connection, "test_container")
|
492
|
+
assert_equal @container.metadata, {'foo' => 'bar'}
|
493
|
+
end
|
494
|
+
end
|