gitlab-fog-azure-rm 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +7 -0
  2. data/.arclint +8 -0
  3. data/.codeclimate.yml +17 -0
  4. data/.gitignore +6 -0
  5. data/.gitlab-ci.yml +17 -0
  6. data/.hound.yml +2 -0
  7. data/.rubocop.yml +5 -0
  8. data/.rubocop_todo.yml +274 -0
  9. data/.travis.yml +49 -0
  10. data/CHANGELOG.md +414 -0
  11. data/CONTRIBUTING.md +40 -0
  12. data/CONTRIBUTORS.md +12 -0
  13. data/Gemfile +3 -0
  14. data/LICENSE.md +20 -0
  15. data/README.md +100 -0
  16. data/gitlab-fog-azure-rm.gemspec +31 -0
  17. data/lib/fog/azurerm.rb +30 -0
  18. data/lib/fog/azurerm/async_response.rb +44 -0
  19. data/lib/fog/azurerm/config.rb +1 -0
  20. data/lib/fog/azurerm/constants.rb +72 -0
  21. data/lib/fog/azurerm/credentials.rb +40 -0
  22. data/lib/fog/azurerm/custom_fog_errors.rb +52 -0
  23. data/lib/fog/azurerm/docs/storage.md +398 -0
  24. data/lib/fog/azurerm/docs/structure.md +53 -0
  25. data/lib/fog/azurerm/models/resources/azure_resource.rb +25 -0
  26. data/lib/fog/azurerm/models/resources/azure_resources.rb +40 -0
  27. data/lib/fog/azurerm/models/resources/dependency.rb +27 -0
  28. data/lib/fog/azurerm/models/resources/deployment.rb +65 -0
  29. data/lib/fog/azurerm/models/resources/deployments.rb +30 -0
  30. data/lib/fog/azurerm/models/resources/provider.rb +27 -0
  31. data/lib/fog/azurerm/models/resources/provider_resource_type.rb +22 -0
  32. data/lib/fog/azurerm/models/resources/resource_group.rb +34 -0
  33. data/lib/fog/azurerm/models/resources/resource_groups.rb +29 -0
  34. data/lib/fog/azurerm/models/storage/directories.rb +75 -0
  35. data/lib/fog/azurerm/models/storage/directory.rb +151 -0
  36. data/lib/fog/azurerm/models/storage/file.rb +265 -0
  37. data/lib/fog/azurerm/models/storage/files.rb +183 -0
  38. data/lib/fog/azurerm/models/storage/kind.rb +12 -0
  39. data/lib/fog/azurerm/models/storage/sku_name.rb +15 -0
  40. data/lib/fog/azurerm/models/storage/sku_tier.rb +12 -0
  41. data/lib/fog/azurerm/models/storage/storage_account.rb +92 -0
  42. data/lib/fog/azurerm/models/storage/storage_accounts.rb +47 -0
  43. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +32 -0
  44. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +32 -0
  45. data/lib/fog/azurerm/requests/storage/check_container_exists.rb +30 -0
  46. data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
  47. data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
  48. data/lib/fog/azurerm/requests/storage/copy_blob.rb +30 -0
  49. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +30 -0
  50. data/lib/fog/azurerm/requests/storage/copy_object.rb +20 -0
  51. data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
  52. data/lib/fog/azurerm/requests/storage/create_container.rb +40 -0
  53. data/lib/fog/azurerm/requests/storage/create_disk.rb +62 -0
  54. data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
  55. data/lib/fog/azurerm/requests/storage/delete_blob.rb +32 -0
  56. data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +39 -0
  57. data/lib/fog/azurerm/requests/storage/delete_container.rb +31 -0
  58. data/lib/fog/azurerm/requests/storage/delete_disk.rb +36 -0
  59. data/lib/fog/azurerm/requests/storage/delete_object_url.rb +30 -0
  60. data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
  61. data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
  62. data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
  63. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +55 -0
  64. data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
  65. data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
  66. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +41 -0
  67. data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
  68. data/lib/fog/azurerm/requests/storage/get_object_url.rb +21 -0
  69. data/lib/fog/azurerm/requests/storage/list_blobs.rb +168 -0
  70. data/lib/fog/azurerm/requests/storage/list_containers.rb +73 -0
  71. data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
  72. data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
  73. data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +39 -0
  74. data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +31 -0
  75. data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
  76. data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
  77. data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
  78. data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +31 -0
  79. data/lib/fog/azurerm/requests/storage/put_object_url.rb +30 -0
  80. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +30 -0
  81. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +30 -0
  82. data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
  83. data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
  84. data/lib/fog/azurerm/storage.rb +126 -0
  85. data/lib/fog/azurerm/utilities/general.rb +186 -0
  86. data/lib/fog/azurerm/utilities/logger_messages.yml +19 -0
  87. data/lib/fog/azurerm/version.rb +5 -0
  88. data/rake-script.sh +10 -0
  89. data/rakefile +29 -0
  90. data/test/api_stub.rb +147 -0
  91. data/test/api_stub/models/storage/directory.rb +178 -0
  92. data/test/api_stub/models/storage/file.rb +181 -0
  93. data/test/api_stub/requests/storage/directory.rb +89 -0
  94. data/test/api_stub/requests/storage/file.rb +252 -0
  95. data/test/integration/README.md +14 -0
  96. data/test/integration/blob.rb +297 -0
  97. data/test/integration/container.rb +160 -0
  98. data/test/integration/credentials/azure.yml +5 -0
  99. data/test/integration/storage_account.rb +135 -0
  100. data/test/models/storage/test_directories.rb +74 -0
  101. data/test/models/storage/test_directory.rb +178 -0
  102. data/test/models/storage/test_file.rb +294 -0
  103. data/test/models/storage/test_files.rb +234 -0
  104. data/test/requests/storage/test_acquire_blob_lease.rb +36 -0
  105. data/test/requests/storage/test_acquire_container_lease.rb +36 -0
  106. data/test/requests/storage/test_check_container_exists.rb +18 -0
  107. data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
  108. data/test/requests/storage/test_compare_container_blobs.rb +36 -0
  109. data/test/requests/storage/test_copy_blob.rb +39 -0
  110. data/test/requests/storage/test_copy_blob_from_uri.rb +36 -0
  111. data/test/requests/storage/test_create_block_blob.rb +80 -0
  112. data/test/requests/storage/test_create_container.rb +36 -0
  113. data/test/requests/storage/test_create_disk.rb +70 -0
  114. data/test/requests/storage/test_create_page_blob.rb +34 -0
  115. data/test/requests/storage/test_delete_blob.rb +42 -0
  116. data/test/requests/storage/test_delete_blob_https_url.rb +32 -0
  117. data/test/requests/storage/test_delete_container.rb +42 -0
  118. data/test/requests/storage/test_delete_disk.rb +30 -0
  119. data/test/requests/storage/test_get_blob.rb +141 -0
  120. data/test/requests/storage/test_get_blob_http_url.rb +30 -0
  121. data/test/requests/storage/test_get_blob_https_url.rb +32 -0
  122. data/test/requests/storage/test_get_blob_properties.rb +47 -0
  123. data/test/requests/storage/test_get_blob_url.rb +75 -0
  124. data/test/requests/storage/test_get_container_acl.rb +37 -0
  125. data/test/requests/storage/test_get_container_properties.rb +45 -0
  126. data/test/requests/storage/test_get_container_url.rb +33 -0
  127. data/test/requests/storage/test_list_blobs.rb +77 -0
  128. data/test/requests/storage/test_list_containers.rb +54 -0
  129. data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
  130. data/test/requests/storage/test_put_blob_block.rb +34 -0
  131. data/test/requests/storage/test_put_blob_https_url.rb +32 -0
  132. data/test/requests/storage/test_put_blob_metadata.rb +36 -0
  133. data/test/requests/storage/test_put_blob_pages.rb +34 -0
  134. data/test/requests/storage/test_put_blob_properties.rb +39 -0
  135. data/test/requests/storage/test_put_container_acl.rb +34 -0
  136. data/test/requests/storage/test_put_container_metadata.rb +36 -0
  137. data/test/requests/storage/test_release_blob_lease.rb +34 -0
  138. data/test/requests/storage/test_release_container_lease.rb +34 -0
  139. data/test/requests/storage/test_save_page_blob.rb +115 -0
  140. data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
  141. data/test/smoke_tests/compute/test_resource_group_smoke.rb +37 -0
  142. data/test/test_credentials.rb +63 -0
  143. data/test/test_helper.rb +846 -0
  144. metadata +352 -0
@@ -0,0 +1,34 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Blob Class
4
+ class TestPutBlobBlock < Minitest::Test
5
+ # This class posesses the test cases for the requests of putting blob block.
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_put_blob_block_success
17
+ @blob_client.stub :put_blob_block, true do
18
+ assert @service.put_blob_block('test_container', 'test_blob', 'id', 'data')
19
+ end
20
+ end
21
+
22
+ def test_put_blob_block_http_exception
23
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
24
+ @blob_client.stub :put_blob_block, http_exception do
25
+ assert_raises(Azure::Core::Http::HTTPError) do
26
+ @service.put_blob_block('test_container', 'test_blob', 'id', 'data')
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_put_blob_block_mock
32
+ assert @mock_service.put_blob_block('test_container', 'test_blob', 'id', 'data')
33
+ end
34
+ 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_put_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.put_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
23
+ assert_equal "#{@url}?#{@token}", @service.put_object_url('test_container', 'test_blob', Time.now.utc + 3600, {})
24
+ end
25
+ end
26
+ end
27
+
28
+ def test_put_blob_https_url_mock
29
+ assert_equal "#{@url}?#{@token}", @mock_service.put_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600)
30
+ assert_equal "#{@url}?#{@token}", @mock_service.put_object_url('test_container', 'test_blob', Time.now.utc + 3600, {})
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Blob Class
4
+ class TestPutBlobMetadata < Minitest::Test
5
+ # This class posesses the test cases for the requests of setting blob metadata.
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
+ @metadata = ApiStub::Requests::Storage::File.blob_metadata
16
+ end
17
+
18
+ def test_put_blob_metadata_success
19
+ @blob_client.stub :set_blob_metadata, true do
20
+ assert @service.put_blob_metadata('test_container', 'test_blob', @metadata)
21
+ end
22
+ end
23
+
24
+ def test_put_blob_metadata_http_exception
25
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
26
+ @blob_client.stub :set_blob_metadata, http_exception do
27
+ assert_raises(Azure::Core::Http::HTTPError) do
28
+ @service.put_blob_metadata('test_container', 'test_blob', @metadata)
29
+ end
30
+ end
31
+ end
32
+
33
+ def test_put_blob_metadata_mock
34
+ assert @mock_service.put_blob_metadata('test_container', 'test_blob', @metadata)
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Blob Class
4
+ class TestPutBlobPages < Minitest::Test
5
+ # This class posesses the test cases for the requests of putting blob page.
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_put_blob_pages_success
17
+ @blob_client.stub :put_blob_pages, true do
18
+ assert @service.put_blob_pages('test_container', 'test_blob', 0, 1024, 'data')
19
+ end
20
+ end
21
+
22
+ def test_put_blob_pages_http_exception
23
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
24
+ @blob_client.stub :put_blob_pages, http_exception do
25
+ assert_raises(Azure::Core::Http::HTTPError) do
26
+ @service.put_blob_pages('test_container', 'test_blob', 0, 1024, 'data')
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_put_blob_pages_mock
32
+ assert @mock_service.put_blob_pages('test_container', 'test_blob', 0, 1024, 'data')
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Blob Class
4
+ class TestPutBlobProperties < Minitest::Test
5
+ # This class posesses the test cases for the requests of setting 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
+ @properties = {
16
+ content_language: 'english',
17
+ content_disposition: 'attachment'
18
+ }
19
+ end
20
+
21
+ def test_put_blob_properties_success
22
+ @blob_client.stub :set_blob_properties, true do
23
+ assert @service.put_blob_properties('test_container', 'test_blob', @properties)
24
+ end
25
+ end
26
+
27
+ def test_put_blob_properties_http_exception
28
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
29
+ @blob_client.stub :set_blob_properties, http_exception do
30
+ assert_raises(Azure::Core::Http::HTTPError) do
31
+ @service.put_blob_properties('test_container', 'test_blob', @properties)
32
+ end
33
+ end
34
+ end
35
+
36
+ def test_put_blob_properties_mock
37
+ assert @mock_service.put_blob_properties('test_container', 'test_blob', @properties)
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Container Class
4
+ class TestPutContainerACL < Minitest::Test
5
+ # This class posesses the test cases for the requests of setting 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
+ end
15
+
16
+ def test_put_container_acl_success
17
+ @blob_client.stub :set_container_acl, true do
18
+ assert @service.put_container_acl('test_container', 'container')
19
+ end
20
+ end
21
+
22
+ def test_put_container_acl_http_exception
23
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
24
+ @blob_client.stub :set_container_acl, http_exception do
25
+ assert_raises(Azure::Core::Http::HTTPError) do
26
+ @service.put_container_acl('test_container', 'container')
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_put_container_acl_mock
32
+ assert @mock_service.put_container_acl('test_container', 'container')
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Container Class
4
+ class TestPutContainerMetadata < Minitest::Test
5
+ # This class posesses the test cases for the requests of container service.
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
+ @metadata = ApiStub::Requests::Storage::Directory.container_metadata
16
+ end
17
+
18
+ def test_put_container_metadata_success
19
+ @blob_client.stub :set_container_metadata, true do
20
+ assert @service.put_container_metadata('test_container', @metadata)
21
+ end
22
+ end
23
+
24
+ def test_put_container_metadata_http_exception
25
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
26
+ @blob_client.stub :set_container_metadata, http_exception do
27
+ assert_raises(Azure::Core::Http::HTTPError) do
28
+ @service.put_container_metadata('test_container', @metadata)
29
+ end
30
+ end
31
+ end
32
+
33
+ def test_put_container_metadata_mock
34
+ assert @mock_service.put_container_metadata('test_container', @metadata)
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Blob Class
4
+ class TestReleaseBlobLease < Minitest::Test
5
+ # This class posesses the test cases for the requests of releasing blob lease.
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_release_blob_lease_success
17
+ @blob_client.stub :release_blob_lease, true do
18
+ assert @service.release_blob_lease('test_container', 'test_blob', 'lease_id')
19
+ end
20
+ end
21
+
22
+ def test_release_blob_lease_http_exception
23
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
24
+ @blob_client.stub :release_blob_lease, http_exception do
25
+ assert_raises(Azure::Core::Http::HTTPError) do
26
+ @service.release_blob_lease('test_container', 'test_blob', 'lease_id')
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_release_blob_lease_mock
32
+ assert @mock_service.release_blob_lease('test_container', 'test_blob', 'lease_id')
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Container Class
4
+ class TestReleaseContainerLease < Minitest::Test
5
+ # This class posesses the test cases for the requests of releasing container lease.
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_release_container_lease_success
17
+ @blob_client.stub :release_container_lease, true do
18
+ assert @service.release_container_lease('test_container', 'lease_id')
19
+ end
20
+ end
21
+
22
+ def test_release_container_lease_http_exception
23
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
24
+ @blob_client.stub :release_container_lease, http_exception do
25
+ assert_raises(Azure::Core::Http::HTTPError) do
26
+ @service.release_container_lease('test_container', 'lease_id')
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_release_container_lease_mock
32
+ assert @mock_service.release_container_lease('test_container', 'lease_id')
33
+ end
34
+ end
@@ -0,0 +1,115 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Blob Class
4
+ class TestSavePageBlob < Minitest::Test
5
+ # This class posesses the test cases for the requests of saving storage page 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
+ end
14
+
15
+ def test_save_page_blob_success
16
+ body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
17
+
18
+ @service.stub :create_page_blob, true do
19
+ @service.stub :put_blob_pages, true do
20
+ assert @service.save_page_blob('test_container', 'test_blob', body, worker_thread_num: 6, content_md5: 'oafL1+HS78x65+e39PGIIg==')
21
+ end
22
+ end
23
+ end
24
+
25
+ def test_save_page_blob_with_file_handle_success
26
+ data_length = 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
27
+ i = 0
28
+ multiple_values = lambda do |*|
29
+ i += 1
30
+ return 'd' * 4 * 1024 * 1024 if i == 1
31
+ return 'd' * 1 * 1024 * 1024 if i == 2
32
+ return nil
33
+ end
34
+ temp_file = '/dev/null'
35
+ File.open(temp_file, 'r') do |file_handle|
36
+ file_handle.stub :read, multiple_values do
37
+ file_handle.stub :size, data_length do
38
+ file_handle.stub :rewind, nil do
39
+ @service.stub :create_page_blob, true do
40
+ @service.stub :put_blob_pages, true do
41
+ assert @service.save_page_blob('test_container', 'test_blob', file_handle, worker_thread_num: 0)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def test_save_page_blob_with_file_handle_do_not_support_rewind_success
51
+ data_length = 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
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 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 :size, data_length do
64
+ file_handle.stub :rewind, exception do
65
+ @service.stub :create_page_blob, true do
66
+ @service.stub :put_blob_pages, true do
67
+ assert @service.save_page_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_save_page_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_page_blob, http_exception do
81
+ @service.stub :delete_blob, true do
82
+ assert_raises(Azure::Core::Http::HTTPError) do
83
+ @service.save_page_blob('test_container', 'test_blob', body, {})
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ def test_save_page_blob_invalid_size_exception
90
+ body = 'd' * 1025 # The page blob size must be aligned to a 512-byte boundary.
91
+
92
+ @service.stub :delete_blob, true do
93
+ assert_raises(RuntimeError) do
94
+ @service.save_page_blob('test_container', 'test_blob', body, {})
95
+ end
96
+ end
97
+ end
98
+
99
+ def test_save_page_blob_fail_when_delete_blob_http_exception
100
+ body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
101
+
102
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
103
+ @service.stub :create_page_blob, http_exception do
104
+ @service.stub :delete_blob, http_exception do
105
+ assert_raises(Azure::Core::Http::HTTPError) do
106
+ @service.save_page_blob('test_container', 'test_blob', body, {})
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ def test_save_page_blob_mock
113
+ assert @mock_service.save_page_blob('test_container', 'test_blob', 'content', {})
114
+ end
115
+ end
@@ -0,0 +1,148 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Storage Blob Class
4
+ class TestWaitBlobCopyOperationToFinish < Minitest::Test
5
+ # This class posesses the test cases for the requests of waiting storage blob copy operation to finish.
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
+ @blob = storage_blob
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_wait_blob_copy_operation_to_finish_with_success
18
+ copy_id = @blob.properties[:copy_id]
19
+ copy_status = 'pending'
20
+
21
+ i = 0
22
+ multiple_values = lambda do |*|
23
+ i += 1
24
+ if i == 1
25
+ @blob.properties[:copy_status] = copy_status
26
+ @blob.properties[:copy_progress] = '0/1024'
27
+ @blob.properties[:copy_status_description] = 'in progress'
28
+ return @blob
29
+ end
30
+
31
+ if i == 2
32
+ @blob.properties[:copy_status] = copy_status
33
+ @blob.properties[:copy_progress] = '2/1024'
34
+ @blob.properties[:copy_status_description] = 'in progress'
35
+ return @blob
36
+ end
37
+
38
+ if i == 3
39
+ @blob.properties[:copy_status] = copy_status
40
+ @blob.properties[:copy_progress] = '1023/1024'
41
+ @blob.properties[:copy_status_description] = 'in progress'
42
+ return @blob
43
+ end
44
+
45
+ @blob.properties[:copy_status] = 'success'
46
+ @blob.properties[:copy_progress] = '1024/1024'
47
+ @blob.properties[:copy_status_description] = 'finish'
48
+ @blob
49
+ end
50
+
51
+ @service.stub :get_blob_properties, multiple_values do
52
+ assert @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status)
53
+ end
54
+ end
55
+
56
+ def test_wait_blob_copy_operation_to_finish_with_copy_finished_success
57
+ copy_id = nil
58
+ copy_status = 'success'
59
+
60
+ @service.stub :get_blob_properties, @blob do
61
+ assert @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status)
62
+ end
63
+ end
64
+
65
+ def test_wait_blob_copy_operation_to_finish_with_copy_id_is_nil
66
+ copy_id = nil
67
+ copy_status = 'pending'
68
+
69
+ @service.stub :get_blob_properties, @blob do
70
+ assert @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status)
71
+ end
72
+ end
73
+
74
+ def test_wait_blob_copy_operation_to_finish_with_copy_id_not_match_exception
75
+ copy_id = 'copy_id'
76
+ copy_status = 'pending'
77
+
78
+ @service.stub :get_blob_properties, @blob do
79
+ @service.stub :delete_blob, true do
80
+ assert_raises(RuntimeError) do
81
+ @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status)
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ def test_wait_blob_copy_operation_to_finish_with_timeout_exception
88
+ copy_id = @blob.properties[:copy_id]
89
+ copy_status = 'pending'
90
+
91
+ i = 0
92
+ multiple_values = lambda do |*|
93
+ i += 1
94
+ if i == 1
95
+ @blob.properties[:copy_status] = copy_status
96
+ @blob.properties[:copy_progress] = '0/1024'
97
+ @blob.properties[:copy_status_description] = 'in progress'
98
+ return @blob
99
+ end
100
+
101
+ @blob.properties[:copy_status] = copy_status
102
+ @blob.properties[:copy_progress] = '0/1024'
103
+ @blob.properties[:copy_status_description] = 'in progress'
104
+ @blob
105
+ end
106
+
107
+ @service.stub :get_blob_properties, multiple_values do
108
+ @service.stub :delete_blob, true do
109
+ assert_raises(TimeoutError) do
110
+ @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status, 2)
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ def test_wait_blob_copy_operation_to_finish_with_fail_exception
117
+ copy_id = @blob.properties[:copy_id]
118
+ copy_status = 'pending'
119
+
120
+ @blob.properties[:copy_status] = 'failed'
121
+ @service.stub :get_blob_properties, @blob do
122
+ @service.stub :delete_blob, true do
123
+ assert_raises(RuntimeError) do
124
+ @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status)
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ def test_wait_blob_copy_operation_to_finish_with_fail_when_delete_blob_http_exception
131
+ copy_id = @blob.properties[:copy_id]
132
+ copy_status = 'pending'
133
+
134
+ @blob.properties[:copy_status] = 'failed'
135
+ http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
136
+ @service.stub :get_blob_properties, @blob do
137
+ @service.stub :delete_blob, http_exception do
138
+ assert_raises(RuntimeError) do
139
+ @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status)
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ def test_wait_blob_copy_operation_to_finish_mock
146
+ assert @mock_service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', 'copy_id', 'pending')
147
+ end
148
+ end