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,30 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestGetBlobHttpUrl < 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.gsub('https:', 'http:')
|
16
|
+
@token = ApiStub::Requests::Storage::File.blob_url_token
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_get_blob_http_url_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.get_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_blob_http_url_mock
|
28
|
+
assert_equal "#{@url}?#{@token}", @mock_service.get_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestGetBlobHttpsUrl < 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_get_blob_https_url_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.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
|
23
|
+
assert_equal "#{@url}?#{@token}", @service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_get_blob_https_url_mock
|
29
|
+
assert_equal "#{@url}?#{@token}", @mock_service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
|
30
|
+
assert_equal "#{@url}?#{@token}", @mock_service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestGetBlobProperties < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of getting storage blob properties.
|
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
|
+
@blob = ApiStub::Requests::Storage::File.blob
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_blob_properties_success
|
19
|
+
@blob_client.stub :get_blob_properties, @blob do
|
20
|
+
assert_equal @blob, @service.get_blob_properties('test_container', 'test_blob')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_get_blob_properties_not_found
|
25
|
+
exception = ->(*) { raise StandardError.new('Not found(404). Not exist') }
|
26
|
+
@blob_client.stub :get_blob_properties, exception do
|
27
|
+
assert_raises('NotFound') do
|
28
|
+
@service.get_blob_properties('test_container', 'test_blob')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_get_blob_properties_http_exception
|
34
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
35
|
+
@blob_client.stub :get_blob_properties, http_exception do
|
36
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
37
|
+
@service.get_blob_properties('test_container', 'test_blob')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_blob_properties_mock
|
43
|
+
mock_blob_properties = @mock_service.get_blob_properties('test_container', 'test_blob')
|
44
|
+
assert_equal @blob.name, mock_blob_properties.name
|
45
|
+
assert_equal @blob.properties, mock_blob_properties.properties
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestGetBlobUrl < 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
|
+
end
|
11
|
+
|
12
|
+
def test_get_blob_url_success
|
13
|
+
service = Fog::Storage::AzureRM.new(storage_account_credentials)
|
14
|
+
blob_client = service.instance_variable_get(:@blob_client)
|
15
|
+
url = ApiStub::Requests::Storage::File.blob_https_url
|
16
|
+
|
17
|
+
blob_client.stub :generate_uri, url do
|
18
|
+
assert_equal url, service.get_blob_url('test_container', 'test_blob')
|
19
|
+
|
20
|
+
options = { scheme: 'http' }
|
21
|
+
assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_get_blob_url_for_china_success
|
26
|
+
china_storage_account_credentials = storage_account_credentials.merge(environment: ENVIRONMENT_AZURE_CHINA_CLOUD)
|
27
|
+
service = Fog::Storage::AzureRM.new(china_storage_account_credentials)
|
28
|
+
blob_client = service.instance_variable_get(:@blob_client)
|
29
|
+
url = ApiStub::Requests::Storage::File.blob_https_url(ENVIRONMENT_AZURE_CHINA_CLOUD)
|
30
|
+
|
31
|
+
blob_client.stub :generate_uri, url do
|
32
|
+
assert_equal url, service.get_blob_url('test_container', 'test_blob')
|
33
|
+
|
34
|
+
options = { scheme: 'http' }
|
35
|
+
assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_get_blob_url_for_us_success
|
40
|
+
us_storage_account_credentials = storage_account_credentials.merge(environment: ENVIRONMENT_AZURE_US_GOVERNMENT)
|
41
|
+
service = Fog::Storage::AzureRM.new(us_storage_account_credentials)
|
42
|
+
blob_client = service.instance_variable_get(:@blob_client)
|
43
|
+
url = ApiStub::Requests::Storage::File.blob_https_url(ENVIRONMENT_AZURE_US_GOVERNMENT)
|
44
|
+
|
45
|
+
blob_client.stub :generate_uri, url do
|
46
|
+
assert_equal url, service.get_blob_url('test_container', 'test_blob')
|
47
|
+
|
48
|
+
options = { scheme: 'http' }
|
49
|
+
assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_get_blob_url_for_german_success
|
54
|
+
german_storage_account_credentials = storage_account_credentials.merge(environment: ENVIRONMENT_AZURE_GERMAN_CLOUD)
|
55
|
+
service = Fog::Storage::AzureRM.new(german_storage_account_credentials)
|
56
|
+
blob_client = service.instance_variable_get(:@blob_client)
|
57
|
+
url = ApiStub::Requests::Storage::File.blob_https_url(ENVIRONMENT_AZURE_GERMAN_CLOUD)
|
58
|
+
|
59
|
+
blob_client.stub :generate_uri, url do
|
60
|
+
assert_equal url, service.get_blob_url('test_container', 'test_blob')
|
61
|
+
|
62
|
+
options = { scheme: 'http' }
|
63
|
+
assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_get_blob_url_mock
|
68
|
+
url = ApiStub::Requests::Storage::File.blob_https_url
|
69
|
+
assert_equal url, @mock_service.get_blob_url('test_container', 'test_blob')
|
70
|
+
|
71
|
+
options = { scheme: 'http' }
|
72
|
+
http_url = url.gsub('https:', 'http:')
|
73
|
+
assert_equal http_url, @mock_service.get_blob_url('test_container', 'test_blob', options)
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Container Class
|
4
|
+
class TestGetContainerAcl < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of getting storage container acl.
|
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_container_acl = ApiStub::Requests::Storage::Directory.raw_container_acl
|
16
|
+
@container_acl = ApiStub::Requests::Storage::Directory.container_acl
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_get_container_acl_success
|
20
|
+
@blob_client.stub :get_container_acl, @raw_container_acl do
|
21
|
+
assert_equal @container_acl, @service.get_container_acl('test_container')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_get_container_acl_http_exception
|
26
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
27
|
+
@blob_client.stub :get_container_acl, http_exception do
|
28
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
29
|
+
@service.get_container_acl('test_container')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_get_container_acl_mock
|
35
|
+
assert_equal @container_acl, @mock_service.get_container_acl('test_container')
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Container Class
|
4
|
+
class TestGetContainerProperties < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of getting storage container properties.
|
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_get_container_properties_success
|
19
|
+
@blob_client.stub :get_container_properties, @container do
|
20
|
+
assert_equal @container, @service.get_container_properties('test_container')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_get_container_properties_not_found
|
25
|
+
exception = ->(_name, _option) { raise StandardError.new('Not found(404). Not exist') }
|
26
|
+
@blob_client.stub :get_container_properties, exception do
|
27
|
+
assert_raises('NotFound') do
|
28
|
+
@service.get_container_properties('test_container')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_get_container_properties_http_exception
|
34
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
35
|
+
@blob_client.stub :get_container_properties, http_exception do
|
36
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
37
|
+
@service.get_container_properties('test_container')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_container_properties_mock
|
43
|
+
assert_equal @container, @mock_service.get_container_properties('test_container')
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Container Class
|
4
|
+
class TestGetContainerUrl < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of getting storage container url.
|
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
|
+
|
14
|
+
@url = ApiStub::Requests::Storage::Directory.container_https_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_get_container_url_success
|
18
|
+
@blob_client.stub :generate_uri, @url do
|
19
|
+
assert_equal @url, @service.get_container_url('test_container')
|
20
|
+
|
21
|
+
options = { scheme: 'http' }
|
22
|
+
assert_equal @url.gsub('https:', 'http:'), @service.get_container_url('test_container', options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_get_container_url_mock
|
27
|
+
assert_equal @url, @mock_service.get_container_url('test_container')
|
28
|
+
|
29
|
+
options = { scheme: 'http' }
|
30
|
+
http_url = @url.gsub('https:', 'http:')
|
31
|
+
assert_equal http_url, @mock_service.get_container_url('test_container', options)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestListBlobs < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of listing blobs in 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
|
+
@blob_list = ApiStub::Requests::Storage::File.blob_list
|
16
|
+
@blobs1 = Azure::Service::EnumerationResults.new
|
17
|
+
@blobs1.continuation_token = 'marker'
|
18
|
+
@blobs1.push(@blob_list[0])
|
19
|
+
@blobs1.push(@blob_list[1])
|
20
|
+
@blobs2 = Azure::Service::EnumerationResults.new
|
21
|
+
@blobs2.push(@blob_list[2])
|
22
|
+
@blobs2.push(@blob_list[3])
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_list_blobs_success
|
26
|
+
multiple_values = lambda do |_container_name, options|
|
27
|
+
return @blobs2 if options[:marker] == 'marker'
|
28
|
+
return @blobs1
|
29
|
+
end
|
30
|
+
@blob_client.stub :list_blobs, multiple_values do
|
31
|
+
result = @service.list_blobs('test_container')
|
32
|
+
assert result[:next_marker].nil?
|
33
|
+
assert_equal @blob_list, result[:blobs]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_list_blobs_with_max_results_success
|
38
|
+
@blob_client.stub :list_blobs, @blobs1 do
|
39
|
+
options = { max_results: 2 }
|
40
|
+
result = @service.list_blobs('test_container', options)
|
41
|
+
assert_equal 'marker', result[:next_marker]
|
42
|
+
assert_equal @blob_list[0, 2], result[:blobs]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_list_blobs_not_found
|
47
|
+
exception = ->(*) { raise StandardError.new('Not found(404). Not exist') }
|
48
|
+
@blob_client.stub :list_blobs, exception do
|
49
|
+
assert_raises('NotFound') do
|
50
|
+
@service.list_blobs('test_container')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_list_blobs_http_exception
|
56
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
57
|
+
@blob_client.stub :list_blobs, http_exception do
|
58
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
59
|
+
@service.list_blobs('test_container')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_list_blobs_exception
|
65
|
+
@blob_client.stub :list_blobs, 'exception' do
|
66
|
+
assert_raises(RuntimeError) do
|
67
|
+
@service.list_blobs('test_container')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_list_blobs_mock
|
73
|
+
result = @mock_service.list_blobs('test_container')
|
74
|
+
assert_equal 'marker', result[:next_marker]
|
75
|
+
assert_equal @blob_list, result[:blobs]
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Container Class
|
4
|
+
class TestListContainers < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of listing 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
|
+
@containers = ApiStub::Requests::Storage::Directory.container_list
|
16
|
+
@containers1 = Azure::Service::EnumerationResults.new
|
17
|
+
@containers1.continuation_token = 'marker'
|
18
|
+
@containers1.push(@containers[0])
|
19
|
+
@containers1.push(@containers[1])
|
20
|
+
@containers2 = Azure::Service::EnumerationResults.new
|
21
|
+
@containers2.push(@containers[2])
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_list_containers_success
|
25
|
+
multiple_values = lambda do |options|
|
26
|
+
return @containers2 if options[:marker] == 'marker'
|
27
|
+
return @containers1
|
28
|
+
end
|
29
|
+
@blob_client.stub :list_containers, multiple_values do
|
30
|
+
assert_equal @containers, @service.list_containers
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_list_containers_http_exception
|
35
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
36
|
+
@blob_client.stub :list_containers, http_exception do
|
37
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
38
|
+
@service.list_containers
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_list_containers_exception
|
44
|
+
@blob_client.stub :list_containers, 'exception' do
|
45
|
+
assert_raises(RuntimeError) do
|
46
|
+
@service.list_containers
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_list_containers_mock
|
52
|
+
assert_equal @containers, @mock_service.list_containers
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.expand_path '../../test_helper', __dir__
|
2
|
+
|
3
|
+
# Storage Blob Class
|
4
|
+
class TestMultipartSaveBlockBlob < Minitest::Test
|
5
|
+
# This class posesses the test cases for the requests of saving storage block blob with multiple parts.
|
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_multipart_save_block_blob_success
|
16
|
+
body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
|
17
|
+
|
18
|
+
@service.stub :create_block_blob, true do
|
19
|
+
@service.stub :put_blob_block, true do
|
20
|
+
@service.stub :commit_blob_blocks, true do
|
21
|
+
assert @service.multipart_save_block_blob('test_container', 'test_blob', body, worker_thread_num: 6, content_md5: 'oafL1+HS78x65+e39PGIIg==')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_multipart_save_block_blob_with_file_handle_success
|
28
|
+
i = 0
|
29
|
+
multiple_values = lambda do |*|
|
30
|
+
i += 1
|
31
|
+
return 'd' * 4 * 1024 * 1024 if i == 1
|
32
|
+
return 'd' * (1 * 1024 * 1024 + 1) if i == 2
|
33
|
+
return nil
|
34
|
+
end
|
35
|
+
temp_file = '/dev/null'
|
36
|
+
File.open(temp_file, 'r') do |file_handle|
|
37
|
+
file_handle.stub :read, multiple_values do
|
38
|
+
file_handle.stub :rewind, nil do
|
39
|
+
@service.stub :create_block_blob, @raw_cloud_blob do
|
40
|
+
@service.stub :put_blob_block, true do
|
41
|
+
@service.stub :commit_blob_blocks, true do
|
42
|
+
assert @service.multipart_save_block_blob('test_container', 'test_blob', file_handle, worker_thread_num: 0)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_multipart_save_block_blob_with_file_handle_do_not_support_rewind_success
|
52
|
+
i = 0
|
53
|
+
multiple_values = lambda do |*|
|
54
|
+
i += 1
|
55
|
+
return 'd' * 4 * 1024 * 1024 if i == 1
|
56
|
+
return 'd' * (1 * 1024 * 1024 + 1) if i == 2
|
57
|
+
return nil
|
58
|
+
end
|
59
|
+
temp_file = '/dev/null'
|
60
|
+
exception = ->(*) { raise 'do not support rewind' }
|
61
|
+
File.open(temp_file, 'r') do |file_handle|
|
62
|
+
file_handle.stub :read, multiple_values do
|
63
|
+
file_handle.stub :rewind, exception do
|
64
|
+
@service.stub :create_block_blob, @raw_cloud_blob do
|
65
|
+
@service.stub :put_blob_block, true do
|
66
|
+
@service.stub :commit_blob_blocks, true do
|
67
|
+
assert @service.multipart_save_block_blob('test_container', 'test_blob', file_handle, worker_thread_num: 'invalid')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_multipart_save_block_blob_http_exception
|
77
|
+
body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
|
78
|
+
|
79
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
80
|
+
@service.stub :create_block_blob, http_exception do
|
81
|
+
@service.stub :delete_blob, true do
|
82
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
83
|
+
@service.multipart_save_block_blob('test_container', 'test_blob', body, {})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_multipart_save_block_blob_fail_when_delete_blob_http_exception
|
90
|
+
body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
|
91
|
+
|
92
|
+
http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
|
93
|
+
@service.stub :create_block_blob, http_exception do
|
94
|
+
@service.stub :delete_blob, http_exception do
|
95
|
+
assert_raises(Azure::Core::Http::HTTPError) do
|
96
|
+
@service.multipart_save_block_blob('test_container', 'test_blob', body, {})
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_multipart_save_block_blob_mock
|
103
|
+
assert @mock_service.multipart_save_block_blob('test_container', 'test_blob', 'content', {})
|
104
|
+
end
|
105
|
+
end
|