sml-aws-s3 0.5.1.1225474505
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/COPYING +19 -0
- data/INSTALL +55 -0
- data/README +545 -0
- data/Rakefile +334 -0
- data/bin/s3sh +6 -0
- data/bin/setup.rb +10 -0
- data/lib/aws/s3/acl.rb +636 -0
- data/lib/aws/s3/authentication.rb +221 -0
- data/lib/aws/s3/base.rb +236 -0
- data/lib/aws/s3/bittorrent.rb +58 -0
- data/lib/aws/s3/bucket.rb +319 -0
- data/lib/aws/s3/connection.rb +323 -0
- data/lib/aws/s3/error.rb +69 -0
- data/lib/aws/s3/exceptions.rb +133 -0
- data/lib/aws/s3/extensions.rb +324 -0
- data/lib/aws/s3/logging.rb +311 -0
- data/lib/aws/s3/object.rb +628 -0
- data/lib/aws/s3/owner.rb +44 -0
- data/lib/aws/s3/parsing.rb +99 -0
- data/lib/aws/s3/response.rb +180 -0
- data/lib/aws/s3/service.rb +51 -0
- data/lib/aws/s3/version.rb +12 -0
- data/lib/aws/s3.rb +61 -0
- data/test/acl_test.rb +254 -0
- data/test/authentication_test.rb +114 -0
- data/test/base_test.rb +136 -0
- data/test/bucket_test.rb +74 -0
- data/test/connection_test.rb +216 -0
- data/test/error_test.rb +70 -0
- data/test/extensions_test.rb +331 -0
- data/test/fixtures.rb +89 -0
- data/test/logging_test.rb +89 -0
- data/test/object_test.rb +205 -0
- data/test/parsing_test.rb +66 -0
- data/test/response_test.rb +68 -0
- data/test/service_test.rb +23 -0
- data/test/test_helper.rb +107 -0
- metadata +121 -0
@@ -0,0 +1,331 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class HashExtensionsTest < Test::Unit::TestCase
|
4
|
+
def test_to_query_string
|
5
|
+
# Because hashes aren't ordered, I'm mostly testing against hashes with just one key
|
6
|
+
symbol_keys = {:one => 1}
|
7
|
+
string_keys = {'one' => 1}
|
8
|
+
expected = '?one=1'
|
9
|
+
[symbol_keys, string_keys].each do |hash|
|
10
|
+
assert_equal expected, hash.to_query_string
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_empty_hash_returns_no_query_string
|
15
|
+
assert_equal '', {}.to_query_string
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_include_question_mark
|
19
|
+
hash = {:one => 1}
|
20
|
+
assert_equal '?one=1', hash.to_query_string
|
21
|
+
assert_equal 'one=1', hash.to_query_string(false)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_elements_joined_by_ampersand
|
25
|
+
hash = {:one => 1, :two => 2}
|
26
|
+
qs = hash.to_query_string
|
27
|
+
assert qs['one=1&two=2'] || qs['two=2&one=1']
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_normalized_options
|
31
|
+
expectations = [
|
32
|
+
[{:foo_bar => 1}, {'foo-bar' => '1'}],
|
33
|
+
[{'foo_bar' => 1}, {'foo-bar' => '1'}],
|
34
|
+
[{'foo-bar' => 1}, {'foo-bar' => '1'}],
|
35
|
+
[{}, {}]
|
36
|
+
]
|
37
|
+
|
38
|
+
expectations.each do |(before, after)|
|
39
|
+
assert_equal after, before.to_normalized_options
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class StringExtensionsTest < Test::Unit::TestCase
|
45
|
+
def test_previous
|
46
|
+
expectations = {'abc' => 'abb', '123' => '122', '1' => '0'}
|
47
|
+
expectations.each do |before, after|
|
48
|
+
assert_equal after, before.previous
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_to_header
|
53
|
+
transformations = {
|
54
|
+
'foo' => 'foo',
|
55
|
+
:foo => 'foo',
|
56
|
+
'foo-bar' => 'foo-bar',
|
57
|
+
'foo_bar' => 'foo-bar',
|
58
|
+
:foo_bar => 'foo-bar',
|
59
|
+
'Foo-Bar' => 'foo-bar',
|
60
|
+
'Foo_Bar' => 'foo-bar'
|
61
|
+
}
|
62
|
+
|
63
|
+
transformations.each do |before, after|
|
64
|
+
assert_equal after, before.to_header
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_utf8?
|
69
|
+
assert !"318597/620065/GTL_75\24300_A600_A610.zip".utf8?
|
70
|
+
assert "318597/620065/GTL_75£00_A600_A610.zip".utf8?
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_remove_extended
|
74
|
+
assert "318597/620065/GTL_75\24300_A600_A610.zip".remove_extended.utf8?
|
75
|
+
assert "318597/620065/GTL_75£00_A600_A610.zip".remove_extended.utf8?
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class CoercibleStringTest < Test::Unit::TestCase
|
80
|
+
|
81
|
+
def test_coerce
|
82
|
+
coercions = [
|
83
|
+
['1', 1],
|
84
|
+
['false', false],
|
85
|
+
['true', true],
|
86
|
+
['2006-10-29T23:14:47.000Z', Time.parse('2006-10-29T23:14:47.000Z')],
|
87
|
+
['Hello!', 'Hello!'],
|
88
|
+
['false23', 'false23'],
|
89
|
+
['03 1-2-3-Apple-Tree.mp3', '03 1-2-3-Apple-Tree.mp3'],
|
90
|
+
['0815', '0815'] # This number isn't coerced because the leading zero would be lost
|
91
|
+
]
|
92
|
+
|
93
|
+
coercions.each do |before, after|
|
94
|
+
assert_nothing_raised do
|
95
|
+
assert_equal after, CoercibleString.coerce(before)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class KerneltExtensionsTest < Test::Unit::TestCase
|
102
|
+
class Foo
|
103
|
+
def foo
|
104
|
+
__method__
|
105
|
+
end
|
106
|
+
|
107
|
+
def bar
|
108
|
+
foo
|
109
|
+
end
|
110
|
+
|
111
|
+
def baz
|
112
|
+
bar
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class Bar
|
117
|
+
def foo
|
118
|
+
calling_method
|
119
|
+
end
|
120
|
+
|
121
|
+
def bar
|
122
|
+
calling_method
|
123
|
+
end
|
124
|
+
|
125
|
+
def calling_method
|
126
|
+
__method__(1)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test___method___works_regardless_of_nesting
|
131
|
+
f = Foo.new
|
132
|
+
[:foo, :bar, :baz].each do |method|
|
133
|
+
assert_equal 'foo', f.send(method)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test___method___depth
|
138
|
+
b = Bar.new
|
139
|
+
assert_equal 'foo', b.foo
|
140
|
+
assert_equal 'bar', b.bar
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
class ModuleExtensionsTest < Test::Unit::TestCase
|
145
|
+
class Foo
|
146
|
+
def foo(reload = false)
|
147
|
+
memoize(reload) do
|
148
|
+
Time.now
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def bar(reload = false)
|
153
|
+
memoize(reload, :baz) do
|
154
|
+
Time.now
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def quux
|
159
|
+
Time.now
|
160
|
+
end
|
161
|
+
memoized :quux
|
162
|
+
end
|
163
|
+
|
164
|
+
def setup
|
165
|
+
@instance = Foo.new
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_memoize
|
169
|
+
assert !@instance.instance_variables.include?('@foo')
|
170
|
+
cached_result = @instance.foo
|
171
|
+
assert_equal cached_result, @instance.foo
|
172
|
+
assert @instance.instance_variables.include?('@foo')
|
173
|
+
assert_equal cached_result, @instance.send(:instance_variable_get, :@foo)
|
174
|
+
assert_not_equal cached_result, new_cache = @instance.foo(:reload)
|
175
|
+
assert_equal new_cache, @instance.foo
|
176
|
+
assert_equal new_cache, @instance.send(:instance_variable_get, :@foo)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_customizing_memoize_storage
|
180
|
+
assert !@instance.instance_variables.include?('@bar')
|
181
|
+
assert !@instance.instance_variables.include?('@baz')
|
182
|
+
cached_result = @instance.bar
|
183
|
+
assert !@instance.instance_variables.include?('@bar')
|
184
|
+
assert @instance.instance_variables.include?('@baz')
|
185
|
+
assert_equal cached_result, @instance.bar
|
186
|
+
assert_equal cached_result, @instance.send(:instance_variable_get, :@baz)
|
187
|
+
assert_nil @instance.send(:instance_variable_get, :@bar)
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_memoized
|
191
|
+
assert !@instance.instance_variables.include?('@quux')
|
192
|
+
cached_result = @instance.quux
|
193
|
+
assert_equal cached_result, @instance.quux
|
194
|
+
assert @instance.instance_variables.include?('@quux')
|
195
|
+
assert_equal cached_result, @instance.send(:instance_variable_get, :@quux)
|
196
|
+
assert_not_equal cached_result, new_cache = @instance.quux(:reload)
|
197
|
+
assert_equal new_cache, @instance.quux
|
198
|
+
assert_equal new_cache, @instance.send(:instance_variable_get, :@quux)
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_constant_setting
|
202
|
+
some_module = Module.new
|
203
|
+
assert !some_module.const_defined?(:FOO)
|
204
|
+
assert_nothing_raised do
|
205
|
+
some_module.constant :FOO, 'bar'
|
206
|
+
end
|
207
|
+
|
208
|
+
assert some_module.const_defined?(:FOO)
|
209
|
+
assert_nothing_raised do
|
210
|
+
some_module::FOO
|
211
|
+
some_module.foo
|
212
|
+
end
|
213
|
+
assert_equal 'bar', some_module::FOO
|
214
|
+
assert_equal 'bar', some_module.foo
|
215
|
+
|
216
|
+
assert_nothing_raised do
|
217
|
+
some_module.constant :FOO, 'baz'
|
218
|
+
end
|
219
|
+
|
220
|
+
assert_equal 'bar', some_module::FOO
|
221
|
+
assert_equal 'bar', some_module.foo
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
class AttributeProxyTest < Test::Unit::TestCase
|
226
|
+
class BlindProxyUsingDefaultAttributesHash
|
227
|
+
include SelectiveAttributeProxy
|
228
|
+
proxy_to :exlusively => false
|
229
|
+
end
|
230
|
+
|
231
|
+
class BlindProxyUsingCustomAttributeHash
|
232
|
+
include SelectiveAttributeProxy
|
233
|
+
proxy_to :settings
|
234
|
+
end
|
235
|
+
|
236
|
+
class ProxyUsingPassedInAttributeHash
|
237
|
+
include SelectiveAttributeProxy
|
238
|
+
|
239
|
+
def initialize(attributes = {})
|
240
|
+
@attributes = attributes
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
class RestrictedProxy
|
245
|
+
include SelectiveAttributeProxy
|
246
|
+
|
247
|
+
private
|
248
|
+
def proxiable_attribute?(name)
|
249
|
+
%w(foo bar baz).include?(name)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
class NonExclusiveProxy
|
254
|
+
include SelectiveAttributeProxy
|
255
|
+
proxy_to :settings, :exclusively => false
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_using_all_defaults
|
259
|
+
b = BlindProxyUsingDefaultAttributesHash.new
|
260
|
+
assert_nothing_raised do
|
261
|
+
b.foo = 'bar'
|
262
|
+
end
|
263
|
+
|
264
|
+
assert_nothing_raised do
|
265
|
+
b.foo
|
266
|
+
end
|
267
|
+
|
268
|
+
assert_equal 'bar', b.foo
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_storage_is_autovivified
|
272
|
+
b = BlindProxyUsingDefaultAttributesHash.new
|
273
|
+
assert_nothing_raised do
|
274
|
+
b.send(:attributes)['foo'] = 'bar'
|
275
|
+
end
|
276
|
+
|
277
|
+
assert_nothing_raised do
|
278
|
+
b.foo
|
279
|
+
end
|
280
|
+
|
281
|
+
assert_equal 'bar', b.foo
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_limiting_which_attributes_are_proxiable
|
285
|
+
r = RestrictedProxy.new
|
286
|
+
assert_nothing_raised do
|
287
|
+
r.foo = 'bar'
|
288
|
+
end
|
289
|
+
|
290
|
+
assert_nothing_raised do
|
291
|
+
r.foo
|
292
|
+
end
|
293
|
+
|
294
|
+
assert_equal 'bar', r.foo
|
295
|
+
|
296
|
+
assert_raises(NoMethodError) do
|
297
|
+
r.quux = 'foo'
|
298
|
+
end
|
299
|
+
|
300
|
+
assert_raises(NoMethodError) do
|
301
|
+
r.quux
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_proxying_is_exclusive_by_default
|
306
|
+
p = ProxyUsingPassedInAttributeHash.new('foo' => 'bar')
|
307
|
+
assert_nothing_raised do
|
308
|
+
p.foo
|
309
|
+
p.foo = 'baz'
|
310
|
+
end
|
311
|
+
|
312
|
+
assert_equal 'baz', p.foo
|
313
|
+
|
314
|
+
assert_raises(NoMethodError) do
|
315
|
+
p.quux
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_setting_the_proxy_as_non_exclusive
|
320
|
+
n = NonExclusiveProxy.new
|
321
|
+
assert_nothing_raised do
|
322
|
+
n.foo = 'baz'
|
323
|
+
end
|
324
|
+
|
325
|
+
assert_nothing_raised do
|
326
|
+
n.foo
|
327
|
+
end
|
328
|
+
|
329
|
+
assert_equal 'baz', n.foo
|
330
|
+
end
|
331
|
+
end
|
data/test/fixtures.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module AWS
|
4
|
+
module S3
|
5
|
+
# When this file is loaded, for each fixture file, a module is created within the Fixtures module
|
6
|
+
# with the same name as the fixture file. For each fixture in that fixture file, a singleton method is
|
7
|
+
# added to the module with the name of the given fixture, returning the value of the fixture.
|
8
|
+
#
|
9
|
+
# For example:
|
10
|
+
#
|
11
|
+
# A fixture in <tt>buckets.yml</tt> named <tt>empty_bucket_list</tt> with value <tt><foo>hi!</foo></tt>
|
12
|
+
# would be made available like so:
|
13
|
+
#
|
14
|
+
# Fixtures::Buckets.empty_bucket_list
|
15
|
+
# => "<foo>hi!</foo>"
|
16
|
+
#
|
17
|
+
# Alternatively you can treat the fixture module like a hash
|
18
|
+
#
|
19
|
+
# Fixtures::Buckets[:empty_bucket_list]
|
20
|
+
# => "<foo>hi!</foo>"
|
21
|
+
#
|
22
|
+
# You can find out all available fixtures by calling
|
23
|
+
#
|
24
|
+
# Fixtures.fixtures
|
25
|
+
# => ["Buckets"]
|
26
|
+
#
|
27
|
+
# And all the fixtures contained in a given fixture by calling
|
28
|
+
#
|
29
|
+
# Fixtures::Buckets.fixtures
|
30
|
+
# => ["bucket_list_with_more_than_one_bucket", "bucket_list_with_one_bucket", "empty_bucket_list"]
|
31
|
+
module Fixtures
|
32
|
+
class << self
|
33
|
+
def create_fixtures
|
34
|
+
files.each do |file|
|
35
|
+
create_fixture_for(file)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_fixture_for(file)
|
40
|
+
fixtures = YAML.load_file(path(file))
|
41
|
+
fixture_module = Module.new
|
42
|
+
|
43
|
+
fixtures.each do |name, value|
|
44
|
+
fixture_module.module_eval(<<-EVAL, __FILE__, __LINE__)
|
45
|
+
def #{name}
|
46
|
+
#{value.inspect}
|
47
|
+
end
|
48
|
+
module_function :#{name}
|
49
|
+
EVAL
|
50
|
+
end
|
51
|
+
|
52
|
+
fixture_module.module_eval(<<-EVAL, __FILE__, __LINE__)
|
53
|
+
module_function
|
54
|
+
|
55
|
+
def fixtures
|
56
|
+
#{fixtures.keys.sort.inspect}
|
57
|
+
end
|
58
|
+
|
59
|
+
def [](name)
|
60
|
+
send(name) if fixtures.include?(name.to_s)
|
61
|
+
end
|
62
|
+
EVAL
|
63
|
+
|
64
|
+
const_set(module_name(file), fixture_module)
|
65
|
+
end
|
66
|
+
|
67
|
+
def fixtures
|
68
|
+
constants.sort
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def files
|
74
|
+
Dir.glob(File.dirname(__FILE__) + '/fixtures/*.yml').map {|fixture| File.basename(fixture)}
|
75
|
+
end
|
76
|
+
|
77
|
+
def module_name(file_name)
|
78
|
+
File.basename(file_name, '.*').capitalize
|
79
|
+
end
|
80
|
+
|
81
|
+
def path(file_name)
|
82
|
+
File.join(File.dirname(__FILE__), 'fixtures', file_name)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
create_fixtures
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class LoggingStatusReadingTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@disabled = logging_status(:logging_disabled)
|
7
|
+
@enabled = logging_status(:logging_enabled)
|
8
|
+
@new_status = Logging::Status.new('target_bucket' => 'foo', 'target_prefix' => 'access-log-')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_logging_enabled?
|
12
|
+
assert !@disabled.logging_enabled?
|
13
|
+
assert !@new_status.logging_enabled?
|
14
|
+
assert @enabled.logging_enabled?
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_passing_in_prefix_and_bucket
|
18
|
+
assert_equal 'foo', @new_status.target_bucket
|
19
|
+
assert_equal 'access-log-', @new_status.target_prefix
|
20
|
+
assert !@new_status.logging_enabled?
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def logging_status(fixture)
|
25
|
+
Logging::Status.new(Parsing::XmlParser.new(Fixtures::Logging[fixture.to_s]))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class LoggingStatusWritingTest < LoggingStatusReadingTest
|
30
|
+
def setup
|
31
|
+
super
|
32
|
+
@disabled = Logging::Status.new(Parsing::XmlParser.new(@disabled.to_xml))
|
33
|
+
@enabled = Logging::Status.new(Parsing::XmlParser.new(@enabled.to_xml))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class LogTest < Test::Unit::TestCase
|
38
|
+
def test_value_converted_to_log_lines
|
39
|
+
log_object = S3Object.new
|
40
|
+
log_object.value = Fixtures::Logs.simple_log.join
|
41
|
+
log = Logging::Log.new(log_object)
|
42
|
+
assert_nothing_raised do
|
43
|
+
log.lines
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_equal 2, log.lines.size
|
47
|
+
assert_kind_of Logging::Log::Line, log.lines.first
|
48
|
+
assert_equal 'marcel', log.lines.first.bucket
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class LogLineTest < Test::Unit::TestCase
|
53
|
+
def setup
|
54
|
+
@line = Logging::Log::Line.new(Fixtures::Loglines.bucket_get)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_field_accessors
|
58
|
+
expected_results = {
|
59
|
+
:owner => Owner.new('id' => 'bb2041a25975c3d4ce9775fe9e93e5b77a6a9fad97dc7e00686191f3790b13f1'),
|
60
|
+
:bucket => 'marcel',
|
61
|
+
:time => Time.parse('11/14/2006 06:36:48 +0000'),
|
62
|
+
:remote_ip => '67.165.183.125',
|
63
|
+
:request_id => '8B5297D428A05432',
|
64
|
+
:requestor => Owner.new('id' => 'bb2041a25975c3d4ce9775fe9e93e5b77a6a9fad97dc7e00686191f3790b13f1'),
|
65
|
+
:operation => 'REST.GET.BUCKET',
|
66
|
+
:key => nil,
|
67
|
+
:request_uri => 'GET /marcel HTTP/1.1',
|
68
|
+
:http_status => 200,
|
69
|
+
:error_code => nil,
|
70
|
+
:bytes_sent => 4534,
|
71
|
+
:object_size => nil,
|
72
|
+
:total_time => 398,
|
73
|
+
:turn_around_time => 395,
|
74
|
+
:referrer => nil,
|
75
|
+
:user_agent => nil
|
76
|
+
}
|
77
|
+
|
78
|
+
expected_results.each do |field, expected|
|
79
|
+
assert_equal expected, @line.send(field)
|
80
|
+
end
|
81
|
+
|
82
|
+
assert_equal expected_results, @line.attributes
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_user_agent
|
86
|
+
line = Logging::Log::Line.new(Fixtures::Loglines.browser_get)
|
87
|
+
assert_equal 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0', line.user_agent
|
88
|
+
end
|
89
|
+
end
|
data/test/object_test.rb
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ObjectTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
bucket = Bucket.new(Parsing::XmlParser.new(Fixtures::Buckets.bucket_with_one_key))
|
6
|
+
@object = bucket.objects.first
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_header_settings_reader_and_writer
|
10
|
+
headers = {'content-type' => 'text/plain'}
|
11
|
+
mock_connection_for(S3Object, :returns => {:headers => headers})
|
12
|
+
|
13
|
+
assert_nothing_raised do
|
14
|
+
@object.content_type
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_equal 'text/plain', @object.content_type
|
18
|
+
|
19
|
+
assert_nothing_raised do
|
20
|
+
@object.content_type = 'image/jpg'
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_equal 'image/jpg', @object.content_type
|
24
|
+
|
25
|
+
assert_raises(NoMethodError) do
|
26
|
+
@object.non_existant_header_setting
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_key_name_validation
|
31
|
+
assert_raises(InvalidKeyName) do
|
32
|
+
S3Object.create(nil, '', 'marcel')
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_raises(InvalidKeyName) do
|
36
|
+
huge_name = 'a' * 1500
|
37
|
+
S3Object.create(huge_name, '', 'marcel')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_content_type_inference
|
42
|
+
[
|
43
|
+
['foo.jpg', {}, 'image/jpeg'],
|
44
|
+
['foo.txt', {}, 'text/plain'],
|
45
|
+
['foo', {}, nil],
|
46
|
+
['foo.asdf', {}, nil],
|
47
|
+
['foo.jpg', {:content_type => nil}, nil],
|
48
|
+
['foo', {:content_type => 'image/jpg'}, 'image/jpg'],
|
49
|
+
['foo.jpg', {:content_type => 'image/png'}, 'image/png'],
|
50
|
+
['foo.asdf', {:content_type => 'image/jpg'}, 'image/jpg']
|
51
|
+
].each do |key, options, content_type|
|
52
|
+
S3Object.send(:infer_content_type!, key, options)
|
53
|
+
assert_equal content_type, options[:content_type]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_object_has_owner
|
58
|
+
assert_kind_of Owner, @object.owner
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_owner_attributes_are_accessible
|
62
|
+
owner = @object.owner
|
63
|
+
assert owner.id
|
64
|
+
assert owner.display_name
|
65
|
+
assert_equal 'bb2041a25975c3d4ce9775fe9e93e5b77a6a9fad97dc7e00686191f3790b13f1', owner.id
|
66
|
+
assert_equal 'mmolina@onramp.net', owner.display_name
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_only_valid_attributes_accessible
|
70
|
+
assert_raises(NoMethodError) do
|
71
|
+
@object.owner.foo
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_fetching_object_value_generates_value_object
|
76
|
+
mock_connection_for(S3Object, :returns => {:body => 'hello!'})
|
77
|
+
value = S3Object.value('foo', 'bar')
|
78
|
+
assert_kind_of S3Object::Value, value
|
79
|
+
assert_equal 'hello!', value
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_fetching_file_by_name_raises_when_heuristic_fails
|
83
|
+
mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_one_key})
|
84
|
+
assert_raises(NoSuchKey) do
|
85
|
+
S3Object.find('not_tongue_overload.jpg', 'marcel_molina')
|
86
|
+
end
|
87
|
+
|
88
|
+
object = nil # Block scoping
|
89
|
+
assert_nothing_raised do
|
90
|
+
object = S3Object.find('tongue_overload.jpg', 'marcel_molina')
|
91
|
+
end
|
92
|
+
assert_kind_of S3Object, object
|
93
|
+
assert_equal 'tongue_overload.jpg', object.key
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_about
|
97
|
+
headers = {'content-size' => '12345', 'date' => Time.now.httpdate, 'content-type' => 'application/xml'}
|
98
|
+
mock_connection_for(S3Object, :returns => [
|
99
|
+
{:headers => headers},
|
100
|
+
{:code => 404}
|
101
|
+
]
|
102
|
+
)
|
103
|
+
about = S3Object.about('foo', 'bar')
|
104
|
+
assert_kind_of S3Object::About, about
|
105
|
+
assert_equal headers, about
|
106
|
+
|
107
|
+
assert_raises(NoSuchKey) do
|
108
|
+
S3Object.about('foo', 'bar')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_can_tell_that_an_s3object_does_not_exist
|
113
|
+
mock_connection_for(S3Object, :returns => {:code => 404})
|
114
|
+
assert_equal false, S3Object.exists?('foo', 'bar')
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_can_tell_that_an_s3object_exists
|
118
|
+
mock_connection_for(S3Object, :returns => {:code => 200})
|
119
|
+
assert_equal true, S3Object.exists?('foo', 'bar')
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_s3object_equality
|
123
|
+
mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_more_than_one_key})
|
124
|
+
file1, file2 = Bucket.objects('does not matter')
|
125
|
+
assert file1 == file1
|
126
|
+
assert file2 == file2
|
127
|
+
assert !(file1 == file2) # /!\ Parens required /!\
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_inspect
|
131
|
+
mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_one_key})
|
132
|
+
object = S3Object.find('tongue_overload.jpg', 'bucket does not matter')
|
133
|
+
assert object.path
|
134
|
+
assert_nothing_raised { object.inspect }
|
135
|
+
assert object.inspect[object.path]
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_etag
|
139
|
+
mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_one_key})
|
140
|
+
file = S3Object.find('tongue_overload.jpg', 'bucket does not matter')
|
141
|
+
assert file.etag
|
142
|
+
assert_equal 'f21f7c4e8ea6e34b268887b07d6da745', file.etag
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_fetching_information_about_an_object_that_does_not_exist_raises_no_such_key
|
146
|
+
mock_connection_for(S3Object, :returns => {:body => '', :code => 404})
|
147
|
+
assert_raises(NoSuchKey) do
|
148
|
+
S3Object.about('asdfasdfasdfas-this-does-not-exist', 'bucket does not matter')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
class MetadataTest < Test::Unit::TestCase
|
154
|
+
def setup
|
155
|
+
@metadata = S3Object::Metadata.new(Fixtures::Headers.headers_including_one_piece_of_metadata)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_only_metadata_is_extracted
|
159
|
+
assert @metadata.to_headers.size == 1
|
160
|
+
assert @metadata.to_headers['x-amz-meta-test']
|
161
|
+
assert_equal 'foo', @metadata.to_headers['x-amz-meta-test']
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_setting_new_metadata_normalizes_name
|
165
|
+
@metadata[:bar] = 'baz'
|
166
|
+
assert @metadata.to_headers.include?('x-amz-meta-bar')
|
167
|
+
@metadata['baz'] = 'quux'
|
168
|
+
assert @metadata.to_headers.include?('x-amz-meta-baz')
|
169
|
+
@metadata['x-amz-meta-quux'] = 'whatever'
|
170
|
+
assert @metadata.to_headers.include?('x-amz-meta-quux')
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_clobbering_existing_header
|
174
|
+
@metadata[:bar] = 'baz'
|
175
|
+
assert_equal 'baz', @metadata.to_headers['x-amz-meta-bar']
|
176
|
+
@metadata[:bar] = 'quux'
|
177
|
+
assert_equal 'quux', @metadata.to_headers['x-amz-meta-bar']
|
178
|
+
@metadata['bar'] = 'foo'
|
179
|
+
assert_equal 'foo', @metadata.to_headers['x-amz-meta-bar']
|
180
|
+
@metadata['x-amz-meta-bar'] = 'bar'
|
181
|
+
assert_equal 'bar', @metadata.to_headers['x-amz-meta-bar']
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_invalid_metadata
|
185
|
+
@metadata[:invalid_header] = ' ' * (S3Object::Metadata::SIZE_LIMIT + 1)
|
186
|
+
assert_raises InvalidMetadataValue do
|
187
|
+
@metadata.to_headers
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
class ValueTest < Test::Unit::TestCase
|
193
|
+
def setup
|
194
|
+
@response = FakeResponse.new(:body => 'hello there')
|
195
|
+
@value = S3Object::Value.new(@response)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_value_is_set_to_response_body
|
199
|
+
assert_equal @response.body, @value
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_response_is_accessible_from_value_object
|
203
|
+
assert_equal @response, @value.response
|
204
|
+
end
|
205
|
+
end
|