waz-storage 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +9 -9
  2. data/CHANGELOG.rdoc +72 -72
  3. data/Gemfile +4 -4
  4. data/Gemfile.lock +46 -46
  5. data/LICENSE +18 -18
  6. data/README.rdoc +310 -310
  7. data/lib/waz-blobs.rb +4 -4
  8. data/lib/waz-queues.rb +6 -6
  9. data/lib/waz-storage.rb +39 -39
  10. data/lib/waz-tables.rb +4 -4
  11. data/lib/waz/blobs/blob_object.rb +122 -122
  12. data/lib/waz/blobs/container.rb +172 -172
  13. data/lib/waz/blobs/exceptions.rb +10 -10
  14. data/lib/waz/blobs/service.rb +181 -181
  15. data/lib/waz/queues/exceptions.rb +28 -28
  16. data/lib/waz/queues/message.rb +64 -64
  17. data/lib/waz/queues/queue.rb +164 -164
  18. data/lib/waz/queues/service.rb +105 -105
  19. data/lib/waz/storage/base.rb +70 -70
  20. data/lib/waz/storage/core_service.rb +2 -1
  21. data/lib/waz/storage/exceptions.rb +33 -33
  22. data/lib/waz/storage/validation_rules.rb +25 -25
  23. data/lib/waz/tables/edm_type_helper.rb +44 -44
  24. data/lib/waz/tables/exceptions.rb +44 -44
  25. data/lib/waz/tables/service.rb +178 -178
  26. data/lib/waz/tables/table.rb +74 -74
  27. data/lib/waz/tables/table_array.rb +10 -10
  28. data/rakefile +7 -7
  29. data/spec/configuration.rb +22 -22
  30. data/spec/waz/blobs/blob_object_spec.rb +80 -80
  31. data/spec/waz/blobs/container_spec.rb +175 -175
  32. data/spec/waz/blobs/service_spec.rb +336 -336
  33. data/spec/waz/queues/message_spec.rb +32 -32
  34. data/spec/waz/queues/queue_spec.rb +205 -205
  35. data/spec/waz/queues/service_spec.rb +298 -298
  36. data/spec/waz/storage/base_tests.rb +81 -81
  37. data/spec/waz/storage/shared_key_core_service_spec.rb +141 -141
  38. data/spec/waz/tables/service_spec.rb +613 -613
  39. data/spec/waz/tables/table_spec.rb +97 -97
  40. data/waz-storage.gemspec +29 -29
  41. metadata +3 -3
@@ -1,336 +1,336 @@
1
- # enabling the load of files from root (on RSpec)
2
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../')
3
- require 'spec/configuration'
4
- require 'lib/waz-blobs'
5
-
6
- describe "blobs service behavior" do
7
- it "should create container" do
8
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
9
- RestClient::Request.any_instance.expects(:execute)
10
- service.expects(:generate_request_uri).with("mock-container", {:restype => 'container'}).returns("mock-uri")
11
- service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
12
- service.create_container('mock-container')
13
- end
14
-
15
- it "should get container properties" do
16
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
17
- mock_response = mock()
18
- mock_response.stubs(:headers).returns(RestClient::AbstractResponse.beautify_headers({"x-ms-meta-Name" => ["customName"]}))
19
- RestClient::Request.any_instance.expects(:execute).returns(mock_response)
20
- service.expects(:generate_request_uri).with("mock-container", {:restype => 'container'}).returns("mock-uri")
21
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
22
- properties = service.get_container_properties('mock-container')
23
- properties[:x_ms_meta_name].should == "customName"
24
- end
25
-
26
- it "should set container properties" do
27
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
28
- RestClient::Request.any_instance.expects(:execute)
29
- service.expects(:generate_request_uri).with("mock-container", {:restype => 'container', :comp => 'metadata'}).returns("mock-uri")
30
- service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => '2009-09-19', :x_ms_meta_Name => "myName"}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
31
- properties = service.set_container_properties('mock-container', {:x_ms_meta_Name => "myName"})
32
- end
33
-
34
- it "should get container acl" do
35
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
36
- mock_response = mock()
37
- mock_response.stubs(:headers).returns(RestClient::AbstractResponse.beautify_headers({:x_ms_blob_public_access.to_s => [true]}))
38
- RestClient::Request.any_instance.expects(:execute).returns(mock_response)
39
- service.expects(:generate_request_uri).with("mock-container", {:restype => 'container', :comp => 'acl'}).returns("mock-uri")
40
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
41
- service.get_container_acl('mock-container').should == true
42
- end
43
-
44
- it "should set container acl" do
45
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
46
- RestClient::Request.any_instance.expects(:execute)
47
- service.expects(:generate_request_uri).with("mock-container", :restype => 'container', :comp => 'acl').returns("mock-uri")
48
- service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => '2009-09-19', :x_ms_blob_public_access => false}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
49
- properties = service.set_container_acl('mock-container', false)
50
- end
51
-
52
- it "should list containers" do
53
- response = <<-eos
54
- <?xml version="1.0" encoding="utf-8"?>
55
- <EnumerationResults AccountName="http://myaccount.blob.core.windows.net">
56
- <Containers>
57
- <Container>
58
- <Name>mycontainer</Name>
59
- <Url>http://localhost/mycontainer</Url>
60
- <LastModified>2009-09-11</LastModified>
61
- </Container>
62
- <Container>
63
- <Name>othercontainer</Name>
64
- <Url>http://localhost/othercontainer</Url>
65
- <LastModified>2009-09-11</LastModified>
66
- </Container>
67
- </Containers>
68
- </EnumerationResults>
69
- eos
70
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
71
- RestClient::Request.any_instance.expects(:execute).returns(response)
72
- service.expects(:generate_request_uri).with(nil, {:comp => 'list'}).returns("mock-uri")
73
- service.expects(:generate_request).with(:get, "mock-uri", {}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
74
- containers = service.list_containers
75
- containers[0][:name].should == "mycontainer"
76
- containers[1][:name].should == "othercontainer"
77
- end
78
-
79
- it "should delete container" do
80
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
81
- RestClient::Request.any_instance.expects(:execute)
82
- service.expects(:generate_request_uri).with("mock-container", {:restype => 'container'}).returns("mock-uri")
83
- service.expects(:generate_request).with(:delete, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
84
- service.delete_container('mock-container')
85
- end
86
-
87
- it "should list blobs" do
88
- response = <<-eos
89
- <?xml version="1.0" encoding="utf-8"?>
90
- <EnumerationResults AccountName="http://myaccount.blob.core.windows.net">
91
- <Blobs>
92
- <Blob>
93
- <Url>http://localhost/container/blob</Url>
94
- <Name>blob</Name>
95
- <Properties>
96
- <Content-Type>text/xml</Content-Type>
97
- </Properties>
98
- <Metadata>
99
- <Name>value</Name>
100
- </Metadata>
101
- </Blob>
102
- <Blob>
103
- <Url>http://localhost/container/blob2</Url>
104
- <Name>blob2</Name>
105
- <Properties>
106
- <Content-Type>application/x-stream</Content-Type>
107
- </Properties>
108
- <Metadata>
109
- <Name>value</Name>
110
- </Metadata>
111
- </Blob>
112
- </Blobs>
113
- </EnumerationResults>
114
- eos
115
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
116
- RestClient::Request.any_instance.expects(:execute).returns(response)
117
- service.expects(:generate_request_uri).with("container", {:restype => 'container', :comp => 'list'}).returns("mock-uri")
118
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
119
- blobs = service.list_blobs("container")
120
- blobs[0][:name].should == "blob"
121
- blobs[1][:name].should == "blob2"
122
- blobs[0][:url].should == "http://localhost/container/blob"
123
- blobs[1][:url].should == "http://localhost/container/blob2"
124
- blobs[0][:content_type].should == "text/xml"
125
- blobs[1][:content_type].should == "application/x-stream"
126
- end
127
-
128
- it "should statistics" do
129
- response = <<-eos
130
- <?xml version='1.0' encoding='UTF-8'?>
131
- <EnumerationResults ContainerName='http://myaccount.blob.core.windows.net/hiro-test'>
132
- <Blobs>
133
- <Blob>
134
- <Name>000/000000.txt</Name>
135
- <Url>http://myaccount.blob.core.windows.net/hiro-test/000/000000.txt</Url>
136
- <Properties>
137
- <Last-Modified>Mon, 07 Jan 2013 05:31:13 GMT</Last-Modified>
138
- <Etag>0x8CFBAAF57E5A6C5</Etag>
139
- <Content-Length>1</Content-Length>
140
- <Content-Type>application/octet-stream</Content-Type>
141
- <Content-Encoding/>
142
- <Content-Language/>
143
- <Content-MD5/>
144
- <Cache-Control/>
145
- <BlobType>BlockBlob</BlobType>
146
- <LeaseStatus>unlocked</LeaseStatus>
147
- </Properties>
148
- </Blob>
149
- <Blob>
150
- <Name>000/000001.txt</Name>
151
- <Url>http://myaccount.blob.core.windows.net/hiro-test/000/000001.txt</Url>
152
- <Properties>
153
- <Last-Modified>Mon, 07 Jan 2013 05:31:15 GMT</Last-Modified>
154
- <Etag>0x8CFBAAF58DF9D8B</Etag>
155
- <Content-Length>12</Content-Length>
156
- <Content-Type>application/octet-stream</Content-Type>
157
- <Content-Encoding/>
158
- <Content-Language/>
159
- <Content-MD5/>
160
- <Cache-Control/>
161
- <BlobType>BlockBlob</BlobType>
162
- <LeaseStatus>unlocked</LeaseStatus>
163
- </Properties>
164
- </Blob>
165
- </Blobs>
166
- <NextMarker>test-marker</NextMarker>
167
- </EnumerationResults>
168
- eos
169
- options = {:restype => 'container', :comp => 'list'}
170
- add_options = {:maxresults => 1000}
171
-
172
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
173
- RestClient::Request.any_instance.expects(:execute).returns(response)
174
- service.expects(:generate_request_uri).with("container", options.merge(add_options)).returns("mock-uri")
175
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => '2011-08-18'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
176
- statistics = service.statistics("container", add_options)
177
- statistics[:size].should == 13
178
- statistics[:files].should == 2
179
- statistics[:next_marker].should == 'test-marker'
180
- end
181
-
182
- it "should put blob" do
183
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
184
- RestClient::Request.any_instance.expects(:execute).returns(nil)
185
- service.expects(:generate_request_uri).with("container/blob", nil).returns("mock-uri")
186
- service.expects(:generate_request).with(:put, "mock-uri", {'Content-Type' => 'application/octet-stream', :x_ms_version => "2009-09-19", :x_ms_blob_type => "BlockBlob"}, "payload").returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
187
- service.put_blob("container/blob", "payload")
188
- end
189
-
190
- it "should get blob" do
191
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
192
- RestClient::Request.any_instance.expects(:execute).returns("payload")
193
- service.expects(:generate_request_uri).with("container/blob", {}).returns("mock-uri")
194
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => "2009-09-19"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
195
- service.get_blob("container/blob").should == "payload"
196
- end
197
-
198
- it "should delete blob" do
199
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
200
- RestClient::Request.any_instance.expects(:execute).returns(nil)
201
- service.expects(:generate_request_uri).with("container/blob", nil).returns("mock-uri")
202
- service.expects(:generate_request).with(:delete, "mock-uri", {:x_ms_version => "2009-09-19"}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
203
- service.delete_blob("container/blob")
204
- end
205
-
206
- it "should get blob properties" do
207
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
208
- response = mock()
209
- response.stubs(:headers).returns(RestClient::AbstractResponse.beautify_headers({"x-ms-meta-Name" => ["customName"]}))
210
- RestClient::Request.any_instance.expects(:execute).returns(response)
211
- service.expects(:generate_request_uri).with("container/blob", {}).returns("mock-uri")
212
- service.expects(:generate_request).with(:head, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
213
- service.get_blob_properties("container/blob").should == response.headers
214
- end
215
-
216
- it "should set blob properties" do
217
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
218
- RestClient::Request.any_instance.expects(:execute).returns(nil)
219
- service.expects(:generate_request_uri).with("container/blob", :comp => 'properties').returns("mock-uri")
220
- service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => '2009-09-19', :x_ms_meta_Name => "johnny"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
221
- service.set_blob_properties("container/blob", {:x_ms_meta_Name => "johnny"})
222
- end
223
-
224
- it "should copy blob" do
225
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
226
- RestClient::Request.any_instance.expects(:execute).returns(nil)
227
- service.expects(:generate_request_uri).with("container/blob-copy", nil).returns("mock-uri")
228
- service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => "2009-09-19", :x_ms_copy_source => "/mock-account/container/blob"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
229
- service.copy_blob("container/blob", "container/blob-copy")
230
- end
231
-
232
- it "should put block" do
233
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
234
- RestClient::Request.any_instance.expects(:execute).returns(nil)
235
- service.expects(:generate_request_uri).with("container/blob", { :blockid => 'block_id', :comp => 'block'}).returns("mock-uri")
236
- service.expects(:generate_request).with(:put, "mock-uri", {'Content-Type' => 'application/octet-stream'}, "payload").returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
237
- service.put_block("container/blob", "block_id", "payload")
238
- end
239
-
240
- it "should put block list" do
241
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
242
- RestClient::Request.any_instance.expects(:execute).returns(nil)
243
- service.expects(:generate_request_uri).with("container/blob", { :comp => 'blocklist'}).returns("mock-uri")
244
- service.expects(:generate_request).with(:put, "mock-uri", {'Content-Type' => 'text/plain', :x_ms_version => '2009-09-19'}, '<?xml version="1.0" encoding="utf-8"?><BlockList><Latest>AAAAAA==</Latest><Latest>AQAAAA==</Latest></BlockList>').returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
245
- service.put_block_list("container/blob", ["AAAAAA==", "AQAAAA=="], "text/plain")
246
- end
247
-
248
- it "should list blocks" do
249
- response = <<-eos
250
- <?xml version="1.0" encoding="utf-8"?>
251
- <BlockList>
252
- <CommittedBlocks>
253
- <Block>
254
- <Name>AAAAAA==</Name>
255
- <Size>1048576</Size>
256
- </Block>
257
- </CommittedBlocks>
258
- <UncommittedBlocks>
259
- <Block>
260
- <Name>AQAAAA==</Name>
261
- <Size>1048576</Size>
262
- </Block>
263
- <Block>
264
- <Name>AgAAAA==</Name>
265
- <Size>402848</Size>
266
- </Block>
267
- </UncommittedBlocks>
268
- </BlockList>
269
- eos
270
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
271
- RestClient::Request.any_instance.expects(:execute).returns(response)
272
- service.expects(:generate_request_uri).with('container/blob', {:comp => 'blocklist', :blocklisttype => 'all'}).returns("mock-uri")
273
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => "2009-04-14"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
274
- blocks = service.list_blocks('container/blob')
275
- blocks.first[:name].should == "AAAAAA=="
276
- blocks.first[:size].should == "1048576"
277
- blocks.first[:committed].should == true
278
- blocks.last[:name].should == "AgAAAA=="
279
- blocks.last[:size].should == "402848"
280
- blocks.last[:committed].should == false
281
- end
282
-
283
- it "should list with additional parameters" do
284
- response = <<-eos
285
- <?xml version="1.0" encoding="utf-8"?>
286
- <BlockList>
287
- <CommittedBlocks>
288
- <Block>
289
- <Name>AAAAAA==</Name>
290
- <Size>1048576</Size>
291
- </Block>
292
- </CommittedBlocks>
293
- <UncommittedBlocks>
294
- <Block>
295
- <Name>AQAAAA==</Name>
296
- <Size>1048576</Size>
297
- </Block>
298
- <Block>
299
- <Name>AgAAAA==</Name>
300
- <Size>402848</Size>
301
- </Block>
302
- </UncommittedBlocks>
303
- </BlockList>
304
- eos
305
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
306
- RestClient::Request.any_instance.expects(:execute).returns(response)
307
- service.expects(:generate_request_uri).with('container/blob', {:comp => 'blocklist', :blocklisttype => 'committed'}).returns("mock-uri")
308
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => "2009-04-14"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
309
- blocks = service.list_blocks('container/blob', 'COMMITTED')
310
- blocks.first[:name].should == "AAAAAA=="
311
- blocks.first[:size].should == "1048576"
312
- blocks.first[:committed].should == true
313
- blocks.last[:name].should == "AgAAAA=="
314
- blocks.last[:size].should == "402848"
315
- blocks.last[:committed].should == false
316
- end
317
-
318
- it "should throw when block list type is nil or doesn't fall into the valid values" do
319
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
320
- lambda { service.list_blocks('container/blob', 'whatever') }.should raise_error(WAZ::Storage::InvalidParameterValue)
321
- lambda { service.list_blocks('container/blob', nil) }.should raise_error(WAZ::Storage::InvalidParameterValue)
322
- end
323
-
324
- it "should take blob snapshots" do
325
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
326
-
327
- mock_response = mock()
328
- mock_response.stubs(:headers).returns({:x_ms_snapshot => Time.new.httpdate})
329
- mock_request = mock()
330
- mock_request.stubs(:execute).returns(mock_response)
331
-
332
- service.expects(:generate_request_uri).with("container/blob", {:comp => "snapshot"}).returns("container/blob")
333
- service.expects(:generate_request).with(:put, "container/blob", {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
334
- service.snapshot_blob("container/blob").should == mock_response.headers[:x_ms_snapshot]
335
- end
336
- end
1
+ # enabling the load of files from root (on RSpec)
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../')
3
+ require 'spec/configuration'
4
+ require 'lib/waz-blobs'
5
+
6
+ describe "blobs service behavior" do
7
+ it "should create container" do
8
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
9
+ RestClient::Request.any_instance.expects(:execute)
10
+ service.expects(:generate_request_uri).with("mock-container", {:restype => 'container'}).returns("mock-uri")
11
+ service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
12
+ service.create_container('mock-container')
13
+ end
14
+
15
+ it "should get container properties" do
16
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
17
+ mock_response = mock()
18
+ mock_response.stubs(:headers).returns(RestClient::AbstractResponse.beautify_headers({"x-ms-meta-Name" => ["customName"]}))
19
+ RestClient::Request.any_instance.expects(:execute).returns(mock_response)
20
+ service.expects(:generate_request_uri).with("mock-container", {:restype => 'container'}).returns("mock-uri")
21
+ service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
22
+ properties = service.get_container_properties('mock-container')
23
+ properties[:x_ms_meta_name].should == "customName"
24
+ end
25
+
26
+ it "should set container properties" do
27
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
28
+ RestClient::Request.any_instance.expects(:execute)
29
+ service.expects(:generate_request_uri).with("mock-container", {:restype => 'container', :comp => 'metadata'}).returns("mock-uri")
30
+ service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => '2009-09-19', :x_ms_meta_Name => "myName"}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
31
+ properties = service.set_container_properties('mock-container', {:x_ms_meta_Name => "myName"})
32
+ end
33
+
34
+ it "should get container acl" do
35
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
36
+ mock_response = mock()
37
+ mock_response.stubs(:headers).returns(RestClient::AbstractResponse.beautify_headers({:x_ms_blob_public_access.to_s => [true]}))
38
+ RestClient::Request.any_instance.expects(:execute).returns(mock_response)
39
+ service.expects(:generate_request_uri).with("mock-container", {:restype => 'container', :comp => 'acl'}).returns("mock-uri")
40
+ service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
41
+ service.get_container_acl('mock-container').should == true
42
+ end
43
+
44
+ it "should set container acl" do
45
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
46
+ RestClient::Request.any_instance.expects(:execute)
47
+ service.expects(:generate_request_uri).with("mock-container", :restype => 'container', :comp => 'acl').returns("mock-uri")
48
+ service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => '2009-09-19', :x_ms_blob_public_access => false}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
49
+ properties = service.set_container_acl('mock-container', false)
50
+ end
51
+
52
+ it "should list containers" do
53
+ response = <<-eos
54
+ <?xml version="1.0" encoding="utf-8"?>
55
+ <EnumerationResults AccountName="http://myaccount.blob.core.windows.net">
56
+ <Containers>
57
+ <Container>
58
+ <Name>mycontainer</Name>
59
+ <Url>http://localhost/mycontainer</Url>
60
+ <LastModified>2009-09-11</LastModified>
61
+ </Container>
62
+ <Container>
63
+ <Name>othercontainer</Name>
64
+ <Url>http://localhost/othercontainer</Url>
65
+ <LastModified>2009-09-11</LastModified>
66
+ </Container>
67
+ </Containers>
68
+ </EnumerationResults>
69
+ eos
70
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
71
+ RestClient::Request.any_instance.expects(:execute).returns(response)
72
+ service.expects(:generate_request_uri).with(nil, {:comp => 'list'}).returns("mock-uri")
73
+ service.expects(:generate_request).with(:get, "mock-uri", {}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
74
+ containers = service.list_containers
75
+ containers[0][:name].should == "mycontainer"
76
+ containers[1][:name].should == "othercontainer"
77
+ end
78
+
79
+ it "should delete container" do
80
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
81
+ RestClient::Request.any_instance.expects(:execute)
82
+ service.expects(:generate_request_uri).with("mock-container", {:restype => 'container'}).returns("mock-uri")
83
+ service.expects(:generate_request).with(:delete, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
84
+ service.delete_container('mock-container')
85
+ end
86
+
87
+ it "should list blobs" do
88
+ response = <<-eos
89
+ <?xml version="1.0" encoding="utf-8"?>
90
+ <EnumerationResults AccountName="http://myaccount.blob.core.windows.net">
91
+ <Blobs>
92
+ <Blob>
93
+ <Url>http://localhost/container/blob</Url>
94
+ <Name>blob</Name>
95
+ <Properties>
96
+ <Content-Type>text/xml</Content-Type>
97
+ </Properties>
98
+ <Metadata>
99
+ <Name>value</Name>
100
+ </Metadata>
101
+ </Blob>
102
+ <Blob>
103
+ <Url>http://localhost/container/blob2</Url>
104
+ <Name>blob2</Name>
105
+ <Properties>
106
+ <Content-Type>application/x-stream</Content-Type>
107
+ </Properties>
108
+ <Metadata>
109
+ <Name>value</Name>
110
+ </Metadata>
111
+ </Blob>
112
+ </Blobs>
113
+ </EnumerationResults>
114
+ eos
115
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
116
+ RestClient::Request.any_instance.expects(:execute).returns(response)
117
+ service.expects(:generate_request_uri).with("container", {:restype => 'container', :comp => 'list'}).returns("mock-uri")
118
+ service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
119
+ blobs = service.list_blobs("container")
120
+ blobs[0][:name].should == "blob"
121
+ blobs[1][:name].should == "blob2"
122
+ blobs[0][:url].should == "http://localhost/container/blob"
123
+ blobs[1][:url].should == "http://localhost/container/blob2"
124
+ blobs[0][:content_type].should == "text/xml"
125
+ blobs[1][:content_type].should == "application/x-stream"
126
+ end
127
+
128
+ it "should statistics" do
129
+ response = <<-eos
130
+ <?xml version='1.0' encoding='UTF-8'?>
131
+ <EnumerationResults ContainerName='http://myaccount.blob.core.windows.net/hiro-test'>
132
+ <Blobs>
133
+ <Blob>
134
+ <Name>000/000000.txt</Name>
135
+ <Url>http://myaccount.blob.core.windows.net/hiro-test/000/000000.txt</Url>
136
+ <Properties>
137
+ <Last-Modified>Mon, 07 Jan 2013 05:31:13 GMT</Last-Modified>
138
+ <Etag>0x8CFBAAF57E5A6C5</Etag>
139
+ <Content-Length>1</Content-Length>
140
+ <Content-Type>application/octet-stream</Content-Type>
141
+ <Content-Encoding/>
142
+ <Content-Language/>
143
+ <Content-MD5/>
144
+ <Cache-Control/>
145
+ <BlobType>BlockBlob</BlobType>
146
+ <LeaseStatus>unlocked</LeaseStatus>
147
+ </Properties>
148
+ </Blob>
149
+ <Blob>
150
+ <Name>000/000001.txt</Name>
151
+ <Url>http://myaccount.blob.core.windows.net/hiro-test/000/000001.txt</Url>
152
+ <Properties>
153
+ <Last-Modified>Mon, 07 Jan 2013 05:31:15 GMT</Last-Modified>
154
+ <Etag>0x8CFBAAF58DF9D8B</Etag>
155
+ <Content-Length>12</Content-Length>
156
+ <Content-Type>application/octet-stream</Content-Type>
157
+ <Content-Encoding/>
158
+ <Content-Language/>
159
+ <Content-MD5/>
160
+ <Cache-Control/>
161
+ <BlobType>BlockBlob</BlobType>
162
+ <LeaseStatus>unlocked</LeaseStatus>
163
+ </Properties>
164
+ </Blob>
165
+ </Blobs>
166
+ <NextMarker>test-marker</NextMarker>
167
+ </EnumerationResults>
168
+ eos
169
+ options = {:restype => 'container', :comp => 'list'}
170
+ add_options = {:maxresults => 1000}
171
+
172
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
173
+ RestClient::Request.any_instance.expects(:execute).returns(response)
174
+ service.expects(:generate_request_uri).with("container", options.merge(add_options)).returns("mock-uri")
175
+ service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => '2011-08-18'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
176
+ statistics = service.statistics("container", add_options)
177
+ statistics[:size].should == 13
178
+ statistics[:files].should == 2
179
+ statistics[:next_marker].should == 'test-marker'
180
+ end
181
+
182
+ it "should put blob" do
183
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
184
+ RestClient::Request.any_instance.expects(:execute).returns(nil)
185
+ service.expects(:generate_request_uri).with("container/blob", nil).returns("mock-uri")
186
+ service.expects(:generate_request).with(:put, "mock-uri", {'Content-Type' => 'application/octet-stream', :x_ms_version => "2009-09-19", :x_ms_blob_type => "BlockBlob"}, "payload").returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
187
+ service.put_blob("container/blob", "payload")
188
+ end
189
+
190
+ it "should get blob" do
191
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
192
+ RestClient::Request.any_instance.expects(:execute).returns("payload")
193
+ service.expects(:generate_request_uri).with("container/blob", {}).returns("mock-uri")
194
+ service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => "2009-09-19"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
195
+ service.get_blob("container/blob").should == "payload"
196
+ end
197
+
198
+ it "should delete blob" do
199
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
200
+ RestClient::Request.any_instance.expects(:execute).returns(nil)
201
+ service.expects(:generate_request_uri).with("container/blob", nil).returns("mock-uri")
202
+ service.expects(:generate_request).with(:delete, "mock-uri", {:x_ms_version => "2009-09-19"}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
203
+ service.delete_blob("container/blob")
204
+ end
205
+
206
+ it "should get blob properties" do
207
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
208
+ response = mock()
209
+ response.stubs(:headers).returns(RestClient::AbstractResponse.beautify_headers({"x-ms-meta-Name" => ["customName"]}))
210
+ RestClient::Request.any_instance.expects(:execute).returns(response)
211
+ service.expects(:generate_request_uri).with("container/blob", {}).returns("mock-uri")
212
+ service.expects(:generate_request).with(:head, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
213
+ service.get_blob_properties("container/blob").should == response.headers
214
+ end
215
+
216
+ it "should set blob properties" do
217
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
218
+ RestClient::Request.any_instance.expects(:execute).returns(nil)
219
+ service.expects(:generate_request_uri).with("container/blob", :comp => 'properties').returns("mock-uri")
220
+ service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => '2009-09-19', :x_ms_meta_Name => "johnny"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
221
+ service.set_blob_properties("container/blob", {:x_ms_meta_Name => "johnny"})
222
+ end
223
+
224
+ it "should copy blob" do
225
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
226
+ RestClient::Request.any_instance.expects(:execute).returns(nil)
227
+ service.expects(:generate_request_uri).with("container/blob-copy", nil).returns("mock-uri")
228
+ service.expects(:generate_request).with(:put, "mock-uri", {:x_ms_version => "2009-09-19", :x_ms_copy_source => "/mock-account/container/blob"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
229
+ service.copy_blob("container/blob", "container/blob-copy")
230
+ end
231
+
232
+ it "should put block" do
233
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
234
+ RestClient::Request.any_instance.expects(:execute).returns(nil)
235
+ service.expects(:generate_request_uri).with("container/blob", { :blockid => 'block_id', :comp => 'block'}).returns("mock-uri")
236
+ service.expects(:generate_request).with(:put, "mock-uri", {'Content-Type' => 'application/octet-stream'}, "payload").returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
237
+ service.put_block("container/blob", "block_id", "payload")
238
+ end
239
+
240
+ it "should put block list" do
241
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
242
+ RestClient::Request.any_instance.expects(:execute).returns(nil)
243
+ service.expects(:generate_request_uri).with("container/blob", { :comp => 'blocklist'}).returns("mock-uri")
244
+ service.expects(:generate_request).with(:put, "mock-uri", {'Content-Type' => 'text/plain', :x_ms_version => '2009-09-19'}, '<?xml version="1.0" encoding="utf-8"?><BlockList><Latest>AAAAAA==</Latest><Latest>AQAAAA==</Latest></BlockList>').returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
245
+ service.put_block_list("container/blob", ["AAAAAA==", "AQAAAA=="], "text/plain")
246
+ end
247
+
248
+ it "should list blocks" do
249
+ response = <<-eos
250
+ <?xml version="1.0" encoding="utf-8"?>
251
+ <BlockList>
252
+ <CommittedBlocks>
253
+ <Block>
254
+ <Name>AAAAAA==</Name>
255
+ <Size>1048576</Size>
256
+ </Block>
257
+ </CommittedBlocks>
258
+ <UncommittedBlocks>
259
+ <Block>
260
+ <Name>AQAAAA==</Name>
261
+ <Size>1048576</Size>
262
+ </Block>
263
+ <Block>
264
+ <Name>AgAAAA==</Name>
265
+ <Size>402848</Size>
266
+ </Block>
267
+ </UncommittedBlocks>
268
+ </BlockList>
269
+ eos
270
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
271
+ RestClient::Request.any_instance.expects(:execute).returns(response)
272
+ service.expects(:generate_request_uri).with('container/blob', {:comp => 'blocklist', :blocklisttype => 'all'}).returns("mock-uri")
273
+ service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => "2009-04-14"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
274
+ blocks = service.list_blocks('container/blob')
275
+ blocks.first[:name].should == "AAAAAA=="
276
+ blocks.first[:size].should == "1048576"
277
+ blocks.first[:committed].should == true
278
+ blocks.last[:name].should == "AgAAAA=="
279
+ blocks.last[:size].should == "402848"
280
+ blocks.last[:committed].should == false
281
+ end
282
+
283
+ it "should list with additional parameters" do
284
+ response = <<-eos
285
+ <?xml version="1.0" encoding="utf-8"?>
286
+ <BlockList>
287
+ <CommittedBlocks>
288
+ <Block>
289
+ <Name>AAAAAA==</Name>
290
+ <Size>1048576</Size>
291
+ </Block>
292
+ </CommittedBlocks>
293
+ <UncommittedBlocks>
294
+ <Block>
295
+ <Name>AQAAAA==</Name>
296
+ <Size>1048576</Size>
297
+ </Block>
298
+ <Block>
299
+ <Name>AgAAAA==</Name>
300
+ <Size>402848</Size>
301
+ </Block>
302
+ </UncommittedBlocks>
303
+ </BlockList>
304
+ eos
305
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
306
+ RestClient::Request.any_instance.expects(:execute).returns(response)
307
+ service.expects(:generate_request_uri).with('container/blob', {:comp => 'blocklist', :blocklisttype => 'committed'}).returns("mock-uri")
308
+ service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => "2009-04-14"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
309
+ blocks = service.list_blocks('container/blob', 'COMMITTED')
310
+ blocks.first[:name].should == "AAAAAA=="
311
+ blocks.first[:size].should == "1048576"
312
+ blocks.first[:committed].should == true
313
+ blocks.last[:name].should == "AgAAAA=="
314
+ blocks.last[:size].should == "402848"
315
+ blocks.last[:committed].should == false
316
+ end
317
+
318
+ it "should throw when block list type is nil or doesn't fall into the valid values" do
319
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
320
+ lambda { service.list_blocks('container/blob', 'whatever') }.should raise_error(WAZ::Storage::InvalidParameterValue)
321
+ lambda { service.list_blocks('container/blob', nil) }.should raise_error(WAZ::Storage::InvalidParameterValue)
322
+ end
323
+
324
+ it "should take blob snapshots" do
325
+ service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
326
+
327
+ mock_response = mock()
328
+ mock_response.stubs(:headers).returns({:x_ms_snapshot => Time.new.httpdate})
329
+ mock_request = mock()
330
+ mock_request.stubs(:execute).returns(mock_response)
331
+
332
+ service.expects(:generate_request_uri).with("container/blob", {:comp => "snapshot"}).returns("container/blob")
333
+ service.expects(:generate_request).with(:put, "container/blob", {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
334
+ service.snapshot_blob("container/blob").should == mock_response.headers[:x_ms_snapshot]
335
+ end
336
+ end