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.
- data/.gitignore +9 -9
- data/CHANGELOG.rdoc +72 -72
- data/Gemfile +4 -4
- data/Gemfile.lock +46 -46
- data/LICENSE +18 -18
- data/README.rdoc +310 -310
- data/lib/waz-blobs.rb +4 -4
- data/lib/waz-queues.rb +6 -6
- data/lib/waz-storage.rb +39 -39
- data/lib/waz-tables.rb +4 -4
- data/lib/waz/blobs/blob_object.rb +122 -122
- data/lib/waz/blobs/container.rb +172 -172
- data/lib/waz/blobs/exceptions.rb +10 -10
- data/lib/waz/blobs/service.rb +181 -181
- data/lib/waz/queues/exceptions.rb +28 -28
- data/lib/waz/queues/message.rb +64 -64
- data/lib/waz/queues/queue.rb +164 -164
- data/lib/waz/queues/service.rb +105 -105
- data/lib/waz/storage/base.rb +70 -70
- data/lib/waz/storage/core_service.rb +2 -1
- data/lib/waz/storage/exceptions.rb +33 -33
- data/lib/waz/storage/validation_rules.rb +25 -25
- data/lib/waz/tables/edm_type_helper.rb +44 -44
- data/lib/waz/tables/exceptions.rb +44 -44
- data/lib/waz/tables/service.rb +178 -178
- data/lib/waz/tables/table.rb +74 -74
- data/lib/waz/tables/table_array.rb +10 -10
- data/rakefile +7 -7
- data/spec/configuration.rb +22 -22
- data/spec/waz/blobs/blob_object_spec.rb +80 -80
- data/spec/waz/blobs/container_spec.rb +175 -175
- data/spec/waz/blobs/service_spec.rb +336 -336
- data/spec/waz/queues/message_spec.rb +32 -32
- data/spec/waz/queues/queue_spec.rb +205 -205
- data/spec/waz/queues/service_spec.rb +298 -298
- data/spec/waz/storage/base_tests.rb +81 -81
- data/spec/waz/storage/shared_key_core_service_spec.rb +141 -141
- data/spec/waz/tables/service_spec.rb +613 -613
- data/spec/waz/tables/table_spec.rb +97 -97
- data/waz-storage.gemspec +29 -29
- metadata +3 -3
@@ -1,11 +1,11 @@
|
|
1
|
-
module WAZ
|
2
|
-
module Tables
|
3
|
-
class TableArray < Array
|
4
|
-
attr_accessor :continuation_token
|
5
|
-
|
6
|
-
def initialize(array)
|
7
|
-
super(array)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module WAZ
|
2
|
+
module Tables
|
3
|
+
class TableArray < Array
|
4
|
+
attr_accessor :continuation_token
|
5
|
+
|
6
|
+
def initialize(array)
|
7
|
+
super(array)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
11
|
end
|
data/rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
require 'rspec/core/rake_task'
|
3
|
-
require 'bundler/gem_tasks'
|
4
|
-
|
5
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
6
|
-
t.pattern = "spec/**/*_spec.rb"
|
7
|
-
t.rspec_opts = ['-cfn']
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
6
|
+
t.pattern = "spec/**/*_spec.rb"
|
7
|
+
t.rspec_opts = ['-cfn']
|
8
8
|
end
|
data/spec/configuration.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
SimpleCov.start do
|
3
|
-
add_group "Gem files" do |src_file|
|
4
|
-
lib_path = File.expand_path("../lib", File.dirname(__FILE__))
|
5
|
-
src_file.filename.start_with?(lib_path)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'rubygems'
|
10
|
-
require 'rspec'
|
11
|
-
require 'rspec/autorun'
|
12
|
-
require 'mocha'
|
13
|
-
require 'restclient'
|
14
|
-
require 'time'
|
15
|
-
require 'hmac-sha2'
|
16
|
-
require 'base64'
|
17
|
-
require 'rexml/document'
|
18
|
-
require 'rexml/xpath'
|
19
|
-
|
20
|
-
RSpec.configure do |config|
|
21
|
-
config.mock_with :mocha
|
22
|
-
end
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_group "Gem files" do |src_file|
|
4
|
+
lib_path = File.expand_path("../lib", File.dirname(__FILE__))
|
5
|
+
src_file.filename.start_with?(lib_path)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'rspec'
|
11
|
+
require 'rspec/autorun'
|
12
|
+
require 'mocha'
|
13
|
+
require 'restclient'
|
14
|
+
require 'time'
|
15
|
+
require 'hmac-sha2'
|
16
|
+
require 'base64'
|
17
|
+
require 'rexml/document'
|
18
|
+
require 'rexml/xpath'
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.mock_with :mocha
|
22
|
+
end
|
@@ -1,80 +1,80 @@
|
|
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 "Windows Azure Blobs interface API" do
|
7
|
-
it "should return blob path from url" do
|
8
|
-
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
9
|
-
blob.path.should == "container/blob"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return blob metdata" do
|
13
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
14
|
-
WAZ::Blobs::Service.any_instance.expects(:get_blob_properties).with("container/blob").returns({:x_ms_meta_name => "blob_name"})
|
15
|
-
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
16
|
-
blob.metadata.should == { :x_ms_meta_name => "blob_name" }
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should put blob metadataa" do
|
20
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
21
|
-
WAZ::Blobs::Service.any_instance.expects(:set_blob_properties).with("container/blob", {:x_ms_meta_name => "blob_name"})
|
22
|
-
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
23
|
-
blob.put_properties!({ :x_ms_meta_name => "blob_name" })
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should get blob contents" do
|
27
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
28
|
-
WAZ::Blobs::Service.any_instance.expects(:get_blob).with("container/blob").returns("this is the blob content")
|
29
|
-
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
30
|
-
blob.value.should == "this is the blob content"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should put blob contents" do
|
34
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
35
|
-
WAZ::Blobs::Service.any_instance.expects(:get_blob_properties).with("container/blob").returns({})
|
36
|
-
WAZ::Blobs::Service.any_instance.expects(:put_blob).with("container/blob", "my new blob value", "application/xml", {}).returns("this is the blob content")
|
37
|
-
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
38
|
-
blob.value = "my new blob value"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should destroy blob" do
|
42
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
43
|
-
WAZ::Blobs::Service.any_instance.expects(:delete_blob).with("container/blob")
|
44
|
-
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
45
|
-
blob.destroy!
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should copy blob" do
|
49
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
50
|
-
WAZ::Blobs::BlobObject.service_instance.expects(:copy_blob).with('container/blob', 'container/blob-copy')
|
51
|
-
WAZ::Blobs::BlobObject.service_instance.expects(:get_blob_properties).with('container/blob-copy').returns(:content_type => "plain/text")
|
52
|
-
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "plain/text")
|
53
|
-
copy = blob.copy('container/blob-copy')
|
54
|
-
copy.path.should == "container/blob-copy"
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should take a snapshot of a blob" do
|
58
|
-
mock_time = Time.new
|
59
|
-
Time.stubs(:new).returns(mock_time)
|
60
|
-
|
61
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
62
|
-
WAZ::Blobs::BlobObject.service_instance.expects(:get_blob_properties).with('container/blob').returns(:content_type => "plain/text")
|
63
|
-
WAZ::Blobs::BlobObject.service_instance.expects(:snapshot_blob).with('container/blob').returns(mock_time.httpdate)
|
64
|
-
|
65
|
-
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "plain/text")
|
66
|
-
blob_snapshot = blob.snapshot
|
67
|
-
blob_snapshot.snapshot_date.should === mock_time.httpdate
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should not allow snapshoted blobs to perform write operations" do
|
71
|
-
snapshot = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "plain/text", :snapshot_date => Time.new.httpdate)
|
72
|
-
lambda { snapshot.value = "new-value" }.should raise_error(WAZ::Blobs::InvalidOperation)
|
73
|
-
lambda { snapshot.put_properties!({:x_ms_meta_name => "foo"}) }.should raise_error(WAZ::Blobs::InvalidOperation)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "blob path should include snapshot parameter" do
|
77
|
-
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob?snapshot=foo", :content_type => "application/xml")
|
78
|
-
blob.path.should == "container/blob?snapshot=foo"
|
79
|
-
end
|
80
|
-
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 "Windows Azure Blobs interface API" do
|
7
|
+
it "should return blob path from url" do
|
8
|
+
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
9
|
+
blob.path.should == "container/blob"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return blob metdata" do
|
13
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
14
|
+
WAZ::Blobs::Service.any_instance.expects(:get_blob_properties).with("container/blob").returns({:x_ms_meta_name => "blob_name"})
|
15
|
+
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
16
|
+
blob.metadata.should == { :x_ms_meta_name => "blob_name" }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should put blob metadataa" do
|
20
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
21
|
+
WAZ::Blobs::Service.any_instance.expects(:set_blob_properties).with("container/blob", {:x_ms_meta_name => "blob_name"})
|
22
|
+
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
23
|
+
blob.put_properties!({ :x_ms_meta_name => "blob_name" })
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get blob contents" do
|
27
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
28
|
+
WAZ::Blobs::Service.any_instance.expects(:get_blob).with("container/blob").returns("this is the blob content")
|
29
|
+
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
30
|
+
blob.value.should == "this is the blob content"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should put blob contents" do
|
34
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
35
|
+
WAZ::Blobs::Service.any_instance.expects(:get_blob_properties).with("container/blob").returns({})
|
36
|
+
WAZ::Blobs::Service.any_instance.expects(:put_blob).with("container/blob", "my new blob value", "application/xml", {}).returns("this is the blob content")
|
37
|
+
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
38
|
+
blob.value = "my new blob value"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should destroy blob" do
|
42
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
43
|
+
WAZ::Blobs::Service.any_instance.expects(:delete_blob).with("container/blob")
|
44
|
+
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "application/xml")
|
45
|
+
blob.destroy!
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should copy blob" do
|
49
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
50
|
+
WAZ::Blobs::BlobObject.service_instance.expects(:copy_blob).with('container/blob', 'container/blob-copy')
|
51
|
+
WAZ::Blobs::BlobObject.service_instance.expects(:get_blob_properties).with('container/blob-copy').returns(:content_type => "plain/text")
|
52
|
+
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "plain/text")
|
53
|
+
copy = blob.copy('container/blob-copy')
|
54
|
+
copy.path.should == "container/blob-copy"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should take a snapshot of a blob" do
|
58
|
+
mock_time = Time.new
|
59
|
+
Time.stubs(:new).returns(mock_time)
|
60
|
+
|
61
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
62
|
+
WAZ::Blobs::BlobObject.service_instance.expects(:get_blob_properties).with('container/blob').returns(:content_type => "plain/text")
|
63
|
+
WAZ::Blobs::BlobObject.service_instance.expects(:snapshot_blob).with('container/blob').returns(mock_time.httpdate)
|
64
|
+
|
65
|
+
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "plain/text")
|
66
|
+
blob_snapshot = blob.snapshot
|
67
|
+
blob_snapshot.snapshot_date.should === mock_time.httpdate
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not allow snapshoted blobs to perform write operations" do
|
71
|
+
snapshot = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob", :content_type => "plain/text", :snapshot_date => Time.new.httpdate)
|
72
|
+
lambda { snapshot.value = "new-value" }.should raise_error(WAZ::Blobs::InvalidOperation)
|
73
|
+
lambda { snapshot.put_properties!({:x_ms_meta_name => "foo"}) }.should raise_error(WAZ::Blobs::InvalidOperation)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "blob path should include snapshot parameter" do
|
77
|
+
blob = WAZ::Blobs::BlobObject.new(:name => "blob_name", :url => "http://localhost/container/blob?snapshot=foo", :content_type => "application/xml")
|
78
|
+
blob.path.should == "container/blob?snapshot=foo"
|
79
|
+
end
|
80
|
+
end
|
@@ -1,175 +1,175 @@
|
|
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 "Windows Azure Containers interface API" do
|
7
|
-
|
8
|
-
it "should should throw when no container name is provided" do
|
9
|
-
lambda {WAZ::Blobs::Container.new}.should raise_error(WAZ::Storage::InvalidOption)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should list containers" do
|
13
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
14
|
-
WAZ::Blobs::Service.any_instance.expects(:list_containers).returns([{:name => 'my-container'}, {:name => 'other container'}])
|
15
|
-
containers = WAZ::Blobs::Container.list
|
16
|
-
containers.size.should == 2
|
17
|
-
containers.first().name.should == "my-container"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should be able to create a container" do
|
21
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
22
|
-
WAZ::Blobs::Service.any_instance.expects(:create_container).with("my-container")
|
23
|
-
container = WAZ::Blobs::Container.create('my-container')
|
24
|
-
container.name.should == 'my-container'
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should be able to return a container by name" do
|
28
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
29
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:name => "container-name", :x_ms_meta_name => "container-name"}).twice
|
30
|
-
container = WAZ::Blobs::Container.find('container-name')
|
31
|
-
container.metadata[:x_ms_meta_name].should == 'container-name'
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should be able to return container metadata" do
|
35
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
36
|
-
WAZ::Blobs::Service.any_instance.expects(:create_container).with("container-name")
|
37
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
38
|
-
container = WAZ::Blobs::Container.create('container-name')
|
39
|
-
container.metadata[:x_ms_meta_name].should == 'container-name'
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should be able to say whether the container is public or not" do
|
43
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
44
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
45
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_acl).with("container-name").returns(false)
|
46
|
-
container = WAZ::Blobs::Container.find("container-name")
|
47
|
-
container.public_access?.should == false
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should be able to set whether the container is public or not" do
|
51
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
52
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
53
|
-
WAZ::Blobs::Service.any_instance.expects(:set_container_acl).with('container-name', false)
|
54
|
-
container = WAZ::Blobs::Container.find("container-name")
|
55
|
-
container.public_access = false
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should be able to set container properties" do
|
59
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
60
|
-
WAZ::Blobs::Service.any_instance.expects(:set_container_properties).with("container-name", {:x_ms_meta_meta1 => "meta1"}).returns(false)
|
61
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
62
|
-
container = WAZ::Blobs::Container.find("container-name")
|
63
|
-
container.put_properties!(:x_ms_meta_meta1 => "meta1")
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should be able to return a list files within the container" do
|
67
|
-
expected_blobs = [ {:name => 'blob1', :url => 'url', :content_type => 'app/xml'}, {:name => 'blob2', :url => 'url', :content_type => 'app/xml'} ]
|
68
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
69
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
70
|
-
WAZ::Blobs::Service.any_instance.expects(:list_blobs).with("container-name").returns(expected_blobs)
|
71
|
-
container = WAZ::Blobs::Container.find("container-name")
|
72
|
-
container_blobs = container.blobs
|
73
|
-
container_blobs.first().name = expected_blobs[0][:name]
|
74
|
-
container_blobs[1].name = expected_blobs[1][:name]
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should be able to return statistics of the container" do
|
78
|
-
options = {:maxresults => 100, :marker => "marker"}
|
79
|
-
expected_values = {:size => 200, :files => 100, :next_marker => "next-marker"}
|
80
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
81
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
82
|
-
WAZ::Blobs::Service.any_instance.expects(:statistics).with("container-name", options).returns(expected_values)
|
83
|
-
container = WAZ::Blobs::Container.find("container-name")
|
84
|
-
statistics = container.statistics(options)
|
85
|
-
statistics[:size].should == 200
|
86
|
-
statistics[:files].should == 100
|
87
|
-
statistics[:next_marker].should == "next-marker"
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should destroy container" do
|
91
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
92
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
93
|
-
WAZ::Blobs::Service.any_instance.expects(:delete_container).with("container-name")
|
94
|
-
container = WAZ::Blobs::Container.find("container-name")
|
95
|
-
container.destroy!
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should be able to return null when container not found by name" do
|
99
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
100
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").raises(RestClient::ResourceNotFound)
|
101
|
-
container = WAZ::Blobs::Container.find('container-name')
|
102
|
-
container.nil?.should == true
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should be able to put blob inside given container" do
|
106
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
107
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
108
|
-
WAZ::Blobs::Service.any_instance.expects(:put_blob).with("container-name/my_blob", "this is the blob content", "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
109
|
-
container = WAZ::Blobs::Container.find("container-name")
|
110
|
-
blob = container.store("my_blob", "this is the blob content", "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
111
|
-
blob.name.should == "my_blob"
|
112
|
-
blob.url.should == "http://my_account.blob.core.windows.net/container-name/my_blob"
|
113
|
-
blob.content_type.should == "text/plain; charset=UTF-8"
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should be able to upload a stream to a blob inside a given container" do
|
117
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
118
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
119
|
-
WAZ::Blobs::Service.any_instance.expects(:put_block).with("container-name/my_blob", Base64.encode64('%064d' % 0), "this is the blob content")
|
120
|
-
WAZ::Blobs::Service.any_instance.expects(:put_block_list).with("container-name/my_blob", [Base64.encode64('%064d' % 0)], "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
121
|
-
container = WAZ::Blobs::Container.find("container-name")
|
122
|
-
blob = container.upload("my_blob", StringIO.new("this is the blob content"), "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
123
|
-
blob.name.should == "my_blob"
|
124
|
-
blob.url.should == "http://my_account.blob.core.windows.net/container-name/my_blob"
|
125
|
-
blob.content_type.should == "text/plain; charset=UTF-8"
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should be able to put blob inside given container (when simulating fake containers)" do
|
129
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
130
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
131
|
-
WAZ::Blobs::Service.any_instance.expects(:put_blob).with("container-name/fake-container/blob", "this is the blob content", "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
132
|
-
container = WAZ::Blobs::Container.find("container-name")
|
133
|
-
blob = container.store("/fake-container/blob", "this is the blob content", "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
134
|
-
blob.name.should == "fake-container/blob"
|
135
|
-
blob.url.should == "http://my_account.blob.core.windows.net/container-name/fake-container/blob"
|
136
|
-
blob.content_type.should == "text/plain; charset=UTF-8"
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should return a specific blob for the given container" do
|
140
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
141
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
142
|
-
WAZ::Blobs::Service.any_instance.expects(:get_blob_properties).with("container-name/my_blob").returns({ :content_type => "application/xml" })
|
143
|
-
container = WAZ::Blobs::Container.find("container-name")
|
144
|
-
blob = container['my_blob']
|
145
|
-
blob.name.should == 'my_blob'
|
146
|
-
blob.content_type.should == 'application/xml'
|
147
|
-
blob.url.should == 'http://my_account.blob.core.windows.net/container-name/my_blob'
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should return nil when the file does not exist" do
|
151
|
-
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
152
|
-
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
153
|
-
WAZ::Blobs::Service.any_instance.expects(:get_blob_properties).with("container-name/my_blob").raises(RestClient::ResourceNotFound)
|
154
|
-
container = WAZ::Blobs::Container.find('container-name')
|
155
|
-
blob = container['my_blob']
|
156
|
-
blob.nil?.should == true
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should raise an exception when container name starts with - (hypen)" do
|
160
|
-
lambda { WAZ::Blobs::Container.create('-container') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should raise an exception when container name ends with - (hypen)" do
|
164
|
-
lambda { WAZ::Blobs::Container.create('container-') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should raise an exception when container name is less than 3" do
|
168
|
-
lambda { WAZ::Blobs::Container.create('co') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should raise an exception when container name is longer than 63" do
|
172
|
-
lambda { WAZ::Blobs::Container.create('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
173
|
-
end
|
174
|
-
|
175
|
-
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 "Windows Azure Containers interface API" do
|
7
|
+
|
8
|
+
it "should should throw when no container name is provided" do
|
9
|
+
lambda {WAZ::Blobs::Container.new}.should raise_error(WAZ::Storage::InvalidOption)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should list containers" do
|
13
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
14
|
+
WAZ::Blobs::Service.any_instance.expects(:list_containers).returns([{:name => 'my-container'}, {:name => 'other container'}])
|
15
|
+
containers = WAZ::Blobs::Container.list
|
16
|
+
containers.size.should == 2
|
17
|
+
containers.first().name.should == "my-container"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to create a container" do
|
21
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
22
|
+
WAZ::Blobs::Service.any_instance.expects(:create_container).with("my-container")
|
23
|
+
container = WAZ::Blobs::Container.create('my-container')
|
24
|
+
container.name.should == 'my-container'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be able to return a container by name" do
|
28
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
29
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:name => "container-name", :x_ms_meta_name => "container-name"}).twice
|
30
|
+
container = WAZ::Blobs::Container.find('container-name')
|
31
|
+
container.metadata[:x_ms_meta_name].should == 'container-name'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be able to return container metadata" do
|
35
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
36
|
+
WAZ::Blobs::Service.any_instance.expects(:create_container).with("container-name")
|
37
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
38
|
+
container = WAZ::Blobs::Container.create('container-name')
|
39
|
+
container.metadata[:x_ms_meta_name].should == 'container-name'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be able to say whether the container is public or not" do
|
43
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
44
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
45
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_acl).with("container-name").returns(false)
|
46
|
+
container = WAZ::Blobs::Container.find("container-name")
|
47
|
+
container.public_access?.should == false
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be able to set whether the container is public or not" do
|
51
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
52
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
53
|
+
WAZ::Blobs::Service.any_instance.expects(:set_container_acl).with('container-name', false)
|
54
|
+
container = WAZ::Blobs::Container.find("container-name")
|
55
|
+
container.public_access = false
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be able to set container properties" do
|
59
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
60
|
+
WAZ::Blobs::Service.any_instance.expects(:set_container_properties).with("container-name", {:x_ms_meta_meta1 => "meta1"}).returns(false)
|
61
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
62
|
+
container = WAZ::Blobs::Container.find("container-name")
|
63
|
+
container.put_properties!(:x_ms_meta_meta1 => "meta1")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be able to return a list files within the container" do
|
67
|
+
expected_blobs = [ {:name => 'blob1', :url => 'url', :content_type => 'app/xml'}, {:name => 'blob2', :url => 'url', :content_type => 'app/xml'} ]
|
68
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
69
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
70
|
+
WAZ::Blobs::Service.any_instance.expects(:list_blobs).with("container-name").returns(expected_blobs)
|
71
|
+
container = WAZ::Blobs::Container.find("container-name")
|
72
|
+
container_blobs = container.blobs
|
73
|
+
container_blobs.first().name = expected_blobs[0][:name]
|
74
|
+
container_blobs[1].name = expected_blobs[1][:name]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be able to return statistics of the container" do
|
78
|
+
options = {:maxresults => 100, :marker => "marker"}
|
79
|
+
expected_values = {:size => 200, :files => 100, :next_marker => "next-marker"}
|
80
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
81
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
82
|
+
WAZ::Blobs::Service.any_instance.expects(:statistics).with("container-name", options).returns(expected_values)
|
83
|
+
container = WAZ::Blobs::Container.find("container-name")
|
84
|
+
statistics = container.statistics(options)
|
85
|
+
statistics[:size].should == 200
|
86
|
+
statistics[:files].should == 100
|
87
|
+
statistics[:next_marker].should == "next-marker"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should destroy container" do
|
91
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
92
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
93
|
+
WAZ::Blobs::Service.any_instance.expects(:delete_container).with("container-name")
|
94
|
+
container = WAZ::Blobs::Container.find("container-name")
|
95
|
+
container.destroy!
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should be able to return null when container not found by name" do
|
99
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
100
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").raises(RestClient::ResourceNotFound)
|
101
|
+
container = WAZ::Blobs::Container.find('container-name')
|
102
|
+
container.nil?.should == true
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should be able to put blob inside given container" do
|
106
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
107
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
108
|
+
WAZ::Blobs::Service.any_instance.expects(:put_blob).with("container-name/my_blob", "this is the blob content", "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
109
|
+
container = WAZ::Blobs::Container.find("container-name")
|
110
|
+
blob = container.store("my_blob", "this is the blob content", "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
111
|
+
blob.name.should == "my_blob"
|
112
|
+
blob.url.should == "http://my_account.blob.core.windows.net/container-name/my_blob"
|
113
|
+
blob.content_type.should == "text/plain; charset=UTF-8"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should be able to upload a stream to a blob inside a given container" do
|
117
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
118
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
119
|
+
WAZ::Blobs::Service.any_instance.expects(:put_block).with("container-name/my_blob", Base64.encode64('%064d' % 0), "this is the blob content")
|
120
|
+
WAZ::Blobs::Service.any_instance.expects(:put_block_list).with("container-name/my_blob", [Base64.encode64('%064d' % 0)], "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
121
|
+
container = WAZ::Blobs::Container.find("container-name")
|
122
|
+
blob = container.upload("my_blob", StringIO.new("this is the blob content"), "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
123
|
+
blob.name.should == "my_blob"
|
124
|
+
blob.url.should == "http://my_account.blob.core.windows.net/container-name/my_blob"
|
125
|
+
blob.content_type.should == "text/plain; charset=UTF-8"
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should be able to put blob inside given container (when simulating fake containers)" do
|
129
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
130
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
131
|
+
WAZ::Blobs::Service.any_instance.expects(:put_blob).with("container-name/fake-container/blob", "this is the blob content", "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
132
|
+
container = WAZ::Blobs::Container.find("container-name")
|
133
|
+
blob = container.store("/fake-container/blob", "this is the blob content", "text/plain; charset=UTF-8", {:x_ms_meta_custom_property => "customValue"})
|
134
|
+
blob.name.should == "fake-container/blob"
|
135
|
+
blob.url.should == "http://my_account.blob.core.windows.net/container-name/fake-container/blob"
|
136
|
+
blob.content_type.should == "text/plain; charset=UTF-8"
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should return a specific blob for the given container" do
|
140
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
141
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
142
|
+
WAZ::Blobs::Service.any_instance.expects(:get_blob_properties).with("container-name/my_blob").returns({ :content_type => "application/xml" })
|
143
|
+
container = WAZ::Blobs::Container.find("container-name")
|
144
|
+
blob = container['my_blob']
|
145
|
+
blob.name.should == 'my_blob'
|
146
|
+
blob.content_type.should == 'application/xml'
|
147
|
+
blob.url.should == 'http://my_account.blob.core.windows.net/container-name/my_blob'
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should return nil when the file does not exist" do
|
151
|
+
WAZ::Storage::Base.stubs(:default_connection).returns({:account_name => "my_account", :access_key => "key"})
|
152
|
+
WAZ::Blobs::Service.any_instance.expects(:get_container_properties).with("container-name").returns({:x_ms_meta_name => "container-name"})
|
153
|
+
WAZ::Blobs::Service.any_instance.expects(:get_blob_properties).with("container-name/my_blob").raises(RestClient::ResourceNotFound)
|
154
|
+
container = WAZ::Blobs::Container.find('container-name')
|
155
|
+
blob = container['my_blob']
|
156
|
+
blob.nil?.should == true
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should raise an exception when container name starts with - (hypen)" do
|
160
|
+
lambda { WAZ::Blobs::Container.create('-container') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should raise an exception when container name ends with - (hypen)" do
|
164
|
+
lambda { WAZ::Blobs::Container.create('container-') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should raise an exception when container name is less than 3" do
|
168
|
+
lambda { WAZ::Blobs::Container.create('co') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should raise an exception when container name is longer than 63" do
|
172
|
+
lambda { WAZ::Blobs::Container.create('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') }.should raise_error(WAZ::Storage::InvalidParameterValue)
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|