1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
require File.expand_path '../../test_helper', __dir__
# Storage Blob Class
class TestCreateBlockBlob < Minitest::Test
# This class posesses the test cases for the requests of creating block blob.
def setup
Fog.mock!
@mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
Fog.unmock!
@mocked_response = mocked_storage_http_error
@service = Fog::AzureRM::Storage.new(storage_account_credentials)
@blob_client = @service.instance_variable_get(:@blob_client)
@block_blob = ApiStub::Requests::Storage::File.block_blob
@emtpy_block_blob = ApiStub::Requests::Storage::File.emtpy_block_blob
end
def test_create_block_blob_success
@blob_client.stub :create_block_blob, @block_blob do
assert_equal @block_blob, @service.create_block_blob('test_container', 'test_blob', 'data')
end
end
def test_create_block_blob_without_content_success
@blob_client.stub :create_block_blob, @emtpy_block_blob do
assert_equal @emtpy_block_blob, @service.create_block_blob('test_container', 'test_blob', nil)
end
end
def test_create_block_blob_with_file_handle_success
temp_file = '/dev/null'
File.open(temp_file, 'r') do |body|
body.stub :read, 'data' do
body.stub :rewind, nil do
@blob_client.stub :create_block_blob, @block_blob do
assert_equal @block_blob, @service.create_block_blob('test_container', 'test_blob', body)
end
end
end
end
exception = ->(*) { raise 'do not support rewind' }
File.open(temp_file, 'r') do |body|
body.stub :read, 'data' do
body.stub :rewind, exception do
@blob_client.stub :create_block_blob, @block_blob do
assert_equal @block_blob, @service.create_block_blob('test_container', 'test_blob', body)
end
end
end
end
end
def test_create_block_blob_http_exception
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
@blob_client.stub :create_block_blob, http_exception do
assert_raises(Azure::Core::Http::HTTPError) do
@service.create_block_blob('test_container', 'test_blob', nil)
end
end
end
def test_create_block_blob_mock
assert_equal @block_blob, @mock_service.create_block_blob('test_container', 'test_blob', 'data')
end
def test_create_block_blob_without_content_mock
assert_equal @emtpy_block_blob, @mock_service.create_block_blob('test_container', 'test_blob', nil)
end
end
|