waz-storage 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitignore +9 -9
  2. data/CHANGELOG.rdoc +72 -72
  3. data/Gemfile +4 -4
  4. data/Gemfile.lock +46 -40
  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 -161
  13. data/lib/waz/blobs/exceptions.rb +10 -10
  14. data/lib/waz/blobs/service.rb +181 -156
  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/exceptions.rb +33 -33
  21. data/lib/waz/storage/validation_rules.rb +25 -25
  22. data/lib/waz/tables/edm_type_helper.rb +44 -44
  23. data/lib/waz/tables/exceptions.rb +44 -44
  24. data/lib/waz/tables/service.rb +178 -178
  25. data/lib/waz/tables/table.rb +74 -74
  26. data/lib/waz/tables/table_array.rb +10 -10
  27. data/rakefile +8 -21
  28. data/{tests → spec}/configuration.rb +22 -22
  29. data/{tests/waz/blobs/blob_object_test.rb → spec/waz/blobs/blob_object_spec.rb} +80 -80
  30. data/{tests/waz/blobs/container_test.rb → spec/waz/blobs/container_spec.rb} +175 -162
  31. data/{tests/waz/blobs/service_test.rb → spec/waz/blobs/service_spec.rb} +336 -282
  32. data/{tests/waz/queues/message_test.rb → spec/waz/queues/message_spec.rb} +32 -32
  33. data/{tests/waz/queues/queue_test.rb → spec/waz/queues/queue_spec.rb} +205 -205
  34. data/{tests/waz/queues/service_test.rb → spec/waz/queues/service_spec.rb} +298 -298
  35. data/{tests → spec}/waz/storage/base_tests.rb +81 -81
  36. data/{tests/waz/storage/shared_key_core_service_test.rb → spec/waz/storage/shared_key_core_service_spec.rb} +141 -141
  37. data/{tests/waz/tables/service_test.rb → spec/waz/tables/service_spec.rb} +613 -613
  38. data/{tests/waz/tables/table_test.rb → spec/waz/tables/table_spec.rb} +97 -97
  39. data/waz-storage.gemspec +29 -27
  40. metadata +47 -26
@@ -1,282 +1,336 @@
1
- # enabling the load of files from root (on RSpec)
2
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../')
3
- require 'tests/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 put blob" do
129
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
130
- RestClient::Request.any_instance.expects(:execute).returns(nil)
131
- service.expects(:generate_request_uri).with("container/blob", nil).returns("mock-uri")
132
- 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"))
133
- service.put_blob("container/blob", "payload")
134
- end
135
-
136
- it "should get blob" do
137
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
138
- RestClient::Request.any_instance.expects(:execute).returns("payload")
139
- service.expects(:generate_request_uri).with("container/blob", {}).returns("mock-uri")
140
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => "2009-09-19"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
141
- service.get_blob("container/blob").should == "payload"
142
- end
143
-
144
- it "should delete blob" do
145
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
146
- RestClient::Request.any_instance.expects(:execute).returns(nil)
147
- service.expects(:generate_request_uri).with("container/blob", nil).returns("mock-uri")
148
- service.expects(:generate_request).with(:delete, "mock-uri", {:x_ms_version => "2009-09-19"}, nil).returns(RestClient::Request.new(:method => :put, :url => "http://localhost"))
149
- service.delete_blob("container/blob")
150
- end
151
-
152
- it "should get blob properties" do
153
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
154
- response = mock()
155
- response.stubs(:headers).returns(RestClient::AbstractResponse.beautify_headers({"x-ms-meta-Name" => ["customName"]}))
156
- RestClient::Request.any_instance.expects(:execute).returns(response)
157
- service.expects(:generate_request_uri).with("container/blob", {}).returns("mock-uri")
158
- service.expects(:generate_request).with(:head, "mock-uri", {:x_ms_version => '2009-09-19'}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
159
- service.get_blob_properties("container/blob").should == response.headers
160
- end
161
-
162
- it "should set blob properties" do
163
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
164
- RestClient::Request.any_instance.expects(:execute).returns(nil)
165
- service.expects(:generate_request_uri).with("container/blob", :comp => 'properties').returns("mock-uri")
166
- 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"))
167
- service.set_blob_properties("container/blob", {:x_ms_meta_Name => "johnny"})
168
- end
169
-
170
- it "should copy blob" do
171
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
172
- RestClient::Request.any_instance.expects(:execute).returns(nil)
173
- service.expects(:generate_request_uri).with("container/blob-copy", nil).returns("mock-uri")
174
- 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"))
175
- service.copy_blob("container/blob", "container/blob-copy")
176
- end
177
-
178
- it "should put block" do
179
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
180
- RestClient::Request.any_instance.expects(:execute).returns(nil)
181
- service.expects(:generate_request_uri).with("container/blob", { :blockid => 'block_id', :comp => 'block'}).returns("mock-uri")
182
- service.expects(:generate_request).with(:put, "mock-uri", {'Content-Type' => 'application/octet-stream'}, "payload").returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
183
- service.put_block("container/blob", "block_id", "payload")
184
- end
185
-
186
- it "should put block list" do
187
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
188
- RestClient::Request.any_instance.expects(:execute).returns(nil)
189
- service.expects(:generate_request_uri).with("container/blob", { :comp => 'blocklist'}).returns("mock-uri")
190
- 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"))
191
- service.put_block_list("container/blob", ["AAAAAA==", "AQAAAA=="], "text/plain")
192
- end
193
-
194
- it "should list blocks" do
195
- response = <<-eos
196
- <?xml version="1.0" encoding="utf-8"?>
197
- <BlockList>
198
- <CommittedBlocks>
199
- <Block>
200
- <Name>AAAAAA==</Name>
201
- <Size>1048576</Size>
202
- </Block>
203
- </CommittedBlocks>
204
- <UncommittedBlocks>
205
- <Block>
206
- <Name>AQAAAA==</Name>
207
- <Size>1048576</Size>
208
- </Block>
209
- <Block>
210
- <Name>AgAAAA==</Name>
211
- <Size>402848</Size>
212
- </Block>
213
- </UncommittedBlocks>
214
- </BlockList>
215
- eos
216
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
217
- RestClient::Request.any_instance.expects(:execute).returns(response)
218
- service.expects(:generate_request_uri).with('container/blob', {:comp => 'blocklist', :blocklisttype => 'all'}).returns("mock-uri")
219
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => "2009-04-14"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
220
- blocks = service.list_blocks('container/blob')
221
- blocks.first[:name].should == "AAAAAA=="
222
- blocks.first[:size].should == "1048576"
223
- blocks.first[:committed].should == true
224
- blocks.last[:name].should == "AgAAAA=="
225
- blocks.last[:size].should == "402848"
226
- blocks.last[:committed].should == false
227
- end
228
-
229
- it "should list with additional parameters" do
230
- response = <<-eos
231
- <?xml version="1.0" encoding="utf-8"?>
232
- <BlockList>
233
- <CommittedBlocks>
234
- <Block>
235
- <Name>AAAAAA==</Name>
236
- <Size>1048576</Size>
237
- </Block>
238
- </CommittedBlocks>
239
- <UncommittedBlocks>
240
- <Block>
241
- <Name>AQAAAA==</Name>
242
- <Size>1048576</Size>
243
- </Block>
244
- <Block>
245
- <Name>AgAAAA==</Name>
246
- <Size>402848</Size>
247
- </Block>
248
- </UncommittedBlocks>
249
- </BlockList>
250
- eos
251
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
252
- RestClient::Request.any_instance.expects(:execute).returns(response)
253
- service.expects(:generate_request_uri).with('container/blob', {:comp => 'blocklist', :blocklisttype => 'committed'}).returns("mock-uri")
254
- service.expects(:generate_request).with(:get, "mock-uri", {:x_ms_version => "2009-04-14"}, nil).returns(RestClient::Request.new(:method => :get, :url => "http://localhost"))
255
- blocks = service.list_blocks('container/blob', 'COMMITTED')
256
- blocks.first[:name].should == "AAAAAA=="
257
- blocks.first[:size].should == "1048576"
258
- blocks.first[:committed].should == true
259
- blocks.last[:name].should == "AgAAAA=="
260
- blocks.last[:size].should == "402848"
261
- blocks.last[:committed].should == false
262
- end
263
-
264
- it "should throw when block list type is nil or doesn't fall into the valid values" do
265
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
266
- lambda { service.list_blocks('container/blob', 'whatever') }.should raise_error(WAZ::Storage::InvalidParameterValue)
267
- lambda { service.list_blocks('container/blob', nil) }.should raise_error(WAZ::Storage::InvalidParameterValue)
268
- end
269
-
270
- it "should take blob snapshots" do
271
- service = WAZ::Blobs::Service.new(:account_name => "mock-account", :access_key => "mock-key", :type_of_service => "queue", :use_ssl => true, :base_url => "localhost")
272
-
273
- mock_response = mock()
274
- mock_response.stubs(:headers).returns({:x_ms_snapshot => Time.new.httpdate})
275
- mock_request = mock()
276
- mock_request.stubs(:execute).returns(mock_response)
277
-
278
- service.expects(:generate_request_uri).with("container/blob", {:comp => "snapshot"}).returns("container/blob")
279
- service.expects(:generate_request).with(:put, "container/blob", {:x_ms_version => "2009-09-19"}, nil).returns(mock_request)
280
- service.snapshot_blob("container/blob").should == mock_response.headers[:x_ms_snapshot]
281
- end
282
- 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