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,211 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CloudfilesStorageObjectTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_object_creation
|
7
|
+
build_swift_client_object
|
8
|
+
assert_equal @object.name, 'test_object'
|
9
|
+
assert_equal @object.class, CloudFiles::StorageObject
|
10
|
+
assert_equal @object.to_s, 'test_object'
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_object_creation_with_no_cdn_available
|
14
|
+
build_swift_client_object(:connection=>{:cdn_available? => false})
|
15
|
+
assert_equal @object.name, 'test_object'
|
16
|
+
assert_equal @object.class, CloudFiles::StorageObject
|
17
|
+
assert_equal @object.to_s, 'test_object'
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_public_url_exists
|
21
|
+
build_swift_client_object(:name => 'test object', :public => true)
|
22
|
+
assert_equal @object.public_url, "http://cdn.test.example/test%20object"
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_public_url_does_not_exist
|
26
|
+
build_swift_client_object(:connection => {:cdn_available? => false})
|
27
|
+
assert_equal @object.public_url, nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_data_succeeds
|
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
|
33
|
+
assert_equal @object.data, 'This is good data'
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_data_with_offset_succeeds
|
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
|
39
|
+
assert_equal @object.data(3), 'Thi'
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_data_fails
|
43
|
+
SwiftClient.stubs(:get_object).raises(ClientException.new("test_data_fails", :http_status => 999))
|
44
|
+
build_swift_client_object
|
45
|
+
assert_raise(CloudFiles::Exception::NoSuchObject) do
|
46
|
+
@object.data
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_data_stream_succeeds
|
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
|
53
|
+
data = ""
|
54
|
+
assert_nothing_raised do
|
55
|
+
@object.data_stream { |chunk|
|
56
|
+
data += chunk
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_data_stream_with_offset_succeeds
|
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
|
64
|
+
data = ""
|
65
|
+
assert_nothing_raised do
|
66
|
+
@object.data_stream(5) { |chunk|
|
67
|
+
data += chunk
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Need to find a way to simulate this properly
|
73
|
+
def data_stream_fails
|
74
|
+
SwiftClient.stubs(:get_object).raises(ClientException.new("test_data_stream_fails", :http_status => 404))
|
75
|
+
build_swift_client_object
|
76
|
+
data = ""
|
77
|
+
assert_raise(CloudFiles::Exception::NoSuchObject) do
|
78
|
+
@object.data_stream { |chunk|
|
79
|
+
data += chunk
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_set_metadata_succeeds
|
85
|
+
SwiftClient.stubs(:post_object).returns(nil)
|
86
|
+
build_swift_client_object
|
87
|
+
assert_nothing_raised do
|
88
|
+
@object.set_metadata({'Foo' =>'bar'})
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_set_metadata_invalid_object
|
93
|
+
SwiftClient.stubs(:post_object).raises(ClientException.new("test_set_metadata_invalid_object", :http_status => 404))
|
94
|
+
build_swift_client_object
|
95
|
+
assert_raise(CloudFiles::Exception::NoSuchObject) do
|
96
|
+
@object.set_metadata({'Foo' =>'bar'})
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_set_metadata_fails
|
101
|
+
SwiftClient.stubs(:post_object).raises(ClientException.new("test_set_metadata_fails", :http_status => 999))
|
102
|
+
build_swift_client_object
|
103
|
+
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
104
|
+
@object.set_metadata({'Foo' =>'bar'})
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_read_metadata_succeeds
|
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}
|
110
|
+
build_swift_client_object
|
111
|
+
SwiftClient.stubs(:head_object).returns(response)
|
112
|
+
assert_equal @object.metadata, {'foo' => 'Bar', 'spam' => 'peanutbutter'}
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_write_succeeds
|
116
|
+
build_swift_client_object
|
117
|
+
SwiftClient.stubs(:put_object).returns("foobarbazquu")
|
118
|
+
assert_nothing_raised do
|
119
|
+
@object.write("This is test data")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_write_with_make_path
|
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])
|
127
|
+
assert_nothing_raised do
|
128
|
+
@object.write("This is path test data")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_load_from_filename_succeeds
|
133
|
+
require 'tempfile'
|
134
|
+
out = Tempfile.new('test')
|
135
|
+
out.write("This is test data")
|
136
|
+
out.close
|
137
|
+
SwiftClient.stubs(:put_object).returns("foobarbazquu")
|
138
|
+
build_swift_client_object
|
139
|
+
assert_nothing_raised do
|
140
|
+
@object.load_from_filename(out.path)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_write_sets_mime_type
|
145
|
+
SwiftClient.stubs(:put_object).returns('foobarbazquu')
|
146
|
+
build_swift_client_object(:name => 'myfile.xml')
|
147
|
+
assert_nothing_raised do
|
148
|
+
@object.write("This is test data")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_purge_from_cdn_succeeds
|
153
|
+
SwiftClient.stubs(:delete_object).returns(true)
|
154
|
+
build_swift_client_object(:connection => {:cdn_available? => true})
|
155
|
+
assert_nothing_raised do
|
156
|
+
@object.purge_from_cdn
|
157
|
+
@object.purge_from_cdn("small.fox@hole.org")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_write_with_no_data_dies
|
162
|
+
build_swift_client_object
|
163
|
+
$stdin.stubs(:tty?).returns(true)
|
164
|
+
assert_raise(CloudFiles::Exception::Syntax) do
|
165
|
+
@object.write(nil)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_write_with_invalid_content_length_dies
|
170
|
+
SwiftClient.stubs(:put_object).raises(ClientException.new("test_write_with_invalid_content_length_dies", :http_status => '412'))
|
171
|
+
build_swift_client_object
|
172
|
+
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
173
|
+
@object.write('Test Data')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_write_with_mismatched_md5_dies
|
178
|
+
SwiftClient.stubs(:put_object).raises(ClientException.new("test_write_with_mismatched_md5_dies", :http_status => '422'))
|
179
|
+
build_swift_client_object
|
180
|
+
assert_raise(CloudFiles::Exception::MisMatchedChecksum) do
|
181
|
+
@object.write('Test Data')
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_write_with_invalid_response_dies
|
186
|
+
SwiftClient.stubs(:put_object).raises(ClientException.new("test_write_with_invalid_response_dies", :http_status => '999'))
|
187
|
+
build_swift_client_object
|
188
|
+
assert_raise(CloudFiles::Exception::InvalidResponse) do
|
189
|
+
@object.write('Test Data')
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
private
|
194
|
+
|
195
|
+
def build_swift_client_object(args = {})
|
196
|
+
CloudFiles::Container.any_instance.stubs(:metadata).returns({})
|
197
|
+
CloudFiles::Container.any_instance.stubs(:populate).returns(true)
|
198
|
+
CloudFiles::Container.any_instance.stubs(:container_metadata).returns({:bytes => 99, :count => 2})
|
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]))
|
201
|
+
args[:response] = {} unless args[:response]
|
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])
|
203
|
+
container = CloudFiles::Container.new(connection, 'test_container')
|
204
|
+
container.stubs(:connection).returns(connection)
|
205
|
+
container.stubs(:public?).returns(args[:public] || false)
|
206
|
+
container.stubs(:cdn_url).returns('http://cdn.test.example')
|
207
|
+
args[:obj] = [] unless args[:obj]
|
208
|
+
@object = CloudFiles::StorageObject.new(container, args[:name] || 'test_object', *args[:obj] )
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudfiles-sagamore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- H. Wade Minter
|
9
|
+
- Rackspace Hosting
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-01-10 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: mocha
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 0.9.8
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.9.8
|
47
|
+
description: A Ruby version of the Rackspace Cloud Files API.
|
48
|
+
email: minter@lunenburg.org
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.rdoc
|
53
|
+
- TODO
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- CHANGELOG
|
57
|
+
- CONTRIBUTORS
|
58
|
+
- COPYING
|
59
|
+
- Gemfile
|
60
|
+
- README.rdoc
|
61
|
+
- Rakefile
|
62
|
+
- TODO
|
63
|
+
- cloudfiles.gemspec
|
64
|
+
- lib/cloudfiles.rb
|
65
|
+
- lib/client.rb
|
66
|
+
- lib/cloudfiles/authentication.rb
|
67
|
+
- lib/cloudfiles/connection.rb
|
68
|
+
- lib/cloudfiles/container.rb
|
69
|
+
- lib/cloudfiles/exception.rb
|
70
|
+
- lib/cloudfiles/storage_object.rb
|
71
|
+
- lib/cloudfiles/version.rb
|
72
|
+
- test/cf-testunit.rb
|
73
|
+
- test/cloudfiles_authentication_test.rb
|
74
|
+
- test/cloudfiles_connection_test.rb
|
75
|
+
- test/cloudfiles_container_test.rb
|
76
|
+
- test/cloudfiles_storage_object_test.rb
|
77
|
+
- test/cloudfiles_client_test.rb
|
78
|
+
- test/test_helper.rb
|
79
|
+
homepage: http://www.rackspacecloud.com/cloud_hosting_products/files
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --charset=UTF-8
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.24
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: A Ruby API into Rackspace Cloud Files
|
104
|
+
test_files:
|
105
|
+
- test/cf-testunit.rb
|
106
|
+
- test/cloudfiles_authentication_test.rb
|
107
|
+
- test/cloudfiles_connection_test.rb
|
108
|
+
- test/cloudfiles_container_test.rb
|
109
|
+
- test/cloudfiles_storage_object_test.rb
|
110
|
+
- test/cloudfiles_client_test.rb
|
111
|
+
- test/test_helper.rb
|
112
|
+
has_rdoc:
|