cloudfiles 1.4.18 → 1.5.0
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/CHANGELOG +6 -0
- data/CONTRIBUTORS +1 -0
- data/cloudfiles.gemspec +5 -3
- data/lib/client.rb +620 -0
- data/lib/cloudfiles.rb +1 -1
- data/lib/cloudfiles/authentication.rb +10 -25
- data/lib/cloudfiles/connection.rb +55 -123
- data/lib/cloudfiles/container.rb +89 -73
- data/lib/cloudfiles/storage_object.rb +52 -36
- data/lib/cloudfiles/version.rb +1 -1
- data/test/cloudfiles_authentication_test.rb +17 -22
- data/test/cloudfiles_client_test.rb +797 -0
- data/test/cloudfiles_connection_test.rb +53 -194
- data/test/cloudfiles_container_test.rb +253 -121
- data/test/cloudfiles_storage_object_test.rb +51 -65
- data/test/test_helper.rb +1 -0
- metadata +12 -10
@@ -6,6 +6,8 @@ class CloudfilesConnectionTest < Test::Unit::TestCase
|
|
6
6
|
def setup
|
7
7
|
CloudFiles::Authentication.expects(:new).returns(true)
|
8
8
|
@connection = CloudFiles::Connection.new('dummy_user', 'dummy_key')
|
9
|
+
@connection.storagescheme = "http"
|
10
|
+
@connection.storageport = 80
|
9
11
|
@connection.storagehost = "test.setup.example"
|
10
12
|
@connection.storagepath = "/dummypath/setup"
|
11
13
|
@connection.cdnmgmthost = "test.cdn.example"
|
@@ -17,6 +19,13 @@ class CloudfilesConnectionTest < Test::Unit::TestCase
|
|
17
19
|
assert_equal @connection.authkey, 'dummy_key'
|
18
20
|
end
|
19
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
|
+
|
20
29
|
def test_authok
|
21
30
|
# This would normally be set in CloudFiles::Authentication
|
22
31
|
assert_equal @connection.authok?, false
|
@@ -30,326 +39,176 @@ class CloudfilesConnectionTest < Test::Unit::TestCase
|
|
30
39
|
@connection.expects(:snet?).returns(true)
|
31
40
|
assert_equal @connection.snet?, true
|
32
41
|
end
|
33
|
-
|
34
|
-
def test_cfreq_get
|
35
|
-
build_net_http_object
|
36
|
-
assert_nothing_raised do
|
37
|
-
response = @connection.cfreq("GET", "test.server.example", "/dummypath", "80", "http")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_cfreq_post
|
42
|
-
build_net_http_object
|
43
|
-
assert_nothing_raised do
|
44
|
-
response = @connection.cfreq("POST", "test.server.example", "/dummypath", "80", "http")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_cfreq_put
|
49
|
-
build_net_http_object
|
50
|
-
assert_nothing_raised do
|
51
|
-
response = @connection.cfreq("PUT", "test.server.example", "/dummypath", "80", "http")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_cfreq_delete
|
56
|
-
build_net_http_object
|
57
|
-
assert_nothing_raised do
|
58
|
-
response = @connection.cfreq("DELETE", "test.server.example", "/dummypath", "80", "http")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_cfreq_with_static_data
|
63
|
-
build_net_http_object
|
64
|
-
assert_nothing_raised do
|
65
|
-
response = @connection.cfreq("PUT", "test.server.example", "/dummypath", "80", "http", {}, "This is string data")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_cfreq_with_stream_data
|
70
|
-
build_net_http_object
|
71
|
-
require 'tempfile'
|
72
|
-
file = Tempfile.new("test")
|
73
|
-
assert_nothing_raised do
|
74
|
-
response = @connection.cfreq("PUT", "test.server.example", "/dummypath", "80", "http", {}, file)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_cfreq_head
|
79
|
-
build_net_http_object
|
80
|
-
assert_nothing_raised do
|
81
|
-
response = @connection.cfreq("HEAD", "test.server.example", "/dummypath", "80", "http")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_storage_request
|
86
|
-
build_net_http_object
|
87
|
-
assert_nothing_raised do
|
88
|
-
response = @connection.storage_request("HEAD", "dummypath")
|
89
|
-
end
|
90
|
-
end
|
91
42
|
|
92
|
-
def test_storage_request_adds_path
|
93
|
-
build_net_http_object({}, {:method => "HEAD", :path => "#{@connection.storagepath}/dummypath"})
|
94
|
-
assert_nothing_raised do
|
95
|
-
response = @connection.storage_request("HEAD", "dummypath")
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_storage_path_does_not_add_path_when_absolute
|
100
|
-
build_net_http_object({}, {:method => "HEAD", :path => "/dummypath"})
|
101
|
-
assert_nothing_raised do
|
102
|
-
response = @connection.storage_request("HEAD", "/dummypath")
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_cdn_request
|
107
|
-
build_net_http_object
|
108
|
-
assert_nothing_raised do
|
109
|
-
response = @connection.cdn_request("HEAD", "dummypath")
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_cdn_request_adds_path
|
114
|
-
build_net_http_object({}, {:method => "HEAD", :path => "#{@connection.cdnmgmtpath}/dummypath"})
|
115
|
-
assert_nothing_raised do
|
116
|
-
response = @connection.cdn_request("HEAD", "dummypath")
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_cdn_path_does_not_add_path_when_absolute
|
121
|
-
build_net_http_object({}, {:method => "HEAD", :path => "/dummypath"})
|
122
|
-
assert_nothing_raised do
|
123
|
-
response = @connection.cdn_request("HEAD", "/dummypath")
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_net_http_raises_connection_exception
|
128
|
-
Net::HTTP.expects(:new).raises(CloudFiles::Exception::Connection)
|
129
|
-
assert_raises(CloudFiles::Exception::Connection) do
|
130
|
-
response = @connection.cfreq("GET", "test.server.example", "/dummypath", "80", "http")
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_net_http_raises_one_eof_exception
|
135
|
-
response = {'x-cdn-management-url' => 'http://cdn.example.com/path', 'x-storage-url' => 'http://cdn.example.com/storage', 'authtoken' => 'dummy_token'}
|
136
|
-
response.stubs(:code).returns('204')
|
137
|
-
server = stub(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
|
138
|
-
server.stubs(:request).raises(EOFError).then.returns(response)
|
139
|
-
Net::HTTP.stubs(:new).returns(server)
|
140
|
-
assert_nothing_raised do
|
141
|
-
response = @connection.cfreq("GET", "test.server.example", "/dummypath", "443", "https")
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_net_http_raises_one_expired_token
|
146
|
-
CloudFiles::Authentication.expects(:new).returns(true)
|
147
|
-
response = {'x-cdn-management-url' => 'http://cdn.example.com/path', 'x-storage-url' => 'http://cdn.example.com/storage', 'authtoken' => 'dummy_token'}
|
148
|
-
response.stubs(:code).returns('401').then.returns('204')
|
149
|
-
server = stub(:use_ssl= => true, :verify_mode= => true, :start => true)
|
150
|
-
server.stubs(:request).returns(response)
|
151
|
-
Net::HTTP.stubs(:new).returns(server)
|
152
|
-
assert_nothing_raised do
|
153
|
-
response = @connection.cfreq("GET", "test.server.example", "/dummypath", "80", "http")
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_net_http_raises_continual_eof_exceptions
|
158
|
-
response = {'x-cdn-management-url' => 'http://cdn.example.com/path', 'x-storage-url' => 'http://cdn.example.com/storage', 'authtoken' => 'dummy_token'}
|
159
|
-
response.stubs(:code).returns('204')
|
160
|
-
server = stub(:use_ssl= => true, :verify_mode= => true, :start => true)
|
161
|
-
server.stubs(:finish).returns(true)
|
162
|
-
server.stubs(:request).raises(EOFError)
|
163
|
-
CloudFiles::Connection.any_instance.stubs(:get_info).returns({:bytes => @bytes, :count => @count})
|
164
|
-
Net::HTTP.stubs(:new).returns(server)
|
165
|
-
assert_raises(CloudFiles::Exception::Connection) do
|
166
|
-
response = @connection.cfreq("GET", "test.server.example", "/dummypath", "80", "http")
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
43
|
def test_get_info
|
171
|
-
|
44
|
+
@connection.authok = true
|
45
|
+
response = {'x-account-bytes-used' => '9999', 'x-account-container-count' => '5'}
|
46
|
+
SwiftClient.stubs(:head_account).returns(response)
|
172
47
|
@connection.get_info
|
173
48
|
assert_equal @connection.bytes, 9999
|
174
49
|
assert_equal @connection.count, 5
|
175
50
|
end
|
176
51
|
|
177
52
|
def test_get_info_fails
|
178
|
-
|
53
|
+
@connection.authok = true
|
54
|
+
SwiftClient.stubs(:head_account).raises(ClientException.new("foo", :http_status => 999))
|
179
55
|
assert_raises(CloudFiles::Exception::InvalidResponse) do
|
180
56
|
@connection.get_info
|
181
57
|
end
|
182
58
|
end
|
183
59
|
|
184
60
|
def test_public_containers
|
185
|
-
|
61
|
+
response = [nil, [{"name" => 'foo'}, {"name" => "bar"}, {"name" => "baz"}]]
|
62
|
+
SwiftClient.stubs(:get_account).returns(response)
|
186
63
|
public_containers = @connection.public_containers
|
187
64
|
assert_equal public_containers.size, 3
|
188
65
|
assert_equal public_containers.first, 'foo'
|
189
66
|
end
|
190
67
|
|
191
68
|
def test_public_containers_empty
|
192
|
-
|
69
|
+
response = [nil, []]
|
70
|
+
SwiftClient.stubs(:get_account).returns(response)
|
193
71
|
public_containers = @connection.public_containers
|
194
72
|
assert_equal public_containers.size, 0
|
195
73
|
assert_equal public_containers.class, Array
|
196
74
|
end
|
197
75
|
|
198
76
|
def test_public_containers_exception
|
199
|
-
|
77
|
+
SwiftClient.stubs(:get_account).raises(ClientException.new("test_public_containers_exception", :http_status => 999))
|
200
78
|
assert_raises(CloudFiles::Exception::InvalidResponse) do
|
201
79
|
public_containers = @connection.public_containers
|
202
80
|
end
|
203
81
|
end
|
204
82
|
|
205
83
|
def test_delete_container
|
206
|
-
|
84
|
+
SwiftClient.stubs(:delete_container).returns(nil)
|
207
85
|
response = @connection.delete_container("good_container")
|
208
86
|
assert_equal response, true
|
209
87
|
end
|
210
88
|
|
211
89
|
def test_delete_nonempty_container
|
212
|
-
|
90
|
+
SwiftClient.stubs(:delete_container).raises(ClientException.new("test_delete_nonempty_container", :http_status => 409))
|
213
91
|
assert_raises(CloudFiles::Exception::NonEmptyContainer) do
|
214
92
|
response = @connection.delete_container("not_empty")
|
215
93
|
end
|
216
94
|
end
|
217
95
|
|
218
96
|
def test_delete_unknown_container
|
219
|
-
|
97
|
+
SwiftClient.stubs(:delete_container).raises(ClientException.new("test_delete_unknown_container", :http_status => 999))
|
220
98
|
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
221
99
|
response = @connection.delete_container("not_empty")
|
222
100
|
end
|
223
101
|
end
|
224
102
|
|
225
103
|
def test_create_container
|
226
|
-
|
227
|
-
|
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)
|
228
107
|
container = @connection.create_container('good_container')
|
229
108
|
assert_equal container.name, 'good_container'
|
230
109
|
end
|
231
110
|
|
232
111
|
def test_create_container_with_invalid_name
|
233
|
-
CloudFiles::Container.stubs(:new)
|
234
112
|
assert_raise(CloudFiles::Exception::Syntax) do
|
235
113
|
container = @connection.create_container('a'*300)
|
236
114
|
end
|
237
115
|
end
|
238
116
|
|
239
117
|
def test_create_container_name_filter
|
240
|
-
CloudFiles::Container.any_instance.stubs(:populate)
|
241
|
-
build_net_http_object(:code => '201')
|
242
118
|
assert_raises(CloudFiles::Exception::Syntax) do
|
243
119
|
container = @connection.create_container('this/has/bad?characters')
|
244
120
|
end
|
245
121
|
end
|
246
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
|
+
|
247
130
|
def test_container_exists_true
|
248
|
-
|
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)
|
249
133
|
assert_equal @connection.container_exists?('this_container_exists'), true
|
250
134
|
end
|
251
135
|
|
252
136
|
def test_container_exists_false
|
253
|
-
|
137
|
+
SwiftClient.stubs(:head_container).raises(ClientException.new("test_container_exists_false", :http_status => 404))
|
254
138
|
assert_equal @connection.container_exists?('this_does_not_exist'), false
|
255
139
|
end
|
256
140
|
|
257
141
|
def test_fetch_exisiting_container
|
258
|
-
|
259
|
-
|
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])
|
260
144
|
container = @connection.container('good_container')
|
261
145
|
assert_equal container.name, 'good_container'
|
262
146
|
end
|
263
147
|
|
264
148
|
def test_fetch_nonexistent_container
|
265
149
|
CloudFiles::Container.any_instance.stubs(:container_metadata).raises(CloudFiles::Exception::NoSuchContainer)
|
266
|
-
build_net_http_object
|
267
150
|
assert_raise(CloudFiles::Exception::NoSuchContainer) do
|
268
151
|
container = @connection.container('bad_container')
|
269
152
|
end
|
270
153
|
end
|
271
154
|
|
272
155
|
def test_containers
|
273
|
-
|
156
|
+
response = [nil, [{"name" => 'foo'}, {"name" => "bar"}, {"name" => "baz"}, {"name" => "boo"}]]
|
157
|
+
SwiftClient.stubs(:get_account).returns(response)
|
274
158
|
containers = @connection.containers
|
275
159
|
assert_equal containers.size, 4
|
276
160
|
assert_equal containers.first, 'foo'
|
277
161
|
end
|
278
162
|
|
279
163
|
def test_containers_with_limit
|
280
|
-
|
281
|
-
|
164
|
+
response = [nil, [{"name" => 'foo'}]]
|
165
|
+
SwiftClient.stubs(:get_account).returns(response)
|
282
166
|
containers = @connection.containers(1)
|
283
167
|
assert_equal containers.size, 1
|
284
168
|
assert_equal containers.first, 'foo'
|
285
169
|
end
|
286
|
-
|
170
|
+
|
287
171
|
def test_containers_with_marker
|
288
|
-
|
289
|
-
|
172
|
+
response = [nil, [{"name" => "boo"}]]
|
173
|
+
SwiftClient.stubs(:get_account).returns(response)
|
290
174
|
containers = @connection.containers(0, 'baz')
|
291
175
|
assert_equal containers.size, 1
|
292
176
|
assert_equal containers.first, 'boo'
|
293
177
|
end
|
294
|
-
|
178
|
+
|
295
179
|
def test_no_containers_yet
|
296
|
-
|
180
|
+
response = [nil, []]
|
181
|
+
SwiftClient.stubs(:get_account).returns(response)
|
297
182
|
containers = @connection.containers
|
298
183
|
assert_equal containers.size, 0
|
299
184
|
assert_equal containers.class, Array
|
300
185
|
end
|
301
186
|
|
302
187
|
def test_containers_bad_result
|
303
|
-
|
188
|
+
SwiftClient.stubs(:get_account).raises(ClientException.new("foo", :http_status => 999))
|
304
189
|
assert_raises(CloudFiles::Exception::InvalidResponse) do
|
305
190
|
containers = @connection.containers
|
306
191
|
end
|
307
192
|
end
|
308
193
|
|
309
194
|
def test_containers_detail
|
310
|
-
|
311
|
-
|
312
|
-
<container><name>Books</name><count>0</count><bytes>0</bytes></container><container><name>cftest</name><count>0</count><bytes>0</bytes></container><container><name>cszsa</name><count>1</count><bytes>82804</bytes></container><container><name>CWX</name><count>3</count><bytes>3645134</bytes></container><container><name>test</name><count>2</count><bytes>20</bytes></container><container><name>video</name><count>2</count><bytes>34141298</bytes></container><container><name>webpics</name><count>1</count><bytes>177496</bytes></container></account>}
|
313
|
-
build_net_http_object(:body => body, :code => '200')
|
195
|
+
response = [nil, [{"bytes"=>"42", "name"=>"CWX", "count"=>"3"}]]
|
196
|
+
SwiftClient.stubs(:get_account).returns(response)
|
314
197
|
details = @connection.containers_detail
|
315
198
|
assert_equal details['CWX'][:count], "3"
|
316
199
|
end
|
317
200
|
|
318
201
|
def test_empty_containers_detail
|
319
|
-
|
202
|
+
response = [nil, []]
|
203
|
+
SwiftClient.stubs(:get_account).returns(response)
|
320
204
|
details = @connection.containers_detail
|
321
205
|
assert_equal details, {}
|
322
206
|
end
|
323
207
|
|
324
208
|
def test_containers_detail_bad_response
|
325
|
-
|
209
|
+
SwiftClient.stubs(:get_account).raises(ClientException.new("foo", :http_status => 999))
|
326
210
|
assert_raises(CloudFiles::Exception::InvalidResponse) do
|
327
211
|
details = @connection.containers_detail
|
328
212
|
end
|
329
213
|
end
|
330
|
-
|
331
|
-
private
|
332
|
-
|
333
|
-
def build_net_http_object(args={}, cfreq_expectations={})
|
334
|
-
args.merge!(:code => '204') unless args[:code]
|
335
|
-
args[:response] = {} unless args[:response]
|
336
|
-
response = {'x-cdn-management-url' => 'http://cdn.example.com/path', 'x-storage-url' => 'http://cdn.example.com/storage', 'authtoken' => 'dummy_token'}.merge(args[:response])
|
337
|
-
response.stubs(:code).returns(args[:code])
|
338
|
-
response.stubs(:body).returns args[:body] || nil
|
339
|
-
|
340
|
-
if !cfreq_expectations.empty?
|
341
|
-
parameter_expectations = [anything(), anything(), anything(), anything(), anything(), anything(), anything(), anything()]
|
342
|
-
parameter_expectations[0] = cfreq_expectations[:method] if cfreq_expectations[:method]
|
343
|
-
parameter_expectations[2] = cfreq_expectations[:path] if cfreq_expectations[:path]
|
344
|
-
|
345
|
-
@connection.expects(:cfreq).with(*parameter_expectations).returns(response)
|
346
|
-
else
|
347
|
-
@connection.stubs(:cfreq).returns(response)
|
348
|
-
end
|
349
|
-
|
350
|
-
end
|
351
|
-
|
352
|
-
def build_net_http_object_with_cfreq_expectations(args={:code => '204' }, cfreq_expectations={})
|
353
|
-
build_net_http_object(args, cfreq_expectations)
|
354
|
-
end
|
355
214
|
end
|
@@ -4,11 +4,9 @@ require 'test_helper'
|
|
4
4
|
class CloudfilesContainerTest < Test::Unit::TestCase
|
5
5
|
|
6
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)
|
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
8
|
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
|
9
|
-
|
10
|
-
connection.stubs(:storage_request => response)
|
11
|
-
connection.stubs(:cdn_request => response)
|
9
|
+
SwiftClient.stubs(:head_container).returns(response)
|
12
10
|
@container = CloudFiles::Container.new(connection, 'test_container')
|
13
11
|
assert_equal @container.name, 'test_container'
|
14
12
|
assert_equal @container.class, CloudFiles::Container
|
@@ -18,10 +16,9 @@ class CloudfilesContainerTest < Test::Unit::TestCase
|
|
18
16
|
end
|
19
17
|
|
20
18
|
def test_object_creation_with_no_cdn_available
|
21
|
-
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)
|
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")
|
22
20
|
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
|
23
|
-
|
24
|
-
connection.stubs(:storage_request => response)
|
21
|
+
SwiftClient.stubs(:head_container).returns(response)
|
25
22
|
@container = CloudFiles::Container.new(connection, 'test_container')
|
26
23
|
assert_equal 'test_container', @container.name
|
27
24
|
assert_equal CloudFiles::Container, @container.class
|
@@ -29,21 +26,17 @@ class CloudfilesContainerTest < Test::Unit::TestCase
|
|
29
26
|
end
|
30
27
|
|
31
28
|
def test_object_creation_no_such_container
|
32
|
-
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? =>
|
33
|
-
|
34
|
-
response.stubs(:code).returns('999')
|
35
|
-
connection.stubs(:storage_request => response)
|
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))
|
36
31
|
assert_raise(CloudFiles::Exception::NoSuchContainer) do
|
37
32
|
@container = CloudFiles::Container.new(connection, 'test_container')
|
38
33
|
end
|
39
34
|
end
|
40
35
|
|
41
36
|
def test_object_creation_with_cdn
|
42
|
-
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)
|
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")
|
43
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'}
|
44
|
-
|
45
|
-
connection.stubs(:storage_request => response)
|
46
|
-
connection.stubs(:cdn_request => response)
|
39
|
+
SwiftClient.stubs(:head_container).returns(response)
|
47
40
|
@container = CloudFiles::Container.new(connection, 'test_container')
|
48
41
|
assert_equal @container.name, 'test_container'
|
49
42
|
assert_equal @container.cdn_enabled, true
|
@@ -53,183 +46,255 @@ class CloudfilesContainerTest < Test::Unit::TestCase
|
|
53
46
|
end
|
54
47
|
|
55
48
|
def test_to_s
|
56
|
-
|
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')
|
57
53
|
assert_equal @container.to_s, 'test_container'
|
58
54
|
end
|
59
55
|
|
60
56
|
def test_make_private_succeeds
|
61
|
-
|
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
62
|
assert_nothing_raised do
|
63
63
|
@container.make_private
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_make_private_fails
|
68
|
-
|
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')
|
69
73
|
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
70
74
|
@container.make_private
|
71
75
|
end
|
72
76
|
end
|
73
77
|
|
74
78
|
def test_make_public_succeeds
|
75
|
-
|
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')
|
76
85
|
assert_nothing_raised do
|
77
86
|
@container.make_public
|
78
87
|
end
|
79
88
|
end
|
80
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(123)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
81
102
|
def test_make_public_fails
|
82
|
-
|
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')
|
83
109
|
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
84
110
|
@container.make_public
|
85
111
|
end
|
86
112
|
end
|
87
113
|
|
88
114
|
def test_empty_is_false
|
89
|
-
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)
|
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")
|
90
116
|
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5'}
|
91
|
-
|
92
|
-
connection.stubs(:storage_request => response)
|
117
|
+
SwiftClient.stubs(:head_container).returns(response)
|
93
118
|
@container = CloudFiles::Container.new(connection, 'test_container')
|
94
119
|
assert_equal @container.empty?, false
|
95
120
|
end
|
96
121
|
|
97
122
|
def test_empty_is_true
|
98
|
-
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)
|
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")
|
99
124
|
response = {'x-container-bytes-used' => '0', 'x-container-object-count' => '0'}
|
100
|
-
|
101
|
-
connection.stubs(:storage_request => response)
|
125
|
+
SwiftClient.stubs(:head_container).returns(response)
|
102
126
|
@container = CloudFiles::Container.new(connection, 'test_container')
|
103
127
|
assert_equal @container.empty?, true
|
104
128
|
end
|
105
129
|
|
106
130
|
def build_acl_test_state(opts={})
|
107
|
-
@connection = stub(:storagehost => 'test.storage.example', :storagepath => '/dummy/path', :storageport => 443, :storagescheme => 'https', :cdn_available? => false)
|
108
|
-
|
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
|
+
|
109
133
|
@response = {
|
110
134
|
'x-container-bytes-used' => '0',
|
111
135
|
'x-container-object-count' => '0',
|
112
136
|
}.merge(opts.fetch(:response, {}))
|
113
137
|
|
114
138
|
@response.stubs(:code).returns(opts.fetch(:code, '204'))
|
115
|
-
|
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
|
116
144
|
@container = CloudFiles::Container.new(@connection, 'test_container')
|
117
145
|
end
|
118
146
|
|
119
147
|
def test_read_acl_is_set_from_headers
|
120
|
-
|
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')
|
121
152
|
assert_equal @response["x-container-read"], @container.read_acl
|
122
153
|
end
|
123
154
|
|
124
155
|
def test_set_read_acl_fails
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
@connection.stubs(:storage_request => response)
|
130
|
-
|
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')
|
131
160
|
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
132
161
|
@container.set_read_acl('.r:*')
|
133
162
|
end
|
134
163
|
end
|
135
164
|
|
136
165
|
def test_set_read_acl_succeeds
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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')
|
141
170
|
assert_equal @container.set_read_acl('.r:*'), true
|
142
171
|
end
|
143
172
|
|
144
173
|
def test_write_acl_is_set_from_headers
|
145
|
-
|
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')
|
146
178
|
assert_equal @response["x-container-write"], @container.write_acl
|
147
179
|
end
|
148
180
|
|
149
181
|
def test_set_write_acl_fails
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
@connection.stubs(:storage_request => response)
|
155
|
-
|
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')
|
156
186
|
assert_raises(CloudFiles::Exception::NoSuchContainer) do
|
157
187
|
@container.set_write_acl('.r:*')
|
158
188
|
end
|
159
189
|
end
|
160
190
|
|
161
191
|
def test_set_write_acl_succeeds
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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')
|
166
196
|
assert_equal @container.set_write_acl('.r:*'), true
|
167
197
|
end
|
168
198
|
|
169
199
|
def test_log_retention_is_true
|
170
|
-
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)
|
171
|
-
|
172
|
-
response.stubs(:code).returns('204')
|
173
|
-
connection.stubs(:cdn_request => response)
|
174
|
-
connection.stubs(:storage_request => response)
|
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'})
|
175
202
|
@container = CloudFiles::Container.new(connection, 'test_container')
|
176
203
|
assert_equal @container.log_retention?, true
|
177
204
|
end
|
178
205
|
|
179
206
|
def test_object_fetch
|
180
|
-
|
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")
|
181
211
|
object = @container.object('good_object')
|
182
212
|
assert_equal object.class, CloudFiles::StorageObject
|
183
213
|
end
|
184
214
|
|
185
215
|
def test_create_object
|
186
|
-
|
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")
|
187
219
|
object = @container.create_object('new_object')
|
188
220
|
assert_equal object.class, CloudFiles::StorageObject
|
189
221
|
end
|
190
222
|
|
191
223
|
def test_object_exists_true
|
192
|
-
|
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")
|
193
228
|
assert_equal @container.object_exists?('good_object'), true
|
194
229
|
end
|
195
230
|
|
196
231
|
def test_object_exists_false
|
197
|
-
|
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")
|
198
236
|
assert_equal @container.object_exists?('bad_object'), false
|
199
237
|
end
|
200
238
|
|
201
239
|
def test_delete_object_succeeds
|
202
|
-
|
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")
|
203
244
|
assert_nothing_raised do
|
204
245
|
@container.delete_object('good_object')
|
205
246
|
end
|
206
247
|
end
|
207
248
|
|
208
249
|
def test_delete_invalid_object_fails
|
209
|
-
|
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")
|
210
254
|
assert_raise(CloudFiles::Exception::NoSuchObject) do
|
211
255
|
@container.delete_object('nonexistent_object')
|
212
256
|
end
|
213
257
|
end
|
214
258
|
|
215
259
|
def test_delete_invalid_response_code_fails
|
216
|
-
|
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")
|
217
264
|
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
218
265
|
@container.delete_object('broken_object')
|
219
266
|
end
|
220
267
|
end
|
221
268
|
|
222
269
|
def test_fetch_objects
|
223
|
-
|
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
|
+
|
224
275
|
objects = @container.objects
|
225
276
|
assert_equal objects.class, Array
|
226
277
|
assert_equal objects.size, 3
|
227
278
|
assert_equal objects.first, 'foo'
|
228
279
|
end
|
229
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
|
+
|
230
292
|
def test_fetch_objects_with_limit
|
231
|
-
|
232
|
-
|
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
|
+
|
233
298
|
objects = @container.objects(:limit => 1)
|
234
299
|
assert_equal objects.class, Array
|
235
300
|
assert_equal objects.size, 1
|
@@ -237,8 +302,11 @@ class CloudfilesContainerTest < Test::Unit::TestCase
|
|
237
302
|
end
|
238
303
|
|
239
304
|
def test_fetch_objects_with_marker
|
240
|
-
|
241
|
-
|
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
|
+
|
242
310
|
objects = @container.objects(:marker => 'foo')
|
243
311
|
assert_equal objects.class, Array
|
244
312
|
assert_equal objects.size, 1
|
@@ -246,8 +314,11 @@ class CloudfilesContainerTest < Test::Unit::TestCase
|
|
246
314
|
end
|
247
315
|
|
248
316
|
def test_fetch_objects_with_deprecated_offset_param
|
249
|
-
|
250
|
-
|
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
|
+
|
251
322
|
objects = @container.objects(:offset => 'foo')
|
252
323
|
assert_equal objects.class, Array
|
253
324
|
assert_equal objects.size, 1
|
@@ -255,108 +326,169 @@ class CloudfilesContainerTest < Test::Unit::TestCase
|
|
255
326
|
end
|
256
327
|
|
257
328
|
def object_detail_body(skip_kisscam=false)
|
258
|
-
lines = [
|
259
|
-
|
260
|
-
|
261
|
-
lines << '<object><name>kisscam.mov</name><hash>96efd5a0d78b74cfe2a911c479b98ddd</hash><bytes>9196332</bytes><content_type>video/quicktime</content_type><last_modified>2008-12-18T10:34:43.867648</last_modified></object>
|
262
|
-
>'
|
263
|
-
end
|
264
|
-
lines << '<object><name>penaltybox.mov</name><hash>d2a4c0c24d8a7b4e935bee23080e0685</hash><bytes>24944966</bytes><content_type>video/quicktime</content_type><last_modified>2008-12-18T10:35:19.273927</last_modified></object>'
|
265
|
-
lines << '</container>'
|
266
|
-
|
267
|
-
lines.join("\n\n")
|
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'}
|
268
332
|
end
|
269
333
|
|
270
334
|
def test_fetch_objects_detail
|
271
|
-
|
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
|
+
|
272
340
|
details = @container.objects_detail
|
273
341
|
assert_equal details.size, 2
|
274
342
|
assert_equal details['kisscam.mov'][:bytes], '9196332'
|
275
343
|
end
|
276
344
|
|
277
345
|
def test_fetch_objects_details_with_limit
|
278
|
-
|
279
|
-
|
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
|
+
|
280
351
|
details = @container.objects_detail(:limit => 2)
|
281
352
|
assert_equal details.size, 2
|
282
353
|
assert_equal details['kisscam.mov'][:bytes], '9196332'
|
283
354
|
end
|
284
355
|
|
285
356
|
def test_fetch_objects_detail_with_marker
|
286
|
-
|
287
|
-
|
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
|
+
|
288
362
|
details = @container.objects_detail(:marker => 'kisscam.mov')
|
289
363
|
assert_equal details.size, 1
|
290
364
|
assert_equal details['penaltybox.mov'][:bytes], '24944966'
|
291
365
|
end
|
292
366
|
|
293
367
|
def test_fetch_objects_detail_with_deprecated_offset_param
|
294
|
-
|
295
|
-
|
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
|
+
|
296
373
|
details = @container.objects_detail(:offset => 'kisscam.mov')
|
297
374
|
assert_equal details.size, 1
|
298
375
|
assert_equal details['penaltybox.mov'][:bytes], '24944966'
|
299
376
|
end
|
300
377
|
|
301
|
-
|
378
|
+
|
302
379
|
def test_fetch_object_detail_empty
|
303
|
-
|
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
|
+
|
304
385
|
details = @container.objects_detail
|
305
386
|
assert_equal details, {}
|
306
387
|
end
|
307
388
|
|
308
389
|
def test_fetch_object_detail_error
|
309
|
-
|
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
|
+
|
310
395
|
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
311
396
|
details = @container.objects_detail
|
312
397
|
end
|
313
398
|
end
|
314
399
|
|
315
400
|
def test_setting_log_retention
|
316
|
-
|
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
|
+
|
317
406
|
assert(@container.log_retention='false')
|
318
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
|
319
419
|
|
320
420
|
def test_purge_from_cdn_succeeds
|
321
|
-
|
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
|
+
|
322
426
|
assert_nothing_raised do
|
323
427
|
@container.purge_from_cdn
|
324
428
|
@container.purge_from_cdn("small.fox@hole.org")
|
325
429
|
end
|
326
430
|
end
|
327
431
|
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
CloudFiles::Container.
|
333
|
-
CloudFiles::Container.any_instance.stubs(:metadata).returns()
|
334
|
-
CloudFiles::Container.any_instance.stubs(:container_metadata).returns({:bytes => 99, :count => 2})
|
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)
|
336
|
-
args[:response] = {} unless args[:response]
|
337
|
-
response = {'x-cdn-management-url' => 'http://cdn.example.com/path', 'x-storage-url' => 'http://cdn.example.com/storage', 'authtoken' => 'dummy_token', 'last-modified' => Time.now.to_s}.merge(args[:response])
|
338
|
-
response.stubs(:code).returns(args[:code])
|
339
|
-
response.stubs(:body).returns args[:body] || nil
|
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")
|
340
437
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
parameter_expectations = [anything(), anything(), anything(), anything(), anything(), anything()]
|
345
|
-
parameter_expectations[0] = cfreq_expectations[:method] if cfreq_expectations[:method]
|
346
|
-
parameter_expectations[1] = cfreq_expectations[:path] if cfreq_expectations[:path]
|
347
|
-
|
348
|
-
connection.expects(:cdn_request).with(*parameter_expectations).returns(response) if args[:cdn_request]
|
349
|
-
connection.expects(:storage_request).with(*parameter_expectations).returns(response)
|
350
|
-
else
|
351
|
-
connection.stubs(:cdn_request => response) if args[:cdn_request]
|
352
|
-
connection.stubs(:storage_request => response)
|
438
|
+
assert_raise(CloudFiles::Exception::Connection) do
|
439
|
+
@container.purge_from_cdn
|
353
440
|
end
|
354
|
-
|
355
|
-
@container = CloudFiles::Container.new(connection, 'test_container')
|
356
|
-
@container.stubs(:connection).returns(connection)
|
357
441
|
end
|
358
442
|
|
359
|
-
def
|
360
|
-
|
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'}
|
361
493
|
end
|
362
494
|
end
|