gitlab-fog-azure-rm 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.arclint +8 -0
- data/.codeclimate.yml +17 -0
- data/.gitignore +6 -0
- data/.gitlab-ci.yml +17 -0
- data/.hound.yml +2 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +274 -0
- data/.travis.yml +49 -0
- data/CHANGELOG.md +414 -0
- data/CONTRIBUTING.md +40 -0
- data/CONTRIBUTORS.md +12 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/README.md +100 -0
- data/gitlab-fog-azure-rm.gemspec +31 -0
- data/lib/fog/azurerm.rb +30 -0
- data/lib/fog/azurerm/async_response.rb +44 -0
- data/lib/fog/azurerm/config.rb +1 -0
- data/lib/fog/azurerm/constants.rb +72 -0
- data/lib/fog/azurerm/credentials.rb +40 -0
- data/lib/fog/azurerm/custom_fog_errors.rb +52 -0
- data/lib/fog/azurerm/docs/storage.md +398 -0
- data/lib/fog/azurerm/docs/structure.md +53 -0
- data/lib/fog/azurerm/models/resources/azure_resource.rb +25 -0
- data/lib/fog/azurerm/models/resources/azure_resources.rb +40 -0
- data/lib/fog/azurerm/models/resources/dependency.rb +27 -0
- data/lib/fog/azurerm/models/resources/deployment.rb +65 -0
- data/lib/fog/azurerm/models/resources/deployments.rb +30 -0
- data/lib/fog/azurerm/models/resources/provider.rb +27 -0
- data/lib/fog/azurerm/models/resources/provider_resource_type.rb +22 -0
- data/lib/fog/azurerm/models/resources/resource_group.rb +34 -0
- data/lib/fog/azurerm/models/resources/resource_groups.rb +29 -0
- data/lib/fog/azurerm/models/storage/directories.rb +75 -0
- data/lib/fog/azurerm/models/storage/directory.rb +151 -0
- data/lib/fog/azurerm/models/storage/file.rb +265 -0
- data/lib/fog/azurerm/models/storage/files.rb +183 -0
- data/lib/fog/azurerm/models/storage/kind.rb +12 -0
- data/lib/fog/azurerm/models/storage/sku_name.rb +15 -0
- data/lib/fog/azurerm/models/storage/sku_tier.rb +12 -0
- data/lib/fog/azurerm/models/storage/storage_account.rb +92 -0
- data/lib/fog/azurerm/models/storage/storage_accounts.rb +47 -0
- data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +32 -0
- data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +32 -0
- data/lib/fog/azurerm/requests/storage/check_container_exists.rb +30 -0
- data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
- data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
- data/lib/fog/azurerm/requests/storage/copy_blob.rb +30 -0
- data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +30 -0
- data/lib/fog/azurerm/requests/storage/copy_object.rb +20 -0
- data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
- data/lib/fog/azurerm/requests/storage/create_container.rb +40 -0
- data/lib/fog/azurerm/requests/storage/create_disk.rb +62 -0
- data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
- data/lib/fog/azurerm/requests/storage/delete_blob.rb +32 -0
- data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/delete_container.rb +31 -0
- data/lib/fog/azurerm/requests/storage/delete_disk.rb +36 -0
- data/lib/fog/azurerm/requests/storage/delete_object_url.rb +30 -0
- data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
- data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +55 -0
- data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
- data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
- data/lib/fog/azurerm/requests/storage/get_container_properties.rb +41 -0
- data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
- data/lib/fog/azurerm/requests/storage/get_object_url.rb +21 -0
- data/lib/fog/azurerm/requests/storage/list_blobs.rb +168 -0
- data/lib/fog/azurerm/requests/storage/list_containers.rb +73 -0
- data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
- data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
- data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
- data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_object_url.rb +30 -0
- data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +30 -0
- data/lib/fog/azurerm/requests/storage/release_container_lease.rb +30 -0
- data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
- data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
- data/lib/fog/azurerm/storage.rb +126 -0
- data/lib/fog/azurerm/utilities/general.rb +186 -0
- data/lib/fog/azurerm/utilities/logger_messages.yml +19 -0
- data/lib/fog/azurerm/version.rb +5 -0
- data/rake-script.sh +10 -0
- data/rakefile +29 -0
- data/test/api_stub.rb +147 -0
- data/test/api_stub/models/storage/directory.rb +178 -0
- data/test/api_stub/models/storage/file.rb +181 -0
- data/test/api_stub/requests/storage/directory.rb +89 -0
- data/test/api_stub/requests/storage/file.rb +252 -0
- data/test/integration/README.md +14 -0
- data/test/integration/blob.rb +297 -0
- data/test/integration/container.rb +160 -0
- data/test/integration/credentials/azure.yml +5 -0
- data/test/integration/storage_account.rb +135 -0
- data/test/models/storage/test_directories.rb +74 -0
- data/test/models/storage/test_directory.rb +178 -0
- data/test/models/storage/test_file.rb +294 -0
- data/test/models/storage/test_files.rb +234 -0
- data/test/requests/storage/test_acquire_blob_lease.rb +36 -0
- data/test/requests/storage/test_acquire_container_lease.rb +36 -0
- data/test/requests/storage/test_check_container_exists.rb +18 -0
- data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
- data/test/requests/storage/test_compare_container_blobs.rb +36 -0
- data/test/requests/storage/test_copy_blob.rb +39 -0
- data/test/requests/storage/test_copy_blob_from_uri.rb +36 -0
- data/test/requests/storage/test_create_block_blob.rb +80 -0
- data/test/requests/storage/test_create_container.rb +36 -0
- data/test/requests/storage/test_create_disk.rb +70 -0
- data/test/requests/storage/test_create_page_blob.rb +34 -0
- data/test/requests/storage/test_delete_blob.rb +42 -0
- data/test/requests/storage/test_delete_blob_https_url.rb +32 -0
- data/test/requests/storage/test_delete_container.rb +42 -0
- data/test/requests/storage/test_delete_disk.rb +30 -0
- data/test/requests/storage/test_get_blob.rb +141 -0
- data/test/requests/storage/test_get_blob_http_url.rb +30 -0
- data/test/requests/storage/test_get_blob_https_url.rb +32 -0
- data/test/requests/storage/test_get_blob_properties.rb +47 -0
- data/test/requests/storage/test_get_blob_url.rb +75 -0
- data/test/requests/storage/test_get_container_acl.rb +37 -0
- data/test/requests/storage/test_get_container_properties.rb +45 -0
- data/test/requests/storage/test_get_container_url.rb +33 -0
- data/test/requests/storage/test_list_blobs.rb +77 -0
- data/test/requests/storage/test_list_containers.rb +54 -0
- data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
- data/test/requests/storage/test_put_blob_block.rb +34 -0
- data/test/requests/storage/test_put_blob_https_url.rb +32 -0
- data/test/requests/storage/test_put_blob_metadata.rb +36 -0
- data/test/requests/storage/test_put_blob_pages.rb +34 -0
- data/test/requests/storage/test_put_blob_properties.rb +39 -0
- data/test/requests/storage/test_put_container_acl.rb +34 -0
- data/test/requests/storage/test_put_container_metadata.rb +36 -0
- data/test/requests/storage/test_release_blob_lease.rb +34 -0
- data/test/requests/storage/test_release_container_lease.rb +34 -0
- data/test/requests/storage/test_save_page_blob.rb +115 -0
- data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
- data/test/smoke_tests/compute/test_resource_group_smoke.rb +37 -0
- data/test/test_credentials.rb +63 -0
- data/test/test_helper.rb +846 -0
- metadata +352 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestCreateBlockBlob < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of creating block blob.
|
6
|
+
def setup
|
7
|
+
Fog.mock!
|
8
|
+
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
+
Fog.unmock!
|
10
|
+
@mocked_response = mocked_storage_http_error
|
11
|
+
|
12
|
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
13
|
+
@blob_client = @service.instance_variable_get(:@blob_client)
|
14
|
+
|
15
|
+
@block_blob = ApiStub::Requests::Storage::File.block_blob
|
16
|
+
@emtpy_block_blob = ApiStub::Requests::Storage::File.emtpy_block_blob
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_create_block_blob_success
|
20
|
+
@blob_client.stub :create_block_blob, @block_blob do
|
21
|
+
assert_equal @block_blob, @service.create_block_blob('test_container', 'test_blob', 'data')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_create_block_blob_without_content_success
|
26
|
+
@blob_client.stub :create_block_blob, @emtpy_block_blob do
|
27
|
+
assert_equal @emtpy_block_blob, @service.create_block_blob('test_container', 'test_blob', nil)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create_block_blob_with_file_handle_success
|
32
|
+
temp_file = '/dev/null'
|
33
|
+
File.open(temp_file, 'r') do |body|
|
34
|
+
body.stub :read, 'data' do
|
35
|
+
body.stub :rewind, nil do
|
36
|
+
@blob_client.stub :create_block_blob, @block_blob do
|
37
|
+
assert_equal @block_blob, @service.create_block_blob('test_container', 'test_blob', body)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
exception = ->(*) { raise 'do not support rewind' }
|
44
|
+
File.open(temp_file, 'r') do |body|
|
45
|
+
body.stub :read, 'data' do
|
46
|
+
body.stub :rewind, exception do
|
47
|
+
@blob_client.stub :create_block_blob, @block_blob do
|
48
|
+
assert_equal @block_blob, @service.create_block_blob('test_container', 'test_blob', body)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_create_block_blob_exceed_max_body_size
|
56
|
+
data = []
|
57
|
+
data.stub :size, 64 * 1024 * 1024 + 1 do
|
58
|
+
assert_raises(ArgumentError) do
|
59
|
+
@service.create_block_blob('test_container', 'test_blob', data)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_create_block_blob_http_exception
|
65
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
66
|
+
@blob_client.stub :create_block_blob, http_exception do
|
67
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
68
|
+
@service.create_block_blob('test_container', 'test_blob', nil)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_create_block_blob_mock
|
74
|
+
assert_equal @block_blob, @mock_service.create_block_blob('test_container', 'test_blob', 'data')
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_create_block_blob_without_content_mock
|
78
|
+
assert_equal @emtpy_block_blob, @mock_service.create_block_blob('test_container', 'test_blob', nil)
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Container Class
|
4
|
+
class TestCreateContainer < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of creating storage containers.
|
6
|
+
def setup
|
7
|
+
Fog.mock!
|
8
|
+
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
+
Fog.unmock!
|
10
|
+
@mocked_response = mocked_storage_http_error
|
11
|
+
|
12
|
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
13
|
+
@blob_client = @service.instance_variable_get(:@blob_client)
|
14
|
+
|
15
|
+
@container = ApiStub::Requests::Storage::Directory.container
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_create_container_success
|
19
|
+
@blob_client.stub :create_container, @container do
|
20
|
+
assert_equal @container, @service.create_container('test_container')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create_container_http_exception
|
25
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
26
|
+
@blob_client.stub :create_container, http_exception do
|
27
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
28
|
+
@service.create_container('test_container')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_create_container_mock
|
34
|
+
assert_equal @container, @mock_service.create_container('test_container')
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Data Disk Class
|
4
|
+
class TestCreateDisk < Minitest::Test
|
5
|
+
# This class posesses the test cases for the request of create disk.
|
6
|
+
def setup
|
7
|
+
Fog.mock!
|
8
|
+
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
+
Fog.unmock!
|
10
|
+
@mocked_response = mocked_storage_http_error
|
11
|
+
|
12
|
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_create_disk_success
|
16
|
+
@service.stub :create_page_blob, true do
|
17
|
+
@service.stub :put_blob_pages, true do
|
18
|
+
assert @service.create_disk('test_disk', 10)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_create_disk_in_another_container_success
|
24
|
+
@service.stub :create_page_blob, true do
|
25
|
+
@service.stub :put_blob_pages, true do
|
26
|
+
assert @service.create_disk('test_disk', 10, container_name: 'test_container')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create_disk_with_invalid_size_exception
|
32
|
+
assert_raises(ArgumentError) do
|
33
|
+
@service.create_disk('test_disk', 'invalid_size')
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_raises(ArgumentError) do
|
37
|
+
@service.create_disk('test_disk', 0)
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_raises(ArgumentError) do
|
41
|
+
@service.create_disk('test_disk', 1024)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_create_disk_http_exception
|
46
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
47
|
+
@service.stub :create_page_blob, http_exception do
|
48
|
+
@service.stub :delete_blob, true do
|
49
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
50
|
+
@service.create_disk('test_disk', 10, container_name: 'test_container')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_create_disk_fail_when_delete_blob_http_exception
|
57
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
58
|
+
@service.stub :create_page_blob, http_exception do
|
59
|
+
@service.stub :delete_blob, http_exception do
|
60
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
61
|
+
@service.create_disk('test_disk', 10, container_name: 'test_container')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_create_disk_mock
|
68
|
+
assert @mock_service.create_disk('test_disk')
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestCreatePageBlob < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of creating storage page blobs.
|
6
|
+
def setup
|
7
|
+
Fog.mock!
|
8
|
+
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
+
Fog.unmock!
|
10
|
+
@mocked_response = mocked_storage_http_error
|
11
|
+
|
12
|
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
13
|
+
@blob_client = @service.instance_variable_get(:@blob_client)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create_page_blob_success
|
17
|
+
@blob_client.stub :create_page_blob, true do
|
18
|
+
assert @service.create_page_blob('test_container', 'test_blob', 1_024)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_create_page_blob_http_exception
|
23
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
24
|
+
@blob_client.stub :create_page_blob, http_exception do
|
25
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
26
|
+
@service.create_page_blob('test_container', 'test_blob', 1_024)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create_page_blob_mock
|
32
|
+
assert @mock_service.create_page_blob('test_container', 'test_blob', 1_024)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestDeleteBlob < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of deleting storage blobs.
|
6
|
+
def setup
|
7
|
+
Fog.mock!
|
8
|
+
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
+
Fog.unmock!
|
10
|
+
@mocked_response = mocked_storage_http_error
|
11
|
+
@mocked_not_found_response = mocked_storage_http_not_found_error
|
12
|
+
|
13
|
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
14
|
+
@blob_client = @service.instance_variable_get(:@blob_client)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_delete_blob_success
|
18
|
+
@blob_client.stub :delete_blob, true do
|
19
|
+
assert @service.delete_blob('test_container', 'test_blob')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_delete_blob_with_not_found_success
|
24
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_not_found_response) }
|
25
|
+
@blob_client.stub :delete_blob, http_exception do
|
26
|
+
assert @service.delete_blob('test_container', 'test_blob')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_delete_blob_http_exception
|
31
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
32
|
+
@blob_client.stub :delete_blob, http_exception do
|
33
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
34
|
+
@service.delete_blob('test_container', 'test_blob')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_delete_blob_mock
|
40
|
+
assert @mock_service.delete_blob('test_container', 'test_blob')
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestPutBlobHttpUrl < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of Blob service.
|
6
|
+
def setup
|
7
|
+
Fog.mock!
|
8
|
+
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
+
Fog.unmock!
|
10
|
+
|
11
|
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
12
|
+
@blob_client = @service.instance_variable_get(:@blob_client)
|
13
|
+
@signature_client = @service.instance_variable_get(:@signature_client)
|
14
|
+
|
15
|
+
@url = ApiStub::Requests::Storage::File.blob_https_url
|
16
|
+
@token = ApiStub::Requests::Storage::File.blob_url_token
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_delete_blob_http_urls_success
|
20
|
+
@blob_client.stub :generate_uri, @url do
|
21
|
+
@signature_client.stub :generate_service_sas_token, @token do
|
22
|
+
assert_equal "#{@url}?#{@token}", @service.delete_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
|
23
|
+
assert_equal "#{@url}?#{@token}", @service.delete_object_url('test_container', 'test_blob', Time.now.utc + 3600)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_delete_blob_https_url_mock
|
29
|
+
assert_equal "#{@url}?#{@token}", @mock_service.delete_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
|
30
|
+
assert_equal "#{@url}?#{@token}", @mock_service.delete_object_url('test_container', 'test_blob', Time.now.utc + 3600)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Container Class
|
4
|
+
class TestDeleteContainer < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of deleting storage containers.
|
6
|
+
def setup
|
7
|
+
Fog.mock!
|
8
|
+
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
+
Fog.unmock!
|
10
|
+
@mocked_response = mocked_storage_http_error
|
11
|
+
@mocked_not_found_response = mocked_storage_http_not_found_error
|
12
|
+
|
13
|
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
14
|
+
@blob_client = @service.instance_variable_get(:@blob_client)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_delete_container_success
|
18
|
+
@blob_client.stub :delete_container, true do
|
19
|
+
assert @service.delete_container('test_container')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_delete_container_not_found_success
|
24
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_not_found_response) }
|
25
|
+
@blob_client.stub :delete_container, http_exception do
|
26
|
+
assert @service.delete_container('test_container')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_delete_blob_http_exception
|
31
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
32
|
+
@blob_client.stub :delete_container, http_exception do
|
33
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
34
|
+
@service.delete_container('test_container')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_delete_container_mock
|
40
|
+
assert @mock_service.delete_container('test_container')
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Data Disk Class
|
4
|
+
class TestDeleteDisk < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of deleting data disks.
|
6
|
+
def setup
|
7
|
+
Fog.mock!
|
8
|
+
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
+
Fog.unmock!
|
10
|
+
@mocked_response = mocked_storage_http_error
|
11
|
+
|
12
|
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_delete_disk_success
|
16
|
+
@service.stub :delete_blob, true do
|
17
|
+
assert @service.delete_disk('test_disk')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_delete_disk_in_another_container_success
|
22
|
+
@service.stub :delete_blob, true do
|
23
|
+
assert @service.delete_disk('test_disk', container_name: 'test_container')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_delete_disk_mock
|
28
|
+
assert @mock_service.delete_disk('test_disk')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestGetBlob < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of getting storage blob.
|
6
|
+
def setup
|
7
|
+
Fog.mock!
|
8
|
+
@mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
9
|
+
Fog.unmock!
|
10
|
+
@mocked_response = mocked_storage_http_error
|
11
|
+
|
12
|
+
@service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
13
|
+
@blob_client = @service.instance_variable_get(:@blob_client)
|
14
|
+
|
15
|
+
@raw_cloud_blob = storage_blob
|
16
|
+
@blob = ApiStub::Requests::Storage::File.blob_as_hash
|
17
|
+
@blob_with_content = [
|
18
|
+
@blob,
|
19
|
+
'content'
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_get_blob_success
|
24
|
+
@blob_client.stub :get_blob, @blob_with_content do
|
25
|
+
assert_equal @blob_with_content, @service.get_blob('test_container', 'test_blob')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_get_blob_not_found
|
30
|
+
exception = ->(*) { raise StandardError.new('Not found(404). Not exist') }
|
31
|
+
@blob_client.stub :get_blob, exception do
|
32
|
+
assert_raises('NotFound') do
|
33
|
+
@service.get_blob('test_container', 'test_blob')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_get_blob_http_exception
|
39
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
40
|
+
@blob_client.stub :get_blob, http_exception do
|
41
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
42
|
+
@service.get_blob('test_container', 'test_blob')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_get_blob_mock
|
48
|
+
assert_equal @blob_with_content, @mock_service.get_blob('test_container', 'test_blob')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_get_blob_with_block_given_success
|
52
|
+
data = ''
|
53
|
+
@blob_client.stub :get_blob_properties, @raw_cloud_blob do
|
54
|
+
@blob_client.stub :get_blob, @blob_with_content do
|
55
|
+
@service.get_blob('test_container', 'test_blob') do |chunk, _remaining_bytes, _total_bytes|
|
56
|
+
data << chunk
|
57
|
+
end
|
58
|
+
assert_equal @blob_with_content[1], data
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_get_blob_with_block_given_with_emtpy_blob_success
|
64
|
+
data = ''
|
65
|
+
empty_raw_cloud_blob = @raw_cloud_blob
|
66
|
+
empty_raw_cloud_blob.properties[:content_length] = 0
|
67
|
+
empty_blob_with_content = [
|
68
|
+
@blob,
|
69
|
+
''
|
70
|
+
]
|
71
|
+
@blob_client.stub :get_blob_properties, empty_raw_cloud_blob do
|
72
|
+
@blob_client.stub :get_blob, empty_blob_with_content do
|
73
|
+
@service.get_blob('test_container', 'test_blob') do |chunk, _remaining_bytes, _total_bytes|
|
74
|
+
data << chunk
|
75
|
+
end
|
76
|
+
assert data.empty?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_get_blob_with_block_given_with_emtpy_range_success
|
82
|
+
data = ''
|
83
|
+
options = {
|
84
|
+
start_range: 1024,
|
85
|
+
end_range: 1024
|
86
|
+
}
|
87
|
+
@blob_client.stub :get_blob_properties, @raw_cloud_blob do
|
88
|
+
@blob_client.stub :get_blob, @blob_with_content do
|
89
|
+
@service.get_blob('test_container', 'test_blob', options) do |chunk, _remaining_bytes, _total_bytes|
|
90
|
+
data << chunk
|
91
|
+
end
|
92
|
+
assert data.empty?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_get_blob_with_block_given_invalid_options
|
98
|
+
options = {
|
99
|
+
start_range: 1024,
|
100
|
+
end_range: 0
|
101
|
+
}
|
102
|
+
@blob_client.stub :get_blob_properties, @raw_cloud_blob do
|
103
|
+
@service.stub :get_blob_properties, @blob_with_content[0] do
|
104
|
+
assert_raises(ArgumentError) do
|
105
|
+
@service.get_blob('test_container', 'test_blob', options) do |*chunk|
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_get_blob_with_block_given_not_exist
|
113
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
114
|
+
@blob_client.stub :get_blob_properties, http_exception do
|
115
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
116
|
+
@service.get_blob('test_container', 'test_blob') do |*chunk|
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_get_blob_with_block_given_http_exception
|
123
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
124
|
+
@blob_client.stub :get_blob_properties, @raw_cloud_blob do
|
125
|
+
@blob_client.stub :get_blob, http_exception do
|
126
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
127
|
+
@service.get_blob('test_container', 'test_blob') do |*chunk|
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_get_blob_with_block_given_mock
|
135
|
+
data = ''
|
136
|
+
@mock_service.get_blob('test_container', 'test_blob') do |chunk, _remaining_bytes, _total_bytes|
|
137
|
+
data << chunk
|
138
|
+
end
|
139
|
+
assert_equal @blob_with_content[1], data
|
140
|
+
end
|
141
|
+
end
|