зеркало из
1
0
Форкнуть 0
This commit is contained in:
Troy Howard 2012-10-23 19:55:19 -07:00
Родитель 3d20afac1c
Коммит 997aed03e4
29 изменённых файлов: 519 добавлений и 268 удалений

Просмотреть файл

@ -14,6 +14,7 @@
#--------------------------------------------------------------------------
require 'azure/storage/service/storage_service'
require 'azure/storage/blob/serialization'
require 'base64'
module Azure
module Storage
@ -498,7 +499,7 @@ module Azure
#
# container - String. The container name.
# blob - String. The blob name.
# block_id - String. The block id.
# block_id - String. The block id. Note: this should be the raw block id, not Base64 encoded.
# content - IO or String. The content of the blob.
# options - Hash. The optional parameters. Understood hash values listed below:
# :content_md5 - String. Content MD5 for the request contents.
@ -507,7 +508,7 @@ module Azure
#
# Returns the MD5 of the uploaded block (as calculated by the server)
def create_blob_block(container, blob, block_id, content, options={})
uri = blob_uri(container, blob, {"comp"=> "block", "blockid" => block_id })
uri = blob_uri(container, blob, {"comp"=> "block", "blockid" => Base64.strict_encode64(block_id) })
headers = {}
headers["Content-MD5"] = options[:content_md5] if options[:content_md5]
@ -531,7 +532,7 @@ module Azure
#
# container - String. The container name.
# blob - String. The blob name.
# block_list - Array. A ordered list of Hashs in the following format:
# block_list - Array. A ordered list of lists in the following format:
# [ ["block_id1", :committed], ["block_id2", :uncommitted], ["block_id3"], ["block_id4", :committed]... ]
# The first element of the inner list is the block_id, the second is optional
# and can be either :committed or :uncommitted to indicate in which group of blocks
@ -595,7 +596,7 @@ module Azure
query = {"comp"=>"blocklist"}
query["snapshot"] = snapshot if snapshot
query["blocklisttype"] = blocklist_type.to_s unless blocklist_type == :committed
query["blocklisttype"] = blocklist_type.to_s
uri = blob_uri(container, blob, query)
@ -826,9 +827,9 @@ module Azure
end
response = call(:get, uri, nil, headers)
blob = Serialization.blob_from_headers(response.headers)
return blob, response.body
result = Serialization.blob_from_headers(response.headers)
result.name = blob if not result.name
return result, response.body
end
# Public: Deletes a blob or blob snapshot.
@ -960,7 +961,7 @@ module Azure
def copy_blob(destination_container, destination_blob, source_container, source_blob, source_snapshot=nil, options=nil)
uri = blob_uri(destination_container, destination_blob)
headers = {}
headers["x-ms-copy-source"] = blob_uri(source_container, source_blob, source_snapshot ? { "snapshot" => source_snapshot } : {})
headers["x-ms-copy-source"] = blob_uri(source_container, source_blob, source_snapshot ? { "snapshot" => source_snapshot } : {}, true).to_s
unless options == nil
headers["If-Modified-Since"] = options[:dest_if_modified_since] if options[:dest_if_modified_since]
@ -1122,8 +1123,8 @@ module Azure
# host - The host of the API.
#
# Returns a URI.
def blob_uri(container_name, blob_name, query={})
generate_uri(File.join(container_name, blob_name), query)
def blob_uri(container_name, blob_name, query={}, no_timeout=false)
generate_uri(File.join(container_name, blob_name), query, no_timeout)
end
end
end

Просмотреть файл

@ -195,6 +195,8 @@ module Azure
properties.lease_duration = headers["x-ms-lease-duration"]
properties.content_length = headers["x-ms-blob-content-length"] || headers["Content-Length"]
properties.content_length = properties.content_length.to_i if properties.content_length
properties.content_type = headers["x-ms-blob-content-type"] || headers["Content-Type"]
properties.content_encoding = headers["x-ms-blob-content-encoding"] || headers["Content-Encoding"]
properties.content_language = headers["x-ms-blob-content-language"] || headers["Content-Language"]
@ -271,7 +273,7 @@ module Azure
def self.add_block(type, block_node, block_list)
block = Azure::Storage::Blob::Block.new
block.name = block_node.Name.text if (block_node > "Name").any?
block.name = Base64.strict_decode64(block_node.Name.text) if (block_node > "Name").any?
block.size = block_node.Size.text.to_i if (block_node > "Size").any?
block.type = type
block_list[type].push block

Просмотреть файл

@ -30,8 +30,10 @@ module Azure
attr_accessor :default_timeout
def generate_uri(path='', query={})
def generate_uri(path='', query={}, no_timeout=false)
query["timeout"] = default_timeout.to_s unless query == nil or query.has_key? "timeout"
query.delete "timeout" if no_timeout unless query == nil or not query.has_key? "timeout"
super(path, query)
end

Просмотреть файл

@ -85,7 +85,7 @@ module Azure
uri = collection_uri(next_table_token ? { "NextTable" => next_table_token } : {})
response = call(:get, uri)
entries = Azure::Storage::Table::Serialization.entries_from_feed_xml response.body
entries = Azure::Storage::Table::Serialization.entries_from_feed_xml(response.body) || []
results = {}
entries.each do |entry|

Просмотреть файл

@ -17,16 +17,17 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#set/get_blob_metadata' do
let(:container_name) { ContainerNameHelper.name }
let(:blob_name) { "blobname" }
let(:length) { 1024 }
let(:metadata){ {"custommetadata" => "CustomMetadataValue"} }
before {
subject.create_container container_name
subject.create_page_blob container_name, blob_name, length
}
let(:metadata){ {"custommetadata" => "CustomMetadataValue"} }
it 'sets and gets metadata for a blob' do
assert subject.set_blob_metadata container_name, blob_name, metadata

Просмотреть файл

@ -17,6 +17,8 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
let(:container_name) { ContainerNameHelper.name }
let(:blob_name) { "blobname" }
let(:length) { 2560 }
@ -26,8 +28,6 @@ describe Azure::Storage::Blob::BlobService do
}
describe '#create_blob_pages' do
after { TableNameHelper.clean }
it 'creates pages in a page blob' do
content = ""
512.times.each{|i| content << "@" }

Просмотреть файл

@ -18,7 +18,8 @@ require "azure/storage/blob/blob_properties"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#set/get_blob_properties' do
let(:container_name) { ContainerNameHelper.name }
let(:blob_name) { "blobname" }

Просмотреть файл

@ -0,0 +1,251 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/blob/blob_service"
require 'base64'
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
let(:container_name) { ContainerNameHelper.name }
let(:blob_name) { "blobname" }
let(:content) { content = ""; 512.times.each{|i| content << "@" }; content }
before {
subject.create_container container_name
}
describe '#create_block_blob' do
it 'creates a page blob' do
blob = subject.create_block_blob container_name, blob_name, content
blob.name.must_equal blob_name
end
it 'sets additional properties when the options hash is used' do
options = {
:content_type=>"application/xml",
:content_encoding=>"utf-8",
:content_language=>"en-US",
:cache_control=>"max-age=1296000",
:metadata => { "CustomMetadataProperty"=>"CustomMetadataValue"}
}
blob = subject.create_block_blob container_name, blob_name, content, options
blob = subject.get_blob_properties container_name, blob_name
blob.name.must_equal blob_name
blob.properties.content_type.must_equal options[:content_type]
blob.properties.content_encoding.must_equal options[:content_encoding]
blob.properties.cache_control.must_equal options[:cache_control]
blob = subject.get_blob_metadata container_name, blob_name
blob.name.must_equal blob_name
blob.metadata["custommetadataproperty"].must_equal "CustomMetadataValue"
end
it 'errors if the container does not exist' do
assert_raises(Azure::Core::Http::HTTPError) do
subject.create_block_blob ContainerNameHelper.name, blob_name, content
end
end
end
describe '#create_blob_block' do
let(:blockid) {"anyblockid1" }
it 'creates a block as part of a block blob' do
subject.create_blob_block container_name, blob_name, blockid, content
# verify
block_list = subject.list_blob_blocks container_name, blob_name
block = block_list[:uncommitted][0]
block.type.must_equal :uncommitted
block.size.must_equal 512
block.name.must_equal blockid
end
end
describe '#commit_blob_blocks' do
let(:blocklist) { [["anyblockid0"], ["anyblockid1"]] }
before {
blocklist.each { |block_entry|
subject.create_blob_block container_name, blob_name, block_entry[0], content
}
}
it 'commits a list of blocks to blob' do
# verify starting state
block_list = subject.list_blob_blocks container_name, blob_name
(0..1).each { |i|
block = block_list[:uncommitted][i]
block.type.must_equal :uncommitted
block.size.must_equal 512
block.name.must_equal blocklist[i][0]
}
assert_raises(Azure::Core::Http::HTTPError) do
subject.get_blob container_name, blob_name
end
# commit blocks
assert subject.commit_blob_blocks container_name, blob_name, blocklist
blob, returned_content = subject.get_blob container_name, blob_name
blob.properties.content_length.must_equal (content.length * 2)
returned_content.must_equal (content + content)
end
end
describe '#list_blob_blocks' do
let(:blocklist) { [["anyblockid0"], ["anyblockid1"], ["anyblockid2"], ["anyblockid3"]] }
before {
subject.create_blob_block container_name, blob_name, blocklist[0][0], content
subject.create_blob_block container_name, blob_name, blocklist[1][0], content
# two committed blocks, two uncommitted blocks
assert subject.commit_blob_blocks container_name, blob_name, blocklist.slice(0..1)
subject.create_blob_block container_name, blob_name, blocklist[2][0], content
subject.create_blob_block container_name, blob_name, blocklist[3][0], content
}
it 'lists blocks in a blob, including their status' do
result = subject.list_blob_blocks container_name, blob_name
committed = result[:committed]
committed.length.must_equal 2
expected_blocks = blocklist.slice(0..1).each
committed.each { |block|
block.name.must_equal expected_blocks.next[0]
block.type.must_equal :committed
block.size.must_equal 512
}
uncommitted = result[:uncommitted]
uncommitted.length.must_equal 2
expected_blocks = blocklist.slice(2..3).each
uncommitted.each { |block|
block.name.must_equal expected_blocks.next[0]
block.type.must_equal :uncommitted
block.size.must_equal 512
}
end
describe 'when blocklist_type parameter is used' do
it 'lists uncommitted blocks only if :uncommitted is passed' do
result = subject.list_blob_blocks container_name, blob_name, :uncommitted
committed = result[:committed]
committed.length.must_equal 0
uncommitted = result[:uncommitted]
uncommitted.length.must_equal 2
expected_blocks = blocklist.slice(2..3).each
uncommitted.each { |block|
block.name.must_equal expected_blocks.next[0]
block.type.must_equal :uncommitted
block.size.must_equal 512
}
end
it 'lists committed blocks only if :committed is passed' do
result = subject.list_blob_blocks container_name, blob_name, :committed
committed = result[:committed]
committed.length.must_equal 2
expected_blocks = blocklist.slice(0..1).each
committed.each { |block|
block.name.must_equal expected_blocks.next[0]
block.type.must_equal :committed
block.size.must_equal 512
}
uncommitted = result[:uncommitted]
uncommitted.length.must_equal 0
end
it 'lists committed and uncommitted blocks if :all is passed' do
result = subject.list_blob_blocks container_name, blob_name, :all
committed = result[:committed]
committed.length.must_equal 2
expected_blocks = blocklist.slice(0..1).each
committed.each { |block|
block.name.must_equal expected_blocks.next[0]
block.type.must_equal :committed
block.size.must_equal 512
}
uncommitted = result[:uncommitted]
uncommitted.length.must_equal 2
expected_blocks = blocklist.slice(2..3).each
uncommitted.each { |block|
block.name.must_equal expected_blocks.next[0]
block.type.must_equal :uncommitted
block.size.must_equal 512
}
end
end
describe 'when snapshot parameter is used' do
it 'lists blocks for the blob snapshot' do
snapshot = subject.create_blob_snapshot container_name, blob_name
assert subject.commit_blob_blocks container_name, blob_name, blocklist
result = subject.list_blob_blocks container_name, blob_name
committed = result[:committed]
committed.length.must_equal 4
expected_blocks = blocklist.each
committed.each { |block|
block.name.must_equal expected_blocks.next[0]
block.type.must_equal :committed
block.size.must_equal 512
}
result = subject.list_blob_blocks container_name, blob_name, :all, snapshot
committed = result[:committed]
committed.length.must_equal 2
expected_blocks = blocklist.slice(0..1).each
committed.each { |block|
block.name.must_equal expected_blocks.next[0]
block.type.must_equal :committed
block.size.must_equal 512
}
# uncommitted blobs aren't copied in a snapshot.
uncommitted = result[:uncommitted]
uncommitted.length.must_equal 0
end
end
end
end

Просмотреть файл

@ -1,26 +0,0 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
describe '#commit_blob_blocks' do
it '' do
end
end
end

Просмотреть файл

@ -18,6 +18,7 @@ require "azure/storage/service/signed_identifier"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#set/get_container_acl' do
let(:container_name) { ContainerNameHelper.name }
@ -33,7 +34,6 @@ describe Azure::Storage::Blob::BlobService do
before {
subject.create_container container_name
}
after { TableNameHelper.clean }
it 'sets and gets the ACL for the container' do
container, acl = subject.set_container_acl container_name, visibility, identifiers

Просмотреть файл

@ -17,6 +17,7 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#set/get_container_metadata' do
let(:container_name) { ContainerNameHelper.name }
@ -24,7 +25,6 @@ describe Azure::Storage::Blob::BlobService do
before {
subject.create_container container_name
}
after { TableNameHelper.clean }
it 'sets and gets custom metadata for the container' do
assert subject.set_container_metadata container_name, metadata

Просмотреть файл

@ -18,10 +18,10 @@ require "azure/core/http/http_error"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#create_container' do
let(:container_name) { ContainerNameHelper.name }
after { TableNameHelper.clean }
it 'creates the container' do
container = subject.create_container container_name

Просмотреть файл

@ -17,13 +17,13 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#delete_container' do
let(:container_name) { ContainerNameHelper.name }
before {
subject.create_container container_name
}
after { TableNameHelper.clean }
it 'deletes the container' do
assert subject.delete_container container_name

Просмотреть файл

@ -17,17 +17,16 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#get_container_properties' do
let(:container_name) { ContainerNameHelper.name }
let(:metadata) { { "CustomMetadataProperty"=>"CustomMetadataValue" } }
after { TableNameHelper.clean }
it 'gets properties and custom metadata for the container' do
container = subject.create_container container_name, metadata
properties = container.properties
container = subject.get_container_properties container_name
container.wont_be_nil
container.name.must_equal container_name

Просмотреть файл

@ -17,6 +17,7 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#list_containers' do
let(:container_names) { [ContainerNameHelper.name, ContainerNameHelper.name] }
@ -26,7 +27,6 @@ describe Azure::Storage::Blob::BlobService do
subject.create_container c, metadata
}
}
after { TableNameHelper.clean }
it 'lists the containers for the account' do
result = subject.list_containers

Просмотреть файл

@ -17,10 +17,80 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#copy_blob' do
it '' do
let(:source_container_name) { ContainerNameHelper.name }
let(:source_blob_name) { "sourceblobname" }
let(:content) { content = ""; 512.times.each{|i| content << "@" }; content }
let(:dest_container_name) { ContainerNameHelper.name }
let(:dest_blob_name) { "destblobname" }
before {
subject.create_container source_container_name
subject.create_block_blob source_container_name, source_blob_name, content
subject.create_container dest_container_name
}
it 'copies an existing blob to a new storage location' do
copy_id, copy_status = subject.copy_blob dest_container_name, dest_blob_name, source_container_name, source_blob_name
copy_id.wont_be_nil
blob, returned_content = subject.get_blob dest_container_name, dest_blob_name
blob.name.must_equal dest_blob_name
returned_content.must_equal content
end
it 'returns a copyid which can be used to monitor status of the asynchronous copy operation' do
copy_id, copy_status = subject.copy_blob dest_container_name, dest_blob_name, source_container_name, source_blob_name
copy_id.wont_be_nil
counter = 0
finished = false
while(counter < 10 and not finished)
sleep(1)
blob = subject.get_blob_properties dest_container_name, dest_blob_name
blob.properties.copy_id.must_equal copy_id
finished = blob.properties.copy_status == "success"
counter +=1
end
finished.must_equal true
blob, returned_content = subject.get_blob dest_container_name, dest_blob_name
blob.name.must_equal dest_blob_name
returned_content.must_equal content
end
describe 'when a snapshot is specified' do
it 'creates a copy of the snapshot' do
snapshot = subject.create_blob_snapshot source_container_name, source_blob_name
# verify blob is updated, and content is different than snapshot
subject.create_block_blob source_container_name, source_blob_name, content + "more content"
blob, returned_content = subject.get_blob source_container_name, source_blob_name
returned_content.must_equal content + "more content"
# do copy against, snapshot
subject.copy_blob dest_container_name, dest_blob_name, source_container_name, source_blob_name, snapshot
blob, returned_content = subject.get_blob dest_container_name, dest_blob_name
# verify copied content is old content
returned_content.must_equal content
end
end
describe 'when a options hash is used' do
it 'replaces source metadata on the copy with provided Hash in :metadata property' do
skip "TODO"
end
it 'can specify ETag matching behaviours' do
skip "TODO"
end
end
end
end

Просмотреть файл

@ -17,6 +17,7 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#create_blob_snapshot' do
let(:container_name) { ContainerNameHelper.name }
@ -24,11 +25,11 @@ describe Azure::Storage::Blob::BlobService do
let(:content) { content = ""; 1024.times.each{|i| content << "@" }; content }
let(:metadata) { { "CustomMetadataProperty"=>"CustomMetadataValue" } }
let(:options) { { :blob_content_type=>"application/foo", :metadata => metadata } }
before {
subject.create_container container_name
subject.create_block_blob container_name, blob_name, content, options
}
after { TableNameHelper.clean }
it 'errors if the container does not exist' do
assert_raises(Azure::Core::Http::HTTPError) do

Просмотреть файл

@ -1,78 +0,0 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
let(:container_name) { ContainerNameHelper.name }
let(:blob_name) { "blobname" }
let(:content) { content = ""; 512.times.each{|i| content << "@" }; content }
before {
subject.create_container container_name
}
after { TableNameHelper.clean }
describe '#create_block_blob' do
it 'creates a page blob' do
blob = subject.create_block_blob container_name, blob_name, content
blob.name.must_equal blob_name
end
it 'sets additional properties when the options hash is used' do
options = {
:content_type=>"application/xml",
:content_encoding=>"utf-8",
:content_language=>"en-US",
:cache_control=>"max-age=1296000",
:metadata => { "CustomMetadataProperty"=>"CustomMetadataValue"}
}
blob = subject.create_block_blob container_name, blob_name, content, options
blob = subject.get_blob_properties container_name, blob_name
blob.name.must_equal blob_name
blob.properties.content_type.must_equal options[:content_type]
blob.properties.content_encoding.must_equal options[:content_encoding]
blob.properties.cache_control.must_equal options[:cache_control]
blob = subject.get_blob_metadata container_name, blob_name
blob.name.must_equal blob_name
blob.metadata["custommetadataproperty"].must_equal "CustomMetadataValue"
end
it 'errors if the container does not exist' do
assert_raises(Azure::Core::Http::HTTPError) do
subject.create_block_blob ContainerNameHelper.name, blob_name, content
end
end
end
describe '#create_blob_block' do
require 'base64'
let(:blockid) { Base64.strict_encode64("anyblockid") }
#before { subject.create_block_blob container_name, blob_name, content }
it 'creates a block as part of a block blob' do
subject.create_blob_block container_name, blob_name, blockid, content
# verify
block_list = subject.list_blob_blocks container_name, blob_name
block = block_list[:uncommitted][0]
block.type.must_equal :uncommitted
block.size.must_equal 512
block.name.must_equal blockid
end
end
end

Просмотреть файл

@ -17,6 +17,7 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#create_page_blob' do
let(:container_name) { ContainerNameHelper.name }
@ -25,7 +26,6 @@ describe Azure::Storage::Blob::BlobService do
before {
subject.create_container container_name
}
after { TableNameHelper.clean }
it 'creates a page blob' do
blob = subject.create_page_blob container_name, blob_name, length

Просмотреть файл

@ -17,7 +17,8 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#delete_blob' do
let(:container_name) { ContainerNameHelper.name }
let(:blob_name) { "blobname" }
@ -26,7 +27,6 @@ describe Azure::Storage::Blob::BlobService do
subject.create_container container_name
subject.create_page_blob container_name, blob_name, length
}
after { TableNameHelper.clean }
it 'deletes a blob' do
subject.delete_blob container_name, blob_name

Просмотреть файл

@ -17,7 +17,8 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#get_blob' do
let(:container_name) { ContainerNameHelper.name }
let(:blob_name) { "blobname" }
@ -29,7 +30,7 @@ describe Azure::Storage::Blob::BlobService do
subject.create_container container_name
subject.create_block_blob container_name, blob_name, content, options
}
# start_range=nil, end_range=nil, snapshot=nil, get_content_md5 = false
it 'retrieves the blob properties, metadata, and contents' do
blob, returned_content = subject.get_blob container_name, blob_name
returned_content.must_equal content

Просмотреть файл

@ -20,7 +20,7 @@ describe Azure::Storage::Blob::BlobService do
describe '#acquire_lease' do
it '' do
skip "TODO"
end
end
end

Просмотреть файл

@ -20,7 +20,7 @@ describe Azure::Storage::Blob::BlobService do
describe '#break_lease' do
it '' do
skip "TODO"
end
end
end

Просмотреть файл

@ -20,7 +20,7 @@ describe Azure::Storage::Blob::BlobService do
describe '#release_lease' do
it '' do
skip "TODO"
end
end
end

Просмотреть файл

@ -20,7 +20,7 @@ describe Azure::Storage::Blob::BlobService do
describe '#renew_lease' do
it '' do
skip "TODO"
end
end
end

Просмотреть файл

@ -1,26 +0,0 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "integration/test_helper"
require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
describe '#list_blob_blocks' do
it '' do
end
end
end

Просмотреть файл

@ -17,10 +17,85 @@ require "azure/storage/blob/blob_service"
describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { TableNameHelper.clean }
describe '#list_blobs' do
it '' do
let(:container_name) { ContainerNameHelper.name }
let(:blob_names) { ["blobname0","blobname1","blobname2","blobname3"] }
let(:content) { content = ""; 1024.times.each{|i| content << "@" }; content }
let(:metadata) { { "CustomMetadataProperty"=>"CustomMetadataValue" } }
let(:options) { { :blob_content_type=>"application/foo", :metadata => metadata } }
before {
subject.create_container container_name
blob_names.each { |blob_name|
subject.create_block_blob container_name, blob_name, content, options
}
}
it 'lists the available blobs' do
result = subject.list_blobs container_name
result.blobs.length.must_equal blob_names.length
expected_blob_names = blob_names.each
result.blobs.each { |blob|
blob.name.must_equal expected_blob_names.next
blob.properties.content_length.must_equal content.length
}
end
describe 'when options hash is used' do
it 'if :metadata is set true, also returns custom metadata for the blobs' do
result = subject.list_blobs container_name, { :metadata => true }
result.blobs.length.must_equal blob_names.length
expected_blob_names = blob_names.each
result.blobs.each { |blob|
blob.name.must_equal expected_blob_names.next
blob.properties.content_length.must_equal content.length
metadata.each { |k,v|
blob.metadata.must_include k.downcase
blob.metadata[k.downcase].must_equal v
}
}
end
it 'if :snapshots is set true, also returns snapshots' do
snapshot = subject.create_blob_snapshot container_name, blob_names[0]
# verify snapshots aren't returned on a normal call
result = subject.list_blobs container_name
result.blobs.length.must_equal blob_names.length
result = subject.list_blobs container_name, { :snapshots => true }
result.blobs.length.must_equal blob_names.length + 1
found_snapshot = false
result.blobs.each { |blob|
found_snapshot = true if blob.name == blob_names[0] and blob.snapshot == snapshot
}
found_snapshot.must_equal true
end
it 'if :uncommittedblobs is set true, also returns blobs with uploaded, uncommitted blocks' do
# uncommited blob/block
subject.create_blob_block container_name, "blockblobname", "blockid", content
# verify uncommitted blobs aren't returned on a normal call
result = subject.list_blobs container_name
result.blobs.length.must_equal blob_names.length
result = subject.list_blobs container_name, { :uncommittedblobs => true }
result.blobs.length.must_equal blob_names.length + 1
found_uncommitted = true
result.blobs.each { |blob|
found_uncommitted = true if blob.name == "blockblobname"
}
found_uncommitted.must_equal true
end
it 'if :copy is set true, also returns metadata about active copy operations' do
skip "TODO"
end
end
end
end

Просмотреть файл

@ -1,26 +0,0 @@
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
def create_block_blob(options={})
metadata = options.fetch(:metadata, {})
filename = options.fetch(:filename, Fixtures["32px-fulls-black.jpg"].to_path)
name = options.fetch(:name, "myblob")
container = options.fetch(:container, @container)
Azure::Blobs.create_block_blob(container, name, filename, metadata)
end
def create_page_blob(container)
Azure::Blobs.create_page_blob(container, "myblob", {:size => 8192})
end

Просмотреть файл

@ -696,7 +696,7 @@ describe Azure::Storage::Blob::BlobService do
let(:request_headers) {
{
"x-ms-page-write" => "update",
"x-ms-range" => "#{start_range}-#{end_range}",
"x-ms-range" => "bytes=#{start_range}-#{end_range}",
"Content-Type" => ""
}
}
@ -770,8 +770,11 @@ describe Azure::Storage::Blob::BlobService do
describe "#clear_blob_pages" do
let(:method) { :put }
let(:query) { {"comp" => "page"} }
let(:start_range){ 255 }
let(:end_range){ 512 }
let(:request_headers) {
{
"x-ms-range" => "bytes=#{start_range}-#{end_range}",
"x-ms-page-write" => "clear",
"Content-Type" => ""
}
@ -785,54 +788,54 @@ describe Azure::Storage::Blob::BlobService do
it "assembles a URI for the request" do
subject.expects(:blob_uri).with(container_name, blob_name, query).returns(uri)
subject.clear_blob_pages container_name, blob_name
subject.clear_blob_pages container_name, blob_name, start_range, end_range
end
it "calls StorageService#call with the prepared request" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
subject.clear_blob_pages container_name, blob_name
subject.clear_blob_pages container_name, blob_name, start_range, end_range
end
it "returns a Blob on success" do
result = subject.clear_blob_pages container_name, blob_name
result = subject.clear_blob_pages container_name, blob_name, start_range, end_range
result.must_be_kind_of Azure::Storage::Blob::Blob
result.must_equal blob
result.name.must_equal blob_name
end
describe "when start_range is provided" do
let(:start_range){ 255 }
before { request_headers["x-ms-range"]="#{start_range}-" }
# describe "when start_range is provided" do
# let(:start_range){ 255 }
# before { request_headers["x-ms-range"]="#{start_range}-" }
it "modifies the request headers with the desired range" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
subject.clear_blob_pages container_name, blob_name, start_range
end
end
# it "modifies the request headers with the desired range" do
# subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
# subject.clear_blob_pages container_name, blob_name, start_range
# end
# end
describe "when end_range is provided" do
let(:end_range){ 512 }
before { request_headers["x-ms-range"]="0-#{end_range}" }
# describe "when end_range is provided" do
# let(:end_range){ 512 }
# before { request_headers["x-ms-range"]="0-#{end_range}" }
it "modifies the request headers with the desired range" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
subject.clear_blob_pages container_name, blob_name, nil, end_range
end
end
# it "modifies the request headers with the desired range" do
# subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
# subject.clear_blob_pages container_name, blob_name, nil, end_range
# end
# end
describe "when both start_range and end_range are provided" do
let(:start_range){ 255 }
let(:end_range){ 512 }
before { request_headers["x-ms-range"]="#{start_range}-#{end_range}" }
# describe "when both start_range and end_range are provided" do
# before { request_headers["x-ms-range"]="bytes=#{start_range}-#{end_range}" }
it "modifies the request headers with the desired range" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
subject.clear_blob_pages container_name, blob_name, start_range, end_range
end
end
# it "modifies the request headers with the desired range" do
# subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
# subject.clear_blob_pages container_name, blob_name, start_range, end_range
# end
# end
end
describe "#create_blob_block" do
require 'base64'
let(:method) { :put }
let(:content) { "some content"}
let(:block_id) { "block-id"}
@ -840,7 +843,7 @@ describe Azure::Storage::Blob::BlobService do
let(:request_headers) { {} }
before {
query.update({ "comp" => "block", "blockid" => block_id })
query.update({ "comp" => "block", "blockid" => Base64.strict_encode64(block_id) })
response_headers["Content-MD5"] = server_generated_content_md5
subject.stubs(:blob_uri).with(container_name, blob_name, query).returns(uri)
subject.stubs(:call).with(method, uri, content, request_headers).returns(response)
@ -1091,8 +1094,8 @@ describe Azure::Storage::Blob::BlobService do
subject.list_blob_blocks container_name, blob_name, :uncommitted
end
it "does not modify the request query when the value is :committed" do
query.delete "blocklisttype"
it "modifies the request query when the value is :committed" do
query["blocklisttype"] = "committed"
subject.list_blob_blocks container_name, blob_name, :committed
end
end
@ -1139,30 +1142,30 @@ describe Azure::Storage::Blob::BlobService do
result.first.first.next.must_be_kind_of Integer
end
describe "when start_range is provided" do
let(:start_range){ 255 }
before { request_headers["x-ms-range"]="#{start_range}-" }
# describe "when start_range is provided" do
# let(:start_range){ 255 }
# before { request_headers["x-ms-range"]="#{start_range}-" }
it "modifies the request headers with the desired range" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
subject.list_page_blob_ranges container_name, blob_name, start_range
end
end
# it "modifies the request headers with the desired range" do
# subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
# subject.list_page_blob_ranges container_name, blob_name, start_range
# end
# end
describe "when end_range is provided" do
let(:end_range){ 512 }
before { request_headers["x-ms-range"]="0-#{end_range}" }
# describe "when end_range is provided" do
# let(:end_range){ 512 }
# before { request_headers["x-ms-range"]="0-#{end_range}" }
it "modifies the request headers with the desired range" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
subject.list_page_blob_ranges container_name, blob_name, nil, end_range
end
end
# it "modifies the request headers with the desired range" do
# subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
# subject.list_page_blob_ranges container_name, blob_name, nil, end_range
# end
# end
describe "when both start_range and end_range are provided" do
let(:start_range){ 255 }
let(:end_range){ 512 }
before { request_headers["x-ms-range"]="#{start_range}-#{end_range}" }
before { request_headers["x-ms-range"]="bytes=#{start_range}-#{end_range}" }
it "modifies the request headers with the desired range" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
@ -1411,30 +1414,30 @@ describe Azure::Storage::Blob::BlobService do
end
end
describe "when start_range is provided" do
let(:start_range){ 255 }
before { request_headers["x-ms-range"]="#{start_range}-" }
# describe "when start_range is provided" do
# let(:start_range){ 255 }
# before { request_headers["x-ms-range"]="#{start_range}-" }
it "modifies the request headers with the desired range" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
subject.get_blob container_name, blob_name, start_range
end
end
# it "modifies the request headers with the desired range" do
# subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
# subject.get_blob container_name, blob_name, start_range
# end
# end
describe "when end_range is provided" do
let(:end_range){ 512 }
before { request_headers["x-ms-range"]="0-#{end_range}" }
# describe "when end_range is provided" do
# let(:end_range){ 512 }
# before { request_headers["x-ms-range"]="0-#{end_range}" }
it "modifies the request headers with the desired range" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
subject.get_blob container_name, blob_name, nil, end_range
end
end
# it "modifies the request headers with the desired range" do
# subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
# subject.get_blob container_name, blob_name, nil, end_range
# end
# end
describe "when both start_range and end_range are provided" do
let(:start_range){ 255 }
let(:end_range){ 512 }
before { request_headers["x-ms-range"]="#{start_range}-#{end_range}" }
before { request_headers["x-ms-range"]="bytes=#{start_range}-#{end_range}" }
it "modifies the request headers with the desired range" do
subject.expects(:call).with(method, uri, nil, request_headers).returns(response)
@ -1449,7 +1452,7 @@ describe Azure::Storage::Blob::BlobService do
let(:start_range){ 255 }
let(:end_range){ 512 }
before {
request_headers["x-ms-range"]="#{start_range}-#{end_range}"
request_headers["x-ms-range"]="bytes=#{start_range}-#{end_range}"
request_headers["x-ms-range-get-content-md5"]= true
}
@ -1619,13 +1622,13 @@ describe Azure::Storage::Blob::BlobService do
let(:copy_status) { "copy-status" }
before {
request_headers["x-ms-copy-source"] = source_uri
request_headers["x-ms-copy-source"] = source_uri.to_s
response_headers["x-ms-copy-id"] = copy_id
response_headers["x-ms-copy-status"] = copy_status
subject.stubs(:blob_uri).with(container_name, blob_name).returns(uri)
subject.stubs(:blob_uri).with(source_container_name, source_blob_name, query).returns(source_uri)
subject.stubs(:blob_uri).with(source_container_name, source_blob_name, query, true).returns(source_uri)
subject.stubs(:call).with(method, uri, nil, request_headers).returns(response)
}
@ -1635,7 +1638,7 @@ describe Azure::Storage::Blob::BlobService do
end
it "assembles the source URI and places it in the header" do
subject.expects(:blob_uri).with(source_container_name, source_blob_name, query).returns(source_uri)
subject.expects(:blob_uri).with(source_container_name, source_blob_name, query, true).returns(source_uri)
subject.copy_blob container_name, blob_name, source_container_name, source_blob_name
end
@ -1657,7 +1660,7 @@ describe Azure::Storage::Blob::BlobService do
}
it "modifies the source blob uri query string with the snapshot" do
subject.expects(:blob_uri).with(source_container_name, source_blob_name, query).returns(source_uri)
subject.expects(:blob_uri).with(source_container_name, source_blob_name, query, true).returns(source_uri)
subject.copy_blob container_name, blob_name, source_container_name, source_blob_name, source_snapshot
end
end