fake-aws-sdk 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDcyZGRiZjUxNDQxYThiOGE2NDQyNGYzZDRiNTI4YmM5ZGM0MDkyZA==
4
+ YWZiODdkOTg4NGE1MTE5NGY1MjllZjA0Nzk0MDgxMzE3NzA5ZjVmZQ==
5
5
  data.tar.gz: !binary |-
6
- YzVmMGVjMTk5ODM2MjE5ODcxNmQ4OWZlMzY3MTMyNTA3MDA0ODRkZg==
6
+ ZjI2NzQ1ZmQ2ZjdlZmFlZGMxYmI1NjVmNjc0NmVkNWRhOTk5N2RjYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjEwYjVkZGZjMjlhOTk2MWE3MWM5MGY0NjYxYzIzM2FlZGNmMWQ2NDc2ODlk
10
- Mjg3ZTkxZGJiMjRkZmYxMTg0YjA5ZWVlODdjNTZkMjQyNzQ5NjU0YmM0OTAw
11
- NjViMGI3NzdhMjRiODE4ZmUwMGNjZTcwYmFlNDkyNTY1NjVkNDk=
9
+ MGVlNTNmYzhlM2E0MTViM2I1N2U2MTk3ZWVlMzU5MmMzMDZkMzg2MjQxMWIw
10
+ NzE0NzcxOTEwMWUyYzM4MDgxZTRkNWFlZWMwZGIyZmRhZDBkYTVhMDFmZThj
11
+ YjVlMzI4ZTAxMTU1NzFlZDMxNTA4OGU3NTYzZmMwYjllMDk5ODA=
12
12
  data.tar.gz: !binary |-
13
- YTdmODFkNmUyOTE4NzRkOTM4ZmFiMGQ2Zjc2ZDY1ZjIyNjZmODIyMWIwYjEx
14
- OWIyNzZjYzNmYWNiZWI5MjY3M2UzZjRmYmY5NzU5OWZkNTc2ZTM3OTE5ZmE4
15
- Yzc3Zjk4N2JiNTgwNDMwYjY1NDIxY2FlYWZmYmEyZjdiNTRjYTM=
13
+ YmQxZTQ3NTAzYjY1Njc5OWY1NWNmNjcwZjk1MzYxZDdlNWQ2Y2UxZWJmZmFm
14
+ Nzc0ZmJkNWZjYWMxNDQwZGEzYzRmYWM5ZDZhN2JlZjFlNmI3ZGZlOGUwNmFm
15
+ ZTZmNDE0MWU3ZjY3ZmIyYTRkYWQzYTliY2VlMDFjYWZhZTRjYTA=
@@ -5,13 +5,15 @@ module FakeAWS
5
5
 
6
6
  class Bucket
7
7
 
8
- def initialize(name)
8
+ def initialize(name, options = {})
9
9
  @name = name
10
+ @location_constraint = options[:location_constraint]
10
11
  clear!
11
12
  end
12
13
 
13
14
  attr_reader :name
14
15
  attr_reader :objects
16
+ attr_reader :location_constraint
15
17
 
16
18
  def exists?
17
19
  true
@@ -22,7 +24,7 @@ module FakeAWS
22
24
  end
23
25
 
24
26
  def clear!
25
- @objects = ObjectCollection.new
27
+ @objects = ObjectCollection.new(self)
26
28
  end
27
29
 
28
30
  end
@@ -19,7 +19,11 @@ module FakeAWS
19
19
  include Enumerable
20
20
 
21
21
  def each(&block)
22
- @buckets.each_value(&block)
22
+ @buckets.values.sort_by(&:name).each(&block)
23
+ end
24
+
25
+ def create(name, options = {})
26
+ @buckets[name] = Bucket.new(name, options)
23
27
  end
24
28
 
25
29
  end
@@ -6,9 +6,10 @@ module FakeAWS
6
6
 
7
7
  class ObjectCollection
8
8
 
9
- def initialize
9
+ def initialize(bucket)
10
+ @bucket = bucket
10
11
  @objects = Hash.new do |h, key|
11
- h[key] = S3Object.new(key)
12
+ h[key] = S3Object.new(bucket, key)
12
13
  end
13
14
  end
14
15
 
@@ -19,10 +20,8 @@ module FakeAWS
19
20
 
20
21
  include Enumerable
21
22
 
22
- def each
23
- @objects.each_value do |object|
24
- yield object if object.exists?
25
- end
23
+ def each(&block)
24
+ @objects.values.select(&:exists?).sort_by(&:key).each(&block)
26
25
  end
27
26
 
28
27
  def empty?
@@ -3,10 +3,12 @@ module FakeAWS
3
3
 
4
4
  class S3Object
5
5
 
6
- def initialize(key)
6
+ def initialize(bucket, key)
7
+ @bucket = bucket
7
8
  @key = key
8
9
  end
9
10
 
11
+ attr_reader :bucket
10
12
  attr_reader :key
11
13
 
12
14
  def write(data)
@@ -24,6 +26,14 @@ module FakeAWS
24
26
  @data
25
27
  end
26
28
 
29
+ def copy_to(target, options = {})
30
+ resolve_object_reference(target, options).write(self.read)
31
+ end
32
+
33
+ def copy_from(source, options = {})
34
+ write(resolve_object_reference(source, options).read)
35
+ end
36
+
27
37
  def content_length
28
38
  must_exist!
29
39
  @data.length
@@ -43,6 +53,22 @@ module FakeAWS
43
53
  raise KeyError unless exists?
44
54
  end
45
55
 
56
+ def resolve_object_reference(ref, options)
57
+ if ref.is_a?(S3Object)
58
+ ref
59
+ else
60
+ bucket = case
61
+ when options.has_key?(:bucket)
62
+ options[:bucket]
63
+ when options.has_key?(:bucket_name)
64
+ raise NotImplementError, "please specify :bucket"
65
+ else
66
+ self.bucket
67
+ end
68
+ bucket.objects[ref]
69
+ end
70
+ end
71
+
46
72
  end
47
73
 
48
74
  end
@@ -1,3 +1,3 @@
1
1
  module FakeAWS
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -25,11 +25,28 @@ describe FakeAWS::S3::BucketCollection do
25
25
  end
26
26
 
27
27
  describe "#each" do
28
- it "yields all buckets" do
28
+ it "yields all buckets in alphabetical order" do
29
+ buckets["c"]
29
30
  buckets["a"]
30
31
  buckets["b"]
31
- buckets.map(&:name).should eq(%w(a b))
32
+ buckets.map(&:name).should eq(%w(a b c))
32
33
  end
33
34
  end
34
35
 
36
+ describe "#create" do
37
+
38
+ before do
39
+ buckets.create("sydney-bucket", :location_constraint => "ap-southeast-2")
40
+ end
41
+
42
+ it "creates a Bucket" do
43
+ buckets.first.name.should eq("sydney-bucket")
44
+ end
45
+
46
+ it "records the location_constraint" do
47
+ buckets["sydney-bucket"].location_constraint.should eq("ap-southeast-2")
48
+ end
49
+
50
+ end
51
+
35
52
  end
@@ -24,6 +24,14 @@ describe FakeAWS::S3::Bucket do
24
24
 
25
25
  end
26
26
 
27
+ describe "#location_constraint" do
28
+
29
+ it "defaults to nil" do
30
+ bucket.location_constraint.should be_nil
31
+ end
32
+
33
+ end
34
+
27
35
  context "containing objects" do
28
36
 
29
37
  before do
@@ -45,4 +53,14 @@ describe FakeAWS::S3::Bucket do
45
53
 
46
54
  end
47
55
 
56
+ context "with a location_constraint" do
57
+
58
+ let(:bucket) { described_class.new("foo", :location_constraint => "over-there") }
59
+
60
+ it "exposes the specified #location_constraint" do
61
+ bucket.location_constraint.should eq("over-there")
62
+ end
63
+
64
+ end
65
+
48
66
  end
@@ -2,7 +2,8 @@ require "fake_aws/s3/object_collection"
2
2
 
3
3
  describe FakeAWS::S3::ObjectCollection do
4
4
 
5
- let(:objects) { FakeAWS::S3::ObjectCollection.new }
5
+ let(:bucket) { double("BUCKET") }
6
+ let(:objects) { FakeAWS::S3::ObjectCollection.new(bucket) }
6
7
 
7
8
  it "starts empty" do
8
9
  objects.should be_empty
@@ -35,6 +36,7 @@ describe FakeAWS::S3::ObjectCollection do
35
36
  context "after writing some objects" do
36
37
 
37
38
  before do
39
+ objects["c"].write("CONTENT")
38
40
  objects["a"].write("CONTENT")
39
41
  objects["b"].write("CONTENT")
40
42
  end
@@ -45,8 +47,8 @@ describe FakeAWS::S3::ObjectCollection do
45
47
 
46
48
  describe "#each" do
47
49
 
48
- it "yields the objects with content" do
49
- objects.map(&:key).should eq(%w(a b))
50
+ it "yields objects in alphabetical order" do
51
+ objects.map(&:key).should eq(%w(a b c))
50
52
  end
51
53
 
52
54
  end
@@ -3,7 +3,10 @@ require "fake_aws/s3/s3_object"
3
3
 
4
4
  describe FakeAWS::S3::S3Object do
5
5
 
6
- let(:object) { FakeAWS::S3::S3Object.new("test-object") }
6
+ let(:bucket) { FakeAWS::S3::Bucket.new("foo") }
7
+ let(:other_bucket) { FakeAWS::S3::Bucket.new("bar") }
8
+
9
+ let(:object) { bucket.objects["test-object"] }
7
10
 
8
11
  subject { object }
9
12
 
@@ -114,4 +117,98 @@ describe FakeAWS::S3::S3Object do
114
117
 
115
118
  end
116
119
 
120
+ describe "#copy_to" do
121
+
122
+ before do
123
+ object.write("CONTENT")
124
+ end
125
+
126
+ context "with a target S3Object" do
127
+
128
+ let(:target_object) { other_bucket.objects["target"] }
129
+
130
+ before do
131
+ object.copy_to(target_object)
132
+ end
133
+
134
+ it "copies the object" do
135
+ target_object.read.should eq("CONTENT")
136
+ end
137
+
138
+ end
139
+
140
+ context "with a target key" do
141
+
142
+ before do
143
+ object.copy_to("dupe")
144
+ end
145
+
146
+ it "copies within the existing bucket" do
147
+ object.bucket.objects["dupe"].read.should eq("CONTENT")
148
+ end
149
+
150
+ end
151
+
152
+ context "with a target key, and a :bucket" do
153
+
154
+ before do
155
+ object.copy_to("dupe", :bucket => other_bucket)
156
+ end
157
+
158
+ it "copies to the specified bucket" do
159
+ other_bucket.objects["dupe"].read.should eq("CONTENT")
160
+ end
161
+
162
+ end
163
+
164
+ end
165
+
166
+ describe "#copy_from" do
167
+
168
+ let(:source_object) { other_bucket.objects["source"] }
169
+
170
+ before do
171
+ source_object.write("CONTENT")
172
+ end
173
+
174
+ context "with a source S3Object" do
175
+
176
+ before do
177
+ object.copy_from(source_object)
178
+ end
179
+
180
+ it "copies the object" do
181
+ object.read.should eq("CONTENT")
182
+ end
183
+
184
+ end
185
+
186
+ context "with a source key" do
187
+
188
+ let(:source_object) { bucket.objects["source"] }
189
+
190
+ before do
191
+ object.copy_from("source")
192
+ end
193
+
194
+ it "copies within the existing bucket" do
195
+ object.read.should eq("CONTENT")
196
+ end
197
+
198
+ end
199
+
200
+ context "with a target key, and a :bucket" do
201
+
202
+ before do
203
+ object.copy_from("source", :bucket => other_bucket)
204
+ end
205
+
206
+ it "copies from the specified bucket" do
207
+ object.read.should eq("CONTENT")
208
+ end
209
+
210
+ end
211
+
212
+ end
213
+
117
214
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake-aws-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-02-27 00:00:00.000000000 Z
11
+ date: 2013-04-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fake implementation of AWS SDK
14
14
  email: