blobstore_client 0.5.0 → 1.5.0.pre.1113

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.
@@ -1,106 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Bosh::Blobstore::SimpleBlobstoreClient do
4
-
5
- before(:each) do
6
- @httpclient = mock("httpclient")
7
- HTTPClient.stub!(:new).and_return(@httpclient)
8
- end
9
-
10
- describe "options" do
11
-
12
- it "should set up authentication when present" do
13
- response = mock("response")
14
- response.stub!(:status).and_return(200)
15
- response.stub!(:content).and_return("content_id")
16
-
17
- @httpclient.should_receive(:get).with("http://localhost/resources/foo", {},
18
- {"Authorization"=>"Basic am9objpzbWl0aA=="}).and_return(response)
19
- @client = Bosh::Blobstore::SimpleBlobstoreClient.new({"endpoint" => "http://localhost",
20
- "user" => "john",
21
- "password" => "smith"})
22
- @client.get("foo")
23
- end
24
-
25
- end
26
-
27
- describe "operations" do
28
-
29
- it "should create an object" do
30
- response = mock("response")
31
- response.stub!(:status).and_return(200)
32
- response.stub!(:content).and_return("content_id")
33
- @httpclient.should_receive(:post).with { |*args|
34
- uri, body, _ = args
35
- uri.should eql("http://localhost/resources")
36
- body.should be_kind_of(Hash)
37
- body[:content].should be_kind_of(File)
38
- body[:content].read.should eql("some object")
39
- true
40
- }.and_return(response)
41
-
42
- @client = Bosh::Blobstore::SimpleBlobstoreClient.new({"endpoint" => "http://localhost"})
43
- @client.create("some object").should eql("content_id")
44
- end
45
-
46
- it "should raise an exception when there is an error creating an object" do
47
- response = mock("response")
48
- response.stub!(:status).and_return(500)
49
-
50
- @httpclient.should_receive(:post).with { |*args|
51
- uri, body, _ = args
52
- uri.should eql("http://localhost/resources")
53
- body.should be_kind_of(Hash)
54
- body[:content].should be_kind_of(File)
55
- body[:content].read.should eql("some object")
56
- true
57
- }.and_return(response)
58
-
59
- @client = Bosh::Blobstore::SimpleBlobstoreClient.new({"endpoint" => "http://localhost"})
60
- lambda {@client.create("some object")}.should raise_error
61
- end
62
-
63
- it "should fetch an object" do
64
- response = mock("response")
65
- response.stub!(:status).and_return(200)
66
- @httpclient.should_receive(:get).with("http://localhost/resources/some object", {}, {}).
67
- and_yield("content_id").
68
- and_return(response)
69
-
70
- @client = Bosh::Blobstore::SimpleBlobstoreClient.new({"endpoint" => "http://localhost"})
71
- @client.get("some object").should eql("content_id")
72
- end
73
-
74
- it "should raise an exception when there is an error fetching an object" do
75
- response = mock("response")
76
- response.stub!(:status).and_return(500)
77
- response.stub!(:content).and_return("error message")
78
- @httpclient.should_receive(:get).with("http://localhost/resources/some object", {}, {}).and_return(response)
79
-
80
- @client = Bosh::Blobstore::SimpleBlobstoreClient.new({"endpoint" => "http://localhost"})
81
- lambda {@client.get("some object")}.should raise_error
82
- end
83
-
84
- it "should delete an object" do
85
- response = mock("response")
86
- response.stub!(:status).and_return(204)
87
- response.stub!(:content).and_return("")
88
- @httpclient.should_receive(:delete).with("http://localhost/resources/some object", {}).and_return(response)
89
-
90
- @client = Bosh::Blobstore::SimpleBlobstoreClient.new({"endpoint" => "http://localhost"})
91
- @client.delete("some object")
92
- end
93
-
94
- it "should raise an exception when there is an error deleting an object" do
95
- response = mock("response")
96
- response.stub!(:status).and_return(404)
97
- response.stub!(:content).and_return("")
98
- @httpclient.should_receive(:delete).with("http://localhost/resources/some object", {}).and_return(response)
99
-
100
- @client = Bosh::Blobstore::SimpleBlobstoreClient.new({"endpoint" => "http://localhost"})
101
- lambda {@client.delete("some object")}.should raise_error
102
- end
103
-
104
- end
105
-
106
- end
@@ -1,315 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Bosh::Blobstore::SwiftBlobstoreClient do
4
-
5
- def swift_options(container_name, swift_provider, credentials)
6
- if credentials
7
- options = {
8
- "rackspace" => {
9
- "rackspace_username" => "username",
10
- "rackspace_api_key" => "api_key"
11
- },
12
- "hp" => {
13
- "hp_account_id" => "account_id",
14
- "hp_secret_key" => "secret_key",
15
- "hp_tenant_id" => "tenant_id"
16
- }
17
- }
18
- else
19
- options = {}
20
- end
21
- options["container_name"] = container_name if container_name
22
- options["swift_provider"] = swift_provider if swift_provider
23
- options
24
- end
25
-
26
- def swift_blobstore(options)
27
- Bosh::Blobstore::SwiftBlobstoreClient.new(options)
28
- end
29
-
30
- before(:each) do
31
- @swift = mock("swift")
32
- Fog::Storage.stub!(:new).and_return(@swift)
33
- @http_client = mock("http-client")
34
- HTTPClient.stub!(:new).and_return(@http_client)
35
- end
36
-
37
- describe "on HP Cloud Storage" do
38
-
39
- describe "with credentials" do
40
-
41
- before(:each) do
42
- @client = swift_blobstore(swift_options("test-container",
43
- "hp",
44
- true))
45
- end
46
-
47
- it "should create an object" do
48
- data = "some content"
49
- directories = double("directories")
50
- container = double("container")
51
- files = double("files")
52
- object = double("object")
53
-
54
- @client.should_receive(:generate_object_id).and_return("object_id")
55
- @swift.stub(:directories).and_return(directories)
56
- directories.should_receive(:get).with("test-container") \
57
- .and_return(container)
58
- container.should_receive(:files).and_return(files)
59
- files.should_receive(:create).with { |opt|
60
- opt[:key].should eql "object_id"
61
- #opt[:body].should eql data
62
- opt[:public].should eql true
63
- }.and_return(object)
64
- object.should_receive(:public_url).and_return("public-url")
65
-
66
- object_id = @client.create(data)
67
- object_info = MultiJson.decode(Base64.decode64(
68
- URI::unescape(object_id)))
69
- object_info["oid"].should eql("object_id")
70
- object_info["purl"].should eql("public-url")
71
- end
72
-
73
- it "should fetch an object without a public url" do
74
- data = "some content"
75
- directories = double("directories")
76
- container = double("container")
77
- files = double("files")
78
- object = double("object")
79
-
80
- @swift.stub(:directories).and_return(directories)
81
- directories.should_receive(:get).with("test-container") \
82
- .and_return(container)
83
- container.should_receive(:files).and_return(files)
84
- files.should_receive(:get).with("object_id").and_yield(data) \
85
- .and_return(object)
86
-
87
- oid = URI::escape(Base64.encode64(MultiJson.encode(
88
- {:oid => "object_id"})))
89
- @client.get(oid).should eql(data)
90
- end
91
-
92
- it "should fetch an object with a public url" do
93
- data = "some content"
94
- response = mock("response")
95
-
96
- @http_client.should_receive(:get).with("public-url") \
97
- .and_yield(data).and_return(response)
98
- response.stub!(:status).and_return(200)
99
-
100
- oid = URI::escape(Base64.encode64(MultiJson.encode(
101
- {:oid => "object_id",
102
- :purl => "public-url"})))
103
- @client.get(oid).should eql(data)
104
- end
105
-
106
- it "should delete an object" do
107
- directories = double("directories")
108
- container = double("container")
109
- files = double("files")
110
- object = double("object")
111
-
112
- @swift.stub(:directories).and_return(directories)
113
- directories.should_receive(:get).with("test-container") \
114
- .and_return(container)
115
- container.should_receive(:files).and_return(files)
116
- files.should_receive(:get).with("object_id").and_return(object)
117
- object.should_receive(:destroy)
118
-
119
- oid = URI::escape(Base64.encode64(MultiJson.encode(
120
- {:oid => "object_id"})))
121
- @client.delete(oid)
122
- end
123
-
124
- end
125
-
126
- describe "without credentials" do
127
-
128
- before(:each) do
129
- @client = swift_blobstore(swift_options("test-container",
130
- "hp",
131
- false))
132
- end
133
-
134
- it "should refuse to create an object" do
135
- data = "some content"
136
-
137
- lambda {
138
- object_id = @client.create(data)
139
- }.should raise_error(Bosh::Blobstore::BlobstoreError)
140
- end
141
-
142
- it "should refuse to fetch an object without a public url" do
143
- oid = URI::escape(Base64.encode64(MultiJson.encode(
144
- {:oid => "object_id"})))
145
- lambda {
146
- @client.get(oid)
147
- }.should raise_error(Bosh::Blobstore::BlobstoreError)
148
- end
149
-
150
- it "should fetch an object with a public url" do
151
- data = "some content"
152
- response = mock("response")
153
-
154
- @http_client.should_receive(:get).with("public-url") \
155
- .and_yield(data).and_return(response)
156
- response.stub!(:status).and_return(200)
157
-
158
- oid = URI::escape(Base64.encode64(MultiJson.encode(
159
- {:oid => "object_id",
160
- :purl => "public-url"})))
161
- @client.get(oid).should eql(data)
162
- end
163
-
164
- it "should refuse to delete an object" do
165
- oid = URI::escape(Base64.encode64(MultiJson.encode(
166
- {:oid => "object_id"})))
167
- lambda {
168
- @client.delete(oid)
169
- }.should raise_error(Bosh::Blobstore::BlobstoreError)
170
- end
171
-
172
- end
173
-
174
- end
175
-
176
- describe "on Rackspace Cloud Files" do
177
-
178
- describe "with credentials" do
179
-
180
- before(:each) do
181
- @client = swift_blobstore(swift_options("test-container",
182
- "rackspace",
183
- true))
184
- end
185
-
186
- it "should create an object" do
187
- data = "some content"
188
- directories = double("directories")
189
- container = double("container")
190
- files = double("files")
191
- object = double("object")
192
-
193
- @client.should_receive(:generate_object_id).and_return("object_id")
194
- @swift.stub(:directories).and_return(directories)
195
- directories.should_receive(:get).with("test-container") \
196
- .and_return(container)
197
- container.should_receive(:files).and_return(files)
198
- files.should_receive(:create).with { |opt|
199
- opt[:key].should eql "object_id"
200
- #opt[:body].should eql data
201
- opt[:public].should eql true
202
- }.and_return(object)
203
- object.should_receive(:public_url).and_return("public-url")
204
-
205
- object_id = @client.create(data)
206
- object_info = MultiJson.decode(Base64.decode64(
207
- URI::unescape(object_id)))
208
- object_info["oid"].should eql("object_id")
209
- object_info["purl"].should eql("public-url")
210
- end
211
-
212
- it "should fetch an object without a public url" do
213
- data = "some content"
214
- directories = double("directories")
215
- container = double("container")
216
- files = double("files")
217
- object = double("object")
218
-
219
- @swift.stub(:directories).and_return(directories)
220
- directories.should_receive(:get).with("test-container") \
221
- .and_return(container)
222
- container.should_receive(:files).and_return(files)
223
- files.should_receive(:get).with("object_id").and_yield(data) \
224
- .and_return(object)
225
-
226
- oid = URI::escape(Base64.encode64(MultiJson.encode(
227
- {:oid => "object_id"})))
228
- @client.get(oid).should eql(data)
229
- end
230
-
231
- it "should fetch an object with a public url" do
232
- data = "some content"
233
- response = mock("response")
234
-
235
- @http_client.should_receive(:get).with("public-url") \
236
- .and_yield(data).and_return(response)
237
- response.stub!(:status).and_return(200)
238
-
239
- oid = URI::escape(Base64.encode64(MultiJson.encode(
240
- {:oid => "object_id",
241
- :purl => "public-url"})))
242
- @client.get(oid).should eql(data)
243
- end
244
-
245
- it "should delete an object" do
246
- directories = double("directories")
247
- container = double("container")
248
- files = double("files")
249
- object = double("object")
250
-
251
- @swift.stub(:directories).and_return(directories)
252
- directories.should_receive(:get).with("test-container") \
253
- .and_return(container)
254
- container.should_receive(:files).and_return(files)
255
- files.should_receive(:get).with("object_id").and_return(object)
256
- object.should_receive(:destroy)
257
-
258
- oid = URI::escape(Base64.encode64(MultiJson.encode(
259
- {:oid => "object_id"})))
260
- @client.delete(oid)
261
- end
262
-
263
- end
264
-
265
- describe "without credentials" do
266
-
267
- before(:each) do
268
- @client = swift_blobstore(swift_options("test-container",
269
- "rackspace",
270
- false))
271
- end
272
-
273
- it "should refuse to create an object" do
274
- data = "some content"
275
-
276
- lambda {
277
- object_id = @client.create(data)
278
- }.should raise_error(Bosh::Blobstore::BlobstoreError)
279
- end
280
-
281
- it "should refuse to fetch an object without a public url" do
282
- oid = URI::escape(Base64.encode64(MultiJson.encode(
283
- {:oid => "object_id"})))
284
- lambda {
285
- @client.get(oid)
286
- }.should raise_error(Bosh::Blobstore::BlobstoreError)
287
- end
288
-
289
- it "should fetch an object with a public url" do
290
- data = "some content"
291
- response = mock("response")
292
-
293
- @http_client.should_receive(:get).with("public-url") \
294
- .and_yield(data).and_return(response)
295
- response.stub!(:status).and_return(200)
296
-
297
- oid = URI::escape(Base64.encode64(MultiJson.encode(
298
- {:oid => "object_id",
299
- :purl => "public-url"})))
300
- @client.get(oid).should eql(data)
301
- end
302
-
303
- it "should refuse to delete an object" do
304
- oid = URI::escape(Base64.encode64(MultiJson.encode(
305
- {:oid => "object_id"})))
306
- lambda {
307
- @client.delete(oid)
308
- }.should raise_error(Bosh::Blobstore::BlobstoreError)
309
- end
310
-
311
- end
312
-
313
- end
314
-
315
- end