test/requests/storage/test_create_disk.rb in fog-azure-rm-0.1.0 vs test/requests/storage/test_create_disk.rb in fog-azure-rm-0.1.1
- old
+ new
@@ -2,16 +2,69 @@
# Storage Data Disk Class
class TestCreateDisk < Minitest::Test
# This class posesses the test cases for the request of create disk.
def setup
+ Fog.mock!
+ @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
+ Fog.unmock!
+ @mocked_response = mocked_storage_http_error
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
- @blob_client = @service.instance_variable_get(:@blob_client)
- @storage_data_disk_object = ApiStub::Requests::Storage::File.upload_block_blob_from_file
end
def test_create_disk_success
- @service.stub :upload_block_blob_from_file, @storage_data_disk_object do
- assert @service.create_disk('test_blob', options = {})
+ @service.stub :create_page_blob, true do
+ @service.stub :put_blob_pages, true do
+ assert @service.create_disk('test_disk', 10)
+ end
end
+ end
+
+ def test_create_disk_in_another_container_success
+ @service.stub :create_page_blob, true do
+ @service.stub :put_blob_pages, true do
+ assert @service.create_disk('test_disk', 10, container_name: 'test_container')
+ end
+ end
+ end
+
+ def test_create_disk_with_invalid_size_exception
+ assert_raises(ArgumentError) do
+ @service.create_disk('test_disk', 'invalid_size')
+ end
+
+ assert_raises(ArgumentError) do
+ @service.create_disk('test_disk', 0)
+ end
+
+ assert_raises(ArgumentError) do
+ @service.create_disk('test_disk', 1024)
+ end
+ end
+
+ def test_create_disk_http_exception
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
+ @service.stub :create_page_blob, http_exception do
+ @service.stub :delete_blob, true do
+ assert_raises(Azure::Core::Http::HTTPError) do
+ @service.create_disk('test_disk', 10, container_name: 'test_container')
+ end
+ end
+ end
+ end
+
+ def test_create_disk_fail_when_delete_blob_http_exception
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
+ @service.stub :create_page_blob, http_exception do
+ @service.stub :delete_blob, http_exception do
+ assert_raises(Azure::Core::Http::HTTPError) do
+ @service.create_disk('test_disk', 10, container_name: 'test_container')
+ end
+ end
+ end
+ end
+
+ def test_create_disk_mock
+ assert @mock_service.create_disk('test_disk')
end
end