aws-s3 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -2
- data/README +2 -2
- data/Rakefile +18 -12
- data/lib/aws/s3/authentication.rb +8 -5
- data/lib/aws/s3/base.rb +5 -1
- data/lib/aws/s3/bucket.rb +3 -4
- data/lib/aws/s3/connection.rb +18 -9
- data/lib/aws/s3/extensions.rb +5 -4
- data/lib/aws/s3/logging.rb +8 -3
- data/lib/aws/s3/object.rb +11 -9
- data/lib/aws/s3/version.rb +1 -1
- data/test/authentication_test.rb +19 -1
- data/test/base_test.rb +41 -48
- data/test/bucket_test.rb +44 -18
- data/test/connection_test.rb +42 -16
- data/test/error_test.rb +13 -18
- data/test/fixtures/buckets.yml +31 -0
- data/test/mocks/fake_response.rb +26 -0
- data/test/object_test.rb +69 -81
- data/test/remote/object_test.rb +2 -2
- data/test/response_test.rb +3 -5
- data/test/service_test.rb +11 -14
- data/test/test_helper.rb +23 -2
- metadata +87 -80
- data/test/mocks/base.rb +0 -89
data/test/remote/object_test.rb
CHANGED
@@ -315,7 +315,7 @@ class RemoteS3ObjectTest < Test::Unit::TestCase
|
|
315
315
|
S3Object.delete('name with spaces', TEST_BUCKET)
|
316
316
|
end
|
317
317
|
|
318
|
-
def
|
318
|
+
def test_copying_an_object_should_copy_over_its_acl_also_if_requested
|
319
319
|
key = 'copied-objects-inherit-acl'
|
320
320
|
copy_key = key + '2'
|
321
321
|
S3Object.store(key, 'value does not matter', TEST_BUCKET)
|
@@ -328,7 +328,7 @@ class RemoteS3ObjectTest < Test::Unit::TestCase
|
|
328
328
|
acl = S3Object.acl(key, TEST_BUCKET)
|
329
329
|
assert_equal 3, acl.grants.size
|
330
330
|
|
331
|
-
S3Object.copy(key, copy_key, TEST_BUCKET)
|
331
|
+
S3Object.copy(key, copy_key, TEST_BUCKET, :copy_acl => true)
|
332
332
|
copied_object = S3Object.find(copy_key, TEST_BUCKET)
|
333
333
|
assert_equal acl.grants, copied_object.acl.grants
|
334
334
|
ensure
|
data/test/response_test.rb
CHANGED
@@ -34,11 +34,9 @@ end
|
|
34
34
|
|
35
35
|
class S3ObjectResponseTest < Test::Unit::TestCase
|
36
36
|
def test_etag_extracted
|
37
|
-
S3Object.
|
38
|
-
|
39
|
-
|
40
|
-
assert_equal "acbd18db4cc2f85cedef654fccc4a4d8", object_response.etag
|
41
|
-
end
|
37
|
+
mock_connection_for(S3Object, :returns => {:headers => {"etag" => %("acbd18db4cc2f85cedef654fccc4a4d8")}}).once
|
38
|
+
object_response = S3Object.create('name_does_not_matter', 'data does not matter', 'bucket does not matter')
|
39
|
+
assert_equal "acbd18db4cc2f85cedef654fccc4a4d8", object_response.etag
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
data/test/service_test.rb
CHANGED
@@ -2,25 +2,22 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
class ServiceTest < Test::Unit::TestCase
|
4
4
|
def test_bucket_list_with_empty_bucket_list
|
5
|
-
Service
|
6
|
-
|
7
|
-
|
8
|
-
end
|
5
|
+
mock_connection_for(Service, :returns => {:body => Fixtures::Buckets.empty_bucket_list, :code => 200})
|
6
|
+
list = Service.buckets(:reload)
|
7
|
+
assert_equal [], list
|
9
8
|
end
|
10
9
|
|
11
10
|
def test_bucket_list_with_bucket_list_containing_one_bucket
|
12
|
-
Service
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
11
|
+
mock_connection_for(Service, :returns => {:body => Fixtures::Buckets.bucket_list_with_one_bucket, :code => 200})
|
12
|
+
list = Service.buckets(:reload)
|
13
|
+
assert_equal 1, list.size
|
14
|
+
assert_equal 'marcel_molina', list.first.name
|
17
15
|
end
|
18
16
|
|
19
17
|
def test_bucket_list_with_bucket_list_containing_more_than_one_bucket
|
20
|
-
Service
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
18
|
+
mock_connection_for(Service, :returns => {:body => Fixtures::Buckets.bucket_list_with_more_than_one_bucket, :code => 200})
|
19
|
+
list = Service.buckets(:reload)
|
20
|
+
assert_equal 2, list.size
|
21
|
+
assert_equal %w(marcel_molina marcel_molina_jr), list.map {|bucket| bucket.name}.sort
|
25
22
|
end
|
26
23
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
$:.unshift File.dirname(__FILE__) + '/../lib'
|
3
3
|
require 'aws/s3'
|
4
|
-
require File.dirname(__FILE__) + '/mocks/
|
4
|
+
require File.dirname(__FILE__) + '/mocks/fake_response'
|
5
5
|
require File.dirname(__FILE__) + '/fixtures'
|
6
|
-
require_library_or_gem '
|
6
|
+
require_library_or_gem 'ruby-debug'
|
7
|
+
require_library_or_gem 'flexmock'
|
8
|
+
require_library_or_gem 'flexmock/test_unit'
|
9
|
+
|
7
10
|
|
8
11
|
# Data copied from http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAuthentication.html
|
9
12
|
module AmazonDocExampleData
|
@@ -83,4 +86,22 @@ class Test::Unit::TestCase
|
|
83
86
|
def sample_proxy_settings
|
84
87
|
{:host => 'http://google.com', :port => 8080, :user => 'marcel', :password => 'secret'}
|
85
88
|
end
|
89
|
+
|
90
|
+
def mock_connection_for(klass, options = {})
|
91
|
+
data = options[:returns]
|
92
|
+
return_values = case data
|
93
|
+
when Hash
|
94
|
+
FakeResponse.new(data)
|
95
|
+
when Array
|
96
|
+
data.map {|hash| FakeResponse.new(hash)}
|
97
|
+
else
|
98
|
+
abort "Response data for mock connection must be a Hash or an Array. Was #{data.inspect}."
|
99
|
+
end
|
100
|
+
|
101
|
+
connection = flexmock('Mock connection') do |mock|
|
102
|
+
mock.should_receive(:request).and_return(*return_values).at_least.once
|
103
|
+
end
|
104
|
+
|
105
|
+
flexmock(klass).should_receive(:connection).and_return(connection)
|
106
|
+
end
|
86
107
|
end
|
metadata
CHANGED
@@ -1,36 +1,56 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: aws-s3
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-07-08 00:00:00 -05:00
|
8
|
-
summary: Client library for Amazon's Simple Storage Service's REST API
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: marcel@vernix.org
|
12
|
-
homepage: http://amazon.rubyforge.org
|
13
|
-
rubyforge_project: amazon
|
14
|
-
description: Client library for Amazon's Simple Storage Service's REST API
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.5.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Marcel Molina Jr.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-07 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: xml-simple
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: builder
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mime-types
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
description: Client library for Amazon's Simple Storage Service's REST API
|
43
|
+
email: marcel@vernix.org
|
44
|
+
executables:
|
45
|
+
- s3sh
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files:
|
49
|
+
- README
|
50
|
+
- COPYING
|
51
|
+
- INSTALL
|
31
52
|
files:
|
32
53
|
- Rakefile
|
33
|
-
- lib/aws/s3.rb
|
34
54
|
- lib/aws/s3/acl.rb
|
35
55
|
- lib/aws/s3/authentication.rb
|
36
56
|
- lib/aws/s3/base.rb
|
@@ -47,6 +67,7 @@ files:
|
|
47
67
|
- lib/aws/s3/response.rb
|
48
68
|
- lib/aws/s3/service.rb
|
49
69
|
- lib/aws/s3/version.rb
|
70
|
+
- lib/aws/s3.rb
|
50
71
|
- bin/s3sh
|
51
72
|
- bin/setup.rb
|
52
73
|
- support/faster-xml-simple/lib/faster_xml_simple.rb
|
@@ -57,6 +78,37 @@ files:
|
|
57
78
|
- README
|
58
79
|
- COPYING
|
59
80
|
- INSTALL
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://amazon.rubyforge.org
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options:
|
85
|
+
- --title
|
86
|
+
- AWS::S3 -- Support for Amazon S3's REST api
|
87
|
+
- --main
|
88
|
+
- README
|
89
|
+
- --line-numbers
|
90
|
+
- --inline-source
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: "0"
|
98
|
+
version:
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
104
|
+
version:
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project: amazon
|
108
|
+
rubygems_version: 1.1.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 2
|
111
|
+
summary: Client library for Amazon's Simple Storage Service's REST API
|
60
112
|
test_files:
|
61
113
|
- test/acl_test.rb
|
62
114
|
- test/authentication_test.rb
|
@@ -66,15 +118,6 @@ test_files:
|
|
66
118
|
- test/error_test.rb
|
67
119
|
- test/extensions_test.rb
|
68
120
|
- test/fixtures
|
69
|
-
- test/fixtures.rb
|
70
|
-
- test/logging_test.rb
|
71
|
-
- test/mocks
|
72
|
-
- test/object_test.rb
|
73
|
-
- test/parsing_test.rb
|
74
|
-
- test/remote
|
75
|
-
- test/response_test.rb
|
76
|
-
- test/service_test.rb
|
77
|
-
- test/test_helper.rb
|
78
121
|
- test/fixtures/buckets.yml
|
79
122
|
- test/fixtures/errors.yml
|
80
123
|
- test/fixtures/headers.yml
|
@@ -82,7 +125,13 @@ test_files:
|
|
82
125
|
- test/fixtures/loglines.yml
|
83
126
|
- test/fixtures/logs.yml
|
84
127
|
- test/fixtures/policies.yml
|
85
|
-
- test/
|
128
|
+
- test/fixtures.rb
|
129
|
+
- test/logging_test.rb
|
130
|
+
- test/mocks
|
131
|
+
- test/mocks/fake_response.rb
|
132
|
+
- test/object_test.rb
|
133
|
+
- test/parsing_test.rb
|
134
|
+
- test/remote
|
86
135
|
- test/remote/acl_test.rb
|
87
136
|
- test/remote/bittorrent_test.rb
|
88
137
|
- test/remote/bucket_test.rb
|
@@ -90,48 +139,6 @@ test_files:
|
|
90
139
|
- test/remote/object_test.rb
|
91
140
|
- test/remote/test_file.data
|
92
141
|
- test/remote/test_helper.rb
|
93
|
-
|
94
|
-
-
|
95
|
-
-
|
96
|
-
- --main
|
97
|
-
- README
|
98
|
-
- --line-numbers
|
99
|
-
- --inline-source
|
100
|
-
extra_rdoc_files:
|
101
|
-
- README
|
102
|
-
- COPYING
|
103
|
-
- INSTALL
|
104
|
-
executables:
|
105
|
-
- s3sh
|
106
|
-
extensions: []
|
107
|
-
|
108
|
-
requirements: []
|
109
|
-
|
110
|
-
dependencies:
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: xml-simple
|
113
|
-
version_requirement:
|
114
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
115
|
-
requirements:
|
116
|
-
- - ">"
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: 0.0.0
|
119
|
-
version:
|
120
|
-
- !ruby/object:Gem::Dependency
|
121
|
-
name: builder
|
122
|
-
version_requirement:
|
123
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
124
|
-
requirements:
|
125
|
-
- - ">"
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
version: 0.0.0
|
128
|
-
version:
|
129
|
-
- !ruby/object:Gem::Dependency
|
130
|
-
name: mime-types
|
131
|
-
version_requirement:
|
132
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
133
|
-
requirements:
|
134
|
-
- - ">"
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
version: 0.0.0
|
137
|
-
version:
|
142
|
+
- test/response_test.rb
|
143
|
+
- test/service_test.rb
|
144
|
+
- test/test_helper.rb
|
data/test/mocks/base.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require_library_or_gem 'flexmock'
|
2
|
-
|
3
|
-
module AWS
|
4
|
-
module S3
|
5
|
-
class FakeResponse < String
|
6
|
-
attr_reader :code, :body, :headers
|
7
|
-
def initialize(options = {})
|
8
|
-
@code = options.delete(:code) || 200
|
9
|
-
@body = options.delete(:body) || ''
|
10
|
-
@headers = {'content-type' => 'application/xml'}.merge(options.delete(:headers) || {})
|
11
|
-
super(@body)
|
12
|
-
end
|
13
|
-
|
14
|
-
# For ErrorResponse
|
15
|
-
def response
|
16
|
-
self
|
17
|
-
end
|
18
|
-
|
19
|
-
def [](header)
|
20
|
-
headers[header]
|
21
|
-
end
|
22
|
-
|
23
|
-
def each(&block)
|
24
|
-
headers.each(&block)
|
25
|
-
end
|
26
|
-
alias_method :each_header, :each
|
27
|
-
end
|
28
|
-
|
29
|
-
class Base
|
30
|
-
class << self
|
31
|
-
@@responses = []
|
32
|
-
@@in_test_mode = false
|
33
|
-
@@catch_all_response = nil
|
34
|
-
|
35
|
-
def in_test_mode=(boolean)
|
36
|
-
@@in_test_mode = boolean
|
37
|
-
end
|
38
|
-
|
39
|
-
def responses
|
40
|
-
@@responses
|
41
|
-
end
|
42
|
-
|
43
|
-
def catch_all_response
|
44
|
-
@@catch_all_response
|
45
|
-
end
|
46
|
-
|
47
|
-
def reset!
|
48
|
-
responses.clear
|
49
|
-
end
|
50
|
-
|
51
|
-
def request_returns(response_data)
|
52
|
-
responses.concat [response_data].flatten.map {|data| FakeResponse.new(data)}
|
53
|
-
end
|
54
|
-
|
55
|
-
def request_always_returns(response_data, &block)
|
56
|
-
in_test_mode do
|
57
|
-
@@catch_all_response = FakeResponse.new(response_data)
|
58
|
-
yield
|
59
|
-
@@catch_all_response = nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def in_test_mode(&block)
|
64
|
-
self.in_test_mode = true
|
65
|
-
yield
|
66
|
-
ensure
|
67
|
-
self.in_test_mode = false
|
68
|
-
end
|
69
|
-
|
70
|
-
alias_method :old_connection, :connection
|
71
|
-
def connection
|
72
|
-
if @@in_test_mode
|
73
|
-
@mock_connection ||=
|
74
|
-
begin
|
75
|
-
mock_connection = FlexMock.new
|
76
|
-
mock_connection.mock_handle(:request) do
|
77
|
-
raise 'No responses left' unless response = catch_all_response || responses.shift
|
78
|
-
response
|
79
|
-
end
|
80
|
-
mock_connection
|
81
|
-
end
|
82
|
-
else
|
83
|
-
old_connection
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|