cloudfiles 1.4.18 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -2,60 +2,54 @@ $:.unshift File.dirname(__FILE__)
|
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
class CloudfilesStorageObjectTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
def test_object_creation
|
7
|
-
|
8
|
-
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'last-modified' => Time.now.to_s}
|
9
|
-
response.stubs(:code).returns('204')
|
10
|
-
connection.stubs(:storage_request => response)
|
11
|
-
container = CloudFiles::Container.new(connection, 'test_container')
|
12
|
-
@object = CloudFiles::StorageObject.new(container, 'test_object')
|
7
|
+
build_swift_client_object
|
13
8
|
assert_equal @object.name, 'test_object'
|
14
9
|
assert_equal @object.class, CloudFiles::StorageObject
|
15
10
|
assert_equal @object.to_s, 'test_object'
|
16
11
|
end
|
17
12
|
|
18
13
|
def test_object_creation_with_no_cdn_available
|
19
|
-
|
20
|
-
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'last-modified' => Time.now.to_s}
|
21
|
-
response.stubs(:code).returns('204')
|
22
|
-
connection.stubs(:storage_request => response)
|
23
|
-
container = CloudFiles::Container.new(connection, 'test_container')
|
24
|
-
@object = CloudFiles::StorageObject.new(container, 'test_object')
|
14
|
+
build_swift_client_object(:connection=>{:cdn_available? => false})
|
25
15
|
assert_equal @object.name, 'test_object'
|
26
16
|
assert_equal @object.class, CloudFiles::StorageObject
|
27
17
|
assert_equal @object.to_s, 'test_object'
|
28
18
|
end
|
29
19
|
|
30
20
|
def test_public_url_exists
|
31
|
-
|
21
|
+
build_swift_client_object(:name => 'test object', :public => true)
|
32
22
|
assert_equal @object.public_url, "http://cdn.test.example/test%20object"
|
33
23
|
end
|
34
24
|
|
35
25
|
def test_public_url_does_not_exist
|
36
|
-
|
26
|
+
build_swift_client_object(:connection => {:cdn_available? => false})
|
37
27
|
assert_equal @object.public_url, nil
|
38
28
|
end
|
39
29
|
|
40
30
|
def test_data_succeeds
|
41
|
-
|
31
|
+
SwiftClient.stubs(:get_object).returns([{"etag"=>"foo", "last-modified"=>"Tue, 21 Jun 2011 19:54:36 GMT", "content-type"=>"text/html", "date"=>"Thu, 15 Sep 2011 22:12:19 GMT", "content-length"=>"17", "accept-ranges"=>"bytes", "x-trans-id"=>"foo"}, "This is good data"])
|
32
|
+
build_swift_client_object
|
42
33
|
assert_equal @object.data, 'This is good data'
|
43
34
|
end
|
44
35
|
|
45
36
|
def test_data_with_offset_succeeds
|
46
|
-
|
37
|
+
SwiftClient.stubs(:get_object).returns([{"etag"=>"foo", "last-modified"=>"Tue, 21 Jun 2011 19:54:36 GMT", "content-type"=>"text/html", "date"=>"Thu, 15 Sep 2011 22:12:19 GMT", "content-length"=>"17", "accept-ranges"=>"bytes", "x-trans-id"=>"foo"}, "Thi"])
|
38
|
+
build_swift_client_object
|
47
39
|
assert_equal @object.data(3), 'Thi'
|
48
40
|
end
|
49
41
|
|
50
42
|
def test_data_fails
|
51
|
-
|
43
|
+
SwiftClient.stubs(:get_object).raises(ClientException.new("test_data_fails", :http_status => 999))
|
44
|
+
build_swift_client_object
|
52
45
|
assert_raise(CloudFiles::Exception::NoSuchObject) do
|
53
46
|
@object.data
|
54
47
|
end
|
55
48
|
end
|
56
49
|
|
57
50
|
def test_data_stream_succeeds
|
58
|
-
|
51
|
+
SwiftClient.stubs(:get_object).returns([{"etag"=>"foo", "last-modified"=>"Tue, 21 Jun 2011 19:54:36 GMT", "content-type"=>"text/html", "date"=>"Thu, 15 Sep 2011 22:12:19 GMT", "content-length"=>"17", "accept-ranges"=>"bytes", "x-trans-id"=>"foo"}, "This is good data"])
|
52
|
+
build_swift_client_object
|
59
53
|
data = ""
|
60
54
|
assert_nothing_raised do
|
61
55
|
@object.data_stream { |chunk|
|
@@ -65,7 +59,8 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
|
|
65
59
|
end
|
66
60
|
|
67
61
|
def test_data_stream_with_offset_succeeds
|
68
|
-
|
62
|
+
SwiftClient.stubs(:get_object).returns([{"etag"=>"foo", "last-modified"=>"Tue, 21 Jun 2011 19:54:36 GMT", "content-type"=>"text/html", "date"=>"Thu, 15 Sep 2011 22:12:19 GMT", "content-length"=>"5", "accept-ranges"=>"bytes", "x-trans-id"=>"foo"}, "This "])
|
63
|
+
build_swift_client_object
|
69
64
|
data = ""
|
70
65
|
assert_nothing_raised do
|
71
66
|
@object.data_stream(5) { |chunk|
|
@@ -76,7 +71,8 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
|
|
76
71
|
|
77
72
|
# Need to find a way to simulate this properly
|
78
73
|
def data_stream_fails
|
79
|
-
|
74
|
+
SwiftClient.stubs(:get_object).raises(ClientException.new("test_data_stream_fails", :http_status => 404))
|
75
|
+
build_swift_client_object
|
80
76
|
data = ""
|
81
77
|
assert_raise(CloudFiles::Exception::NoSuchObject) do
|
82
78
|
@object.data_stream { |chunk|
|
@@ -86,54 +82,48 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
|
|
86
82
|
end
|
87
83
|
|
88
84
|
def test_set_metadata_succeeds
|
89
|
-
|
90
|
-
|
85
|
+
SwiftClient.stubs(:post_object).returns(nil)
|
86
|
+
build_swift_client_object
|
91
87
|
assert_nothing_raised do
|
92
88
|
@object.set_metadata({'Foo' =>'bar'})
|
93
89
|
end
|
94
90
|
end
|
95
91
|
|
96
92
|
def test_set_metadata_invalid_object
|
97
|
-
|
93
|
+
SwiftClient.stubs(:post_object).raises(ClientException.new("test_set_metadata_invalid_object", :http_status => 404))
|
94
|
+
build_swift_client_object
|
98
95
|
assert_raise(CloudFiles::Exception::NoSuchObject) do
|
99
96
|
@object.set_metadata({'Foo' =>'bar'})
|
100
97
|
end
|
101
98
|
end
|
102
99
|
|
103
100
|
def test_set_metadata_fails
|
104
|
-
|
101
|
+
SwiftClient.stubs(:post_object).raises(ClientException.new("test_set_metadata_fails", :http_status => 999))
|
102
|
+
build_swift_client_object
|
105
103
|
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
106
104
|
@object.set_metadata({'Foo' =>'bar'})
|
107
105
|
end
|
108
106
|
end
|
109
107
|
|
110
108
|
def test_read_metadata_succeeds
|
111
|
-
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)
|
112
109
|
response = {'x-container-bytes-used' => '42', 'x-container-object-count' => '5', 'x-object-meta-foo' => 'Bar', 'x-object-meta-spam' => ['peanut', 'butter'], 'last-modified' => Time.now.to_s}
|
113
|
-
|
114
|
-
|
115
|
-
container = CloudFiles::Container.new(connection, 'test_container')
|
116
|
-
@object = CloudFiles::StorageObject.new(container, 'test_object')
|
110
|
+
build_swift_client_object
|
111
|
+
SwiftClient.stubs(:head_object).returns(response)
|
117
112
|
assert_equal @object.metadata, {'foo' => 'Bar', 'spam' => 'peanutbutter'}
|
118
113
|
end
|
119
114
|
|
120
115
|
def test_write_succeeds
|
121
|
-
|
122
|
-
|
123
|
-
build_net_http_object(:code => '201')
|
116
|
+
build_swift_client_object
|
117
|
+
SwiftClient.stubs(:put_object).returns("foobarbazquu")
|
124
118
|
assert_nothing_raised do
|
125
119
|
@object.write("This is test data")
|
126
120
|
end
|
127
121
|
end
|
128
122
|
|
129
123
|
def test_write_with_make_path
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
connection.stubs(:storage_request => response)
|
134
|
-
CloudFiles::Container.any_instance.stubs(:populate).returns(true)
|
135
|
-
container = CloudFiles::Container.new(connection, 'test_container')
|
136
|
-
@object = CloudFiles::StorageObject.new(container, 'path/to/my/test_object', false, true)
|
124
|
+
SwiftClient.stubs(:put_object).returns("foobarbazquu")
|
125
|
+
SwiftClient.stubs(:head_object).returns({"etag"=>"foo", "last-modified"=>"Tue, 21 Jun 2011 19:54:36 GMT", "content-type"=>"text/html", "date"=>"Thu, 15 Sep 2011 22:12:19 GMT", "content-length"=>"17", "accept-ranges"=>"bytes", "x-trans-id"=>"foo"})
|
126
|
+
build_swift_client_object(:name => "path/to/my/test_object", :obj => [false, true])
|
137
127
|
assert_nothing_raised do
|
138
128
|
@object.write("This is path test data")
|
139
129
|
end
|
@@ -144,25 +134,24 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
|
|
144
134
|
out = Tempfile.new('test')
|
145
135
|
out.write("This is test data")
|
146
136
|
out.close
|
147
|
-
|
148
|
-
|
149
|
-
build_net_http_object(:code => '201')
|
137
|
+
SwiftClient.stubs(:put_object).returns("foobarbazquu")
|
138
|
+
build_swift_client_object
|
150
139
|
assert_nothing_raised do
|
151
140
|
@object.load_from_filename(out.path)
|
152
141
|
end
|
153
142
|
end
|
154
143
|
|
155
144
|
def test_write_sets_mime_type
|
156
|
-
|
157
|
-
|
158
|
-
build_net_http_object(:name => 'myfile.xml', :code => '201')
|
145
|
+
SwiftClient.stubs(:put_object).returns('foobarbazquu')
|
146
|
+
build_swift_client_object(:name => 'myfile.xml')
|
159
147
|
assert_nothing_raised do
|
160
148
|
@object.write("This is test data")
|
161
149
|
end
|
162
150
|
end
|
163
151
|
|
164
152
|
def test_purge_from_cdn_succeeds
|
165
|
-
|
153
|
+
SwiftClient.stubs(:delete_object).returns(true)
|
154
|
+
build_swift_client_object(:connection => {:cdn_available? => true})
|
166
155
|
assert_nothing_raised do
|
167
156
|
@object.purge_from_cdn
|
168
157
|
@object.purge_from_cdn("small.fox@hole.org")
|
@@ -170,56 +159,53 @@ class CloudfilesStorageObjectTest < Test::Unit::TestCase
|
|
170
159
|
end
|
171
160
|
|
172
161
|
def test_write_with_no_data_dies
|
173
|
-
|
162
|
+
build_swift_client_object
|
163
|
+
$stdin.stubs(:tty?).returns(true)
|
174
164
|
assert_raise(CloudFiles::Exception::Syntax) do
|
175
|
-
@object.write
|
165
|
+
@object.write(nil)
|
176
166
|
end
|
177
167
|
end
|
178
168
|
|
179
169
|
def test_write_with_invalid_content_length_dies
|
180
|
-
|
170
|
+
SwiftClient.stubs(:put_object).raises(ClientException.new("test_write_with_invalid_content_length_dies", :http_status => '412'))
|
171
|
+
build_swift_client_object
|
181
172
|
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
182
173
|
@object.write('Test Data')
|
183
174
|
end
|
184
175
|
end
|
185
176
|
|
186
177
|
def test_write_with_mismatched_md5_dies
|
187
|
-
|
178
|
+
SwiftClient.stubs(:put_object).raises(ClientException.new("test_write_with_mismatched_md5_dies", :http_status => '422'))
|
179
|
+
build_swift_client_object
|
188
180
|
assert_raise(CloudFiles::Exception::MisMatchedChecksum) do
|
189
181
|
@object.write('Test Data')
|
190
182
|
end
|
191
183
|
end
|
192
184
|
|
193
185
|
def test_write_with_invalid_response_dies
|
194
|
-
|
186
|
+
SwiftClient.stubs(:put_object).raises(ClientException.new("test_write_with_invalid_response_dies", :http_status => '999'))
|
187
|
+
build_swift_client_object
|
195
188
|
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
196
189
|
@object.write('Test Data')
|
197
190
|
end
|
198
191
|
end
|
199
192
|
|
200
193
|
private
|
201
|
-
|
202
|
-
def
|
203
|
-
args.merge!(:code => '204' ) unless args[:code]
|
194
|
+
|
195
|
+
def build_swift_client_object(args = {})
|
204
196
|
CloudFiles::Container.any_instance.stubs(:metadata).returns({})
|
205
197
|
CloudFiles::Container.any_instance.stubs(:populate).returns(true)
|
206
198
|
CloudFiles::Container.any_instance.stubs(:container_metadata).returns({:bytes => 99, :count => 2})
|
207
|
-
connection =
|
199
|
+
args[:connection] = {} unless args[:connection]
|
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"}.merge!(args[:connection]))
|
208
201
|
args[:response] = {} unless args[:response]
|
209
202
|
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])
|
210
|
-
response.stubs(:code).returns(args[:code])
|
211
|
-
response.stubs(:body).returns args[:body] || nil
|
212
|
-
|
213
|
-
connection.stubs(:cdn_request => response) if args[:cdn_request]
|
214
|
-
|
215
|
-
connection.stubs(:storage_request => response)
|
216
|
-
|
217
203
|
container = CloudFiles::Container.new(connection, 'test_container')
|
218
204
|
container.stubs(:connection).returns(connection)
|
219
205
|
container.stubs(:public?).returns(args[:public] || false)
|
220
206
|
container.stubs(:cdn_url).returns('http://cdn.test.example')
|
221
|
-
|
207
|
+
args[:obj] = [] unless args[:obj]
|
208
|
+
@object = CloudFiles::StorageObject.new(container, args[:name] || 'test_object', *args[:obj] )
|
222
209
|
end
|
223
210
|
|
224
|
-
|
225
211
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudfiles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 1.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- H. Wade Minter
|
@@ -16,22 +16,21 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-11-21 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
|
-
name:
|
23
|
+
name: json
|
24
24
|
prerelease: false
|
25
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 3
|
31
31
|
segments:
|
32
|
-
-
|
33
|
-
|
34
|
-
version: "1.16"
|
32
|
+
- 0
|
33
|
+
version: "0"
|
35
34
|
type: :runtime
|
36
35
|
version_requirements: *id001
|
37
36
|
- !ruby/object:Gem::Dependency
|
@@ -70,6 +69,7 @@ files:
|
|
70
69
|
- TODO
|
71
70
|
- cloudfiles.gemspec
|
72
71
|
- lib/cloudfiles.rb
|
72
|
+
- lib/client.rb
|
73
73
|
- lib/cloudfiles/authentication.rb
|
74
74
|
- lib/cloudfiles/connection.rb
|
75
75
|
- lib/cloudfiles/container.rb
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- test/cloudfiles_connection_test.rb
|
82
82
|
- test/cloudfiles_container_test.rb
|
83
83
|
- test/cloudfiles_storage_object_test.rb
|
84
|
+
- test/cloudfiles_client_test.rb
|
84
85
|
- test/test_helper.rb
|
85
86
|
has_rdoc: true
|
86
87
|
homepage: http://www.rackspacecloud.com/cloud_hosting_products/files
|
@@ -122,4 +123,5 @@ test_files:
|
|
122
123
|
- test/cloudfiles_connection_test.rb
|
123
124
|
- test/cloudfiles_container_test.rb
|
124
125
|
- test/cloudfiles_storage_object_test.rb
|
126
|
+
- test/cloudfiles_client_test.rb
|
125
127
|
- test/test_helper.rb
|