fog-azure-rm 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/lib/fog/azurerm/compute.rb +6 -0
  4. data/lib/fog/azurerm/docs/compute.md +67 -11
  5. data/lib/fog/azurerm/docs/network.md +59 -0
  6. data/lib/fog/azurerm/docs/storage.md +107 -35
  7. data/lib/fog/azurerm/models/compute/server.rb +15 -9
  8. data/lib/fog/azurerm/models/compute/virtual_machine_extension.rb +78 -0
  9. data/lib/fog/azurerm/models/compute/virtual_machine_extensions.rb +30 -0
  10. data/lib/fog/azurerm/models/network/express_route_circuit.rb +21 -21
  11. data/lib/fog/azurerm/models/network/express_route_circuit_peering.rb +21 -21
  12. data/lib/fog/azurerm/models/network/express_route_service_provider.rb +8 -8
  13. data/lib/fog/azurerm/models/network/network_security_rule.rb +27 -0
  14. data/lib/fog/azurerm/models/network/network_security_rules.rb +31 -0
  15. data/lib/fog/azurerm/models/network/subnet.rb +16 -12
  16. data/lib/fog/azurerm/models/network/virtual_network_gateway.rb +6 -6
  17. data/lib/fog/azurerm/models/storage/{containers.rb → directories.rb} +10 -10
  18. data/lib/fog/azurerm/models/storage/{container.rb → directory.rb} +13 -13
  19. data/lib/fog/azurerm/models/storage/file.rb +151 -0
  20. data/lib/fog/azurerm/models/storage/files.rb +31 -0
  21. data/lib/fog/azurerm/network.rb +6 -0
  22. data/lib/fog/azurerm/requests/compute/create_or_update_vm_extension.rb +63 -0
  23. data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +45 -8
  24. data/lib/fog/azurerm/requests/compute/delete_vm_extension.rb +28 -0
  25. data/lib/fog/azurerm/requests/compute/get_vm_extension.rb +46 -0
  26. data/lib/fog/azurerm/requests/network/create_or_update_express_route_circuit.rb +44 -31
  27. data/lib/fog/azurerm/requests/network/create_or_update_express_route_circuit_peering.rb +23 -13
  28. data/lib/fog/azurerm/requests/network/create_or_update_network_security_rule.rb +59 -0
  29. data/lib/fog/azurerm/requests/network/create_or_update_virtual_network_gateway.rb +23 -15
  30. data/lib/fog/azurerm/requests/network/delete_network_security_rule.rb +30 -0
  31. data/lib/fog/azurerm/requests/network/get_available_ipaddresses_count.rb +23 -0
  32. data/lib/fog/azurerm/requests/network/get_network_security_rule.rb +47 -0
  33. data/lib/fog/azurerm/requests/network/list_network_security_groups.rb +1 -1
  34. data/lib/fog/azurerm/requests/network/list_network_security_rules.rb +51 -0
  35. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +29 -0
  36. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +29 -0
  37. data/lib/fog/azurerm/requests/storage/check_blob_exist.rb +25 -0
  38. data/lib/fog/azurerm/requests/storage/compare_blob.rb +73 -0
  39. data/lib/fog/azurerm/requests/storage/copy_blob.rb +30 -0
  40. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +30 -0
  41. data/lib/fog/azurerm/requests/storage/delete_blob.rb +27 -0
  42. data/lib/fog/azurerm/requests/storage/download_blob_to_file.rb +56 -0
  43. data/lib/fog/azurerm/requests/storage/get_blob_metadata.rb +37 -9
  44. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +53 -0
  45. data/lib/fog/azurerm/requests/storage/get_container_metadata.rb +2 -2
  46. data/lib/fog/azurerm/requests/storage/list_blobs.rb +82 -0
  47. data/lib/fog/azurerm/requests/storage/list_containers.rb +1 -1
  48. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +27 -0
  49. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +27 -0
  50. data/lib/fog/azurerm/requests/storage/set_blob_metadata.rb +4 -4
  51. data/lib/fog/azurerm/requests/storage/set_blob_properties.rb +26 -0
  52. data/lib/fog/azurerm/requests/storage/set_container_metadata.rb +3 -3
  53. data/lib/fog/azurerm/requests/storage/upload_block_blob_from_file.rb +60 -0
  54. data/lib/fog/azurerm/storage.rb +26 -8
  55. data/lib/fog/azurerm/utilities/general.rb +14 -1
  56. data/lib/fog/azurerm/version.rb +1 -1
  57. data/test/api_stub.rb +8 -4
  58. data/test/api_stub/models/compute/virtual_machine_extension.rb +31 -0
  59. data/test/api_stub/models/network/network_security_rule.rb +30 -0
  60. data/test/api_stub/models/storage/{container.rb → directory.rb} +1 -1
  61. data/test/api_stub/models/storage/file.rb +178 -0
  62. data/test/api_stub/requests/compute/virtual_machine.rb +119 -0
  63. data/test/api_stub/requests/compute/virtual_machine_extension.rb +46 -0
  64. data/test/api_stub/requests/network/network_security_rule.rb +72 -0
  65. data/test/api_stub/requests/storage/{container.rb → directory.rb} +2 -2
  66. data/test/api_stub/requests/storage/file.rb +164 -0
  67. data/test/integration/availability_set.rb +6 -0
  68. data/test/integration/blob.rb +205 -0
  69. data/test/integration/credentials/azure.yml +4 -4
  70. data/test/integration/deployment.rb +9 -0
  71. data/test/integration/external_load_balancer.rb +9 -0
  72. data/test/integration/internal_load_balancer.rb +8 -0
  73. data/test/integration/network_security_group.rb +9 -0
  74. data/test/integration/network_security_rule.rb +86 -0
  75. data/test/integration/server.rb +62 -9
  76. data/test/integration/server_custom_image.rb +118 -0
  77. data/test/integration/subnet.rb +12 -1
  78. data/test/integration/virtual_machine_extension.rb +148 -0
  79. data/test/integration/virtual_network.rb +9 -1
  80. data/test/integration/virtual_network_gateway.rb +7 -29
  81. data/test/integration/virtual_network_gateway_connection_to_express_route.rb +116 -0
  82. data/test/models/compute/test_virtual_machine_extension.rb +61 -0
  83. data/test/models/compute/test_virtual_machine_extensions.rb +36 -0
  84. data/test/models/network/test_express_route_circuit.rb +4 -10
  85. data/test/models/network/test_express_route_circuit_peering.rb +4 -10
  86. data/test/models/network/test_network_interface.rb +4 -8
  87. data/test/models/network/test_network_security_rule.rb +14 -0
  88. data/test/models/network/test_network_security_rules.rb +42 -0
  89. data/test/models/network/test_subnet.rb +5 -0
  90. data/test/models/storage/test_directories.rb +106 -0
  91. data/test/models/storage/test_directory.rb +125 -0
  92. data/test/models/storage/test_file.rb +258 -0
  93. data/test/models/storage/test_files.rb +67 -0
  94. data/test/models/storage/test_storage_account.rb +2 -4
  95. data/test/requests/compute/test_create_virtual_machine.rb +19 -5
  96. data/test/requests/compute/test_create_vm_extension.rb +35 -0
  97. data/test/requests/compute/test_get_vm_extension.rb +26 -0
  98. data/test/requests/compute/test_update_vm_extension.rb +35 -0
  99. data/test/requests/network/test_create_or_update_network_security_rule.rb +28 -0
  100. data/test/requests/network/test_delete_network_security_rule.rb +25 -0
  101. data/test/requests/network/test_get_available_ipaddresses_count.rb +18 -0
  102. data/test/requests/network/test_get_network_security_rule.rb +26 -0
  103. data/test/requests/network/test_list_network_security_groups.rb +2 -2
  104. data/test/requests/network/test_list_network_security_rules.rb +26 -0
  105. data/test/requests/storage/test_acquire_blob_lease.rb +17 -0
  106. data/test/requests/storage/test_acquire_container_lease.rb +17 -0
  107. data/test/requests/storage/test_check_blob_exist.rb +17 -0
  108. data/test/requests/storage/test_compare_blob.rb +17 -0
  109. data/test/requests/storage/test_copy_blob.rb +17 -0
  110. data/test/requests/storage/test_copy_blob_from_uri.rb +17 -0
  111. data/test/requests/storage/test_create_container.rb +2 -2
  112. data/test/requests/storage/test_delete_blob.rb +22 -0
  113. data/test/requests/storage/test_delete_container.rb +1 -1
  114. data/test/requests/storage/test_download_blob_to_file.rb +25 -0
  115. data/test/requests/storage/test_get_blob_metadata.rb +2 -2
  116. data/test/requests/storage/test_get_blob_properties.rb +23 -0
  117. data/test/requests/storage/test_get_container_access_control_list.rb +2 -2
  118. data/test/requests/storage/test_get_container_metadata.rb +2 -2
  119. data/test/requests/storage/test_get_container_properties.rb +2 -2
  120. data/test/requests/storage/test_list_blobs_in_container.rb +23 -0
  121. data/test/requests/storage/test_list_containers.rb +2 -2
  122. data/test/requests/storage/test_release_blob_lease.rb +16 -0
  123. data/test/requests/storage/test_release_container_lease.rb +16 -0
  124. data/test/requests/storage/test_set_blob_metadata.rb +1 -1
  125. data/test/requests/storage/test_set_blob_properties.rb +16 -0
  126. data/test/requests/storage/test_set_container_metadata.rb +1 -1
  127. data/test/requests/storage/test_upload_block_blob_from_file.rb +23 -0
  128. data/test/test_helper.rb +116 -3
  129. metadata +73 -15
  130. data/.DS_Store +0 -0
  131. data/lib/fog/azurerm/fog_azure_rm_exception.rb +0 -13
  132. data/lib/fog/azurerm/models/storage/blob.rb +0 -13
  133. data/lib/fog/azurerm/models/storage/blobs.rb +0 -22
  134. data/test/api_stub/models/storage/blob.rb +0 -17
  135. data/test/api_stub/requests/storage/blob.rb +0 -24
  136. data/test/models/storage/test_blobs.rb +0 -32
  137. data/test/models/storage/test_container.rb +0 -67
  138. data/test/models/storage/test_containers.rb +0 -56
@@ -0,0 +1,61 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Test class for VirtualMachineExtension Model
4
+ class TestVirtualMachineExtension < Minitest::Test
5
+ def setup
6
+ @service = Fog::Compute::AzureRM.new(credentials)
7
+ @virtual_machine_extension = virtual_machine_extension(@service)
8
+ @compute_client = @service.instance_variable_get(:@compute_mgmt_client)
9
+ end
10
+
11
+ def test_model_methods
12
+ methods = [
13
+ :save,
14
+ :update,
15
+ :destroy
16
+ ]
17
+ methods.each do |method|
18
+ assert @virtual_machine_extension.respond_to? method, true
19
+ end
20
+ end
21
+
22
+ def test_model_attributes
23
+ attributes = [
24
+ :id,
25
+ :name,
26
+ :resource_group,
27
+ :location,
28
+ :vm_name,
29
+ :type,
30
+ :publisher,
31
+ :type_handler_version,
32
+ :auto_upgrade_minor_version,
33
+ :settings,
34
+ :protected_settings
35
+ ]
36
+ attributes.each do |attribute|
37
+ assert @virtual_machine_extension.respond_to? attribute, true
38
+ end
39
+ end
40
+
41
+ def test_save_method_response
42
+ response = ApiStub::Models::Compute::VirtualMachineExtension.create_vm_extension_response(@compute_client)
43
+ @service.stub :create_or_update_vm_extension, response do
44
+ assert_instance_of Fog::Compute::AzureRM::VirtualMachineExtension, @virtual_machine_extension.save
45
+ end
46
+ end
47
+
48
+ def test_update_method_response
49
+ response = ApiStub::Models::Compute::VirtualMachineExtension.create_vm_extension_response(@compute_client)
50
+ @service.stub :create_or_update_vm_extension, response do
51
+ assert_instance_of Fog::Compute::AzureRM::VirtualMachineExtension, @virtual_machine_extension.update({})
52
+ end
53
+ end
54
+
55
+ def test_destroy_method_response
56
+ response = MsRestAzure::AzureOperationResponse.new(MsRest::HttpOperationRequest.new('', '', ''), Faraday::Response.new)
57
+ @service.stub :delete_vm_extension, response do
58
+ assert_instance_of MsRestAzure::AzureOperationResponse, @virtual_machine_extension.destroy
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ class TestVirtualMachineExtensions < Minitest::Test
4
+ def setup
5
+ @service = Fog::Compute::AzureRM.new(credentials)
6
+ @vm_extensions = Fog::Compute::AzureRM::VirtualMachineExtensions.new(resource_group: 'fog-test-rg', service: @service)
7
+ @compute_client = @service.instance_variable_get(:@compute_mgmt_client)
8
+ @response = ApiStub::Models::Compute::VirtualMachineExtension.create_vm_extension_response(@compute_client)
9
+ end
10
+
11
+ def test_collection_methods
12
+ methods = [
13
+ :all,
14
+ :get
15
+ ]
16
+ methods.each do |method|
17
+ assert @vm_extensions.respond_to? method, true
18
+ end
19
+ end
20
+
21
+ def test_collection_attributes
22
+ attributes = [
23
+ :resource_group,
24
+ :vm_name
25
+ ]
26
+ attributes.each do |attribute|
27
+ assert @vm_extensions.respond_to? attribute, true
28
+ end
29
+ end
30
+
31
+ def test_get_method_response
32
+ @service.stub :get_vm_extension, @response do
33
+ assert_instance_of Fog::Compute::AzureRM::VirtualMachineExtension, @vm_extensions.get('fog-test-rg', 'fog-test-server', 'fog-test-extension')
34
+ end
35
+ end
36
+ end
@@ -9,20 +9,16 @@ class TestExpressRouteCircuit < Minitest::Test
9
9
  end
10
10
 
11
11
  def test_model_methods
12
- response = ApiStub::Models::Network::ExpressRouteCircuit.create_express_route_circuit_response(@network_client)
13
12
  methods = [
14
13
  :save,
15
14
  :destroy
16
15
  ]
17
- @service.stub :create_or_update_express_route_circuit, response do
18
- methods.each do |method|
19
- assert @circuit.respond_to? method
20
- end
16
+ methods.each do |method|
17
+ assert @circuit.respond_to? method
21
18
  end
22
19
  end
23
20
 
24
21
  def test_model_attributes
25
- response = ApiStub::Models::Network::ExpressRouteCircuit.create_express_route_circuit_response(@network_client)
26
22
  attributes = [
27
23
  :resource_group,
28
24
  :name,
@@ -36,10 +32,8 @@ class TestExpressRouteCircuit < Minitest::Test
36
32
  :bandwidth_in_mbps,
37
33
  :peerings
38
34
  ]
39
- @service.stub :create_or_update_express_route_circuit, response do
40
- attributes.each do |attribute|
41
- assert @circuit.respond_to? attribute
42
- end
35
+ attributes.each do |attribute|
36
+ assert @circuit.respond_to? attribute
43
37
  end
44
38
  end
45
39
 
@@ -9,20 +9,16 @@ class TestExpressRouteCircuitPeering < Minitest::Test
9
9
  end
10
10
 
11
11
  def test_model_methods
12
- response = ApiStub::Models::Network::ExpressRouteCircuitPeering.create_express_route_circuit_peering_response(@network_client)
13
12
  methods = [
14
13
  :save,
15
14
  :destroy
16
15
  ]
17
- @service.stub :create_or_update_express_route_circuit_peering, response do
18
- methods.each do |method|
19
- assert @circuit_peering.respond_to? method
20
- end
16
+ methods.each do |method|
17
+ assert @circuit_peering.respond_to? method
21
18
  end
22
19
  end
23
20
 
24
21
  def test_model_attributes
25
- response = ApiStub::Models::Network::ExpressRouteCircuitPeering.create_express_route_circuit_peering_response(@network_client)
26
22
  attributes = [
27
23
  :resource_group,
28
24
  :name,
@@ -37,10 +33,8 @@ class TestExpressRouteCircuitPeering < Minitest::Test
37
33
  :customer_asn,
38
34
  :routing_registry_name
39
35
  ]
40
- @service.stub :create_or_update_express_route_circuit_peering, response do
41
- attributes.each do |attribute|
42
- assert @circuit_peering.respond_to? attribute
43
- end
36
+ attributes.each do |attribute|
37
+ assert @circuit_peering.respond_to? attribute
44
38
  end
45
39
  end
46
40
 
@@ -19,10 +19,8 @@ class TestNetworkInterface < Minitest::Test
19
19
  :detach_public_ip,
20
20
  :detach_network_security_group
21
21
  ]
22
- @service.stub :create_or_update_network_interface, @response do
23
- methods.each do |method|
24
- assert @network_interface.respond_to? method
25
- end
22
+ methods.each do |method|
23
+ assert @network_interface.respond_to? method
26
24
  end
27
25
  end
28
26
 
@@ -48,10 +46,8 @@ class TestNetworkInterface < Minitest::Test
48
46
  :internal_dns_name_label,
49
47
  :internal_fqd
50
48
  ]
51
- @service.stub :create_or_update_network_interface, @response do
52
- attributes.each do |attribute|
53
- assert @network_interface.respond_to? attribute
54
- end
49
+ attributes.each do |attribute|
50
+ assert @network_interface.respond_to? attribute
55
51
  end
56
52
  end
57
53
 
@@ -4,6 +4,7 @@ require File.expand_path '../../test_helper', __dir__
4
4
  class TestNetworkSecurityRule < Minitest::Test
5
5
  def setup
6
6
  @service = Fog::Network::AzureRM.new(credentials)
7
+ @client = @service.instance_variable_get(:@network_client)
7
8
  @network_security_rule = network_security_rule(@service)
8
9
  end
9
10
 
@@ -27,4 +28,17 @@ class TestNetworkSecurityRule < Minitest::Test
27
28
  assert @network_security_rule.respond_to? attribute
28
29
  end
29
30
  end
31
+
32
+ def test_save_method_response
33
+ response = ApiStub::Models::Network::NetworkSecurityRule.create_network_security_rule_response(@client)
34
+ @service.stub :create_or_update_network_security_rule, response do
35
+ assert_instance_of Fog::Network::AzureRM::NetworkSecurityRule, @network_security_rule.save
36
+ end
37
+ end
38
+
39
+ def test_destroy_method_response
40
+ @service.stub :delete_network_security_rule, true do
41
+ assert @network_security_rule.destroy
42
+ end
43
+ end
30
44
  end
@@ -0,0 +1,42 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Test class for Network Security Rule Collection
4
+ class TestNetworkSecurityRules < Minitest::Test
5
+ def setup
6
+ @service = Fog::Network::AzureRM.new(credentials)
7
+ client = @service.instance_variable_get(:@network_client)
8
+ @network_security_rules = Fog::Network::AzureRM::NetworkSecurityRules.new(resource_group: 'fog-test-rg', network_security_group_name: 'fog-test-nsg', service: @service)
9
+ @response = [ApiStub::Models::Network::NetworkSecurityRule.create_network_security_rule_response(client)]
10
+ end
11
+
12
+ def test_collection_methods
13
+ methods = [
14
+ :all,
15
+ :get
16
+ ]
17
+ methods.each do |method|
18
+ assert @network_security_rules.respond_to? method
19
+ end
20
+ end
21
+
22
+ def test_collection_attributes
23
+ assert @network_security_rules.respond_to? :resource_group
24
+ assert @network_security_rules.respond_to? :network_security_group_name
25
+ end
26
+
27
+ def test_all_method_response
28
+ @service.stub :list_network_security_rules, @response do
29
+ assert_instance_of Fog::Network::AzureRM::NetworkSecurityRules, @network_security_rules.all
30
+ assert @network_security_rules.all.size >= 1
31
+ @network_security_rules.all.each do |nsr|
32
+ assert_instance_of Fog::Network::AzureRM::NetworkSecurityRule, nsr
33
+ end
34
+ end
35
+ end
36
+
37
+ def test_get_method_response
38
+ @service.stub :get_network_security_rule, @response[0] do
39
+ assert_instance_of Fog::Network::AzureRM::NetworkSecurityRule, @network_security_rules.get('fog-test-rg', 'fog-test-nsg', 'fog-test-nsr')
40
+ end
41
+ end
42
+ end
@@ -16,6 +16,7 @@ class TestSubnet < Minitest::Test
16
16
  :detach_network_security_group,
17
17
  :attach_route_table,
18
18
  :detach_route_table,
19
+ :get_available_ipaddresses_count,
19
20
  :destroy
20
21
  ]
21
22
 
@@ -70,6 +71,10 @@ class TestSubnet < Minitest::Test
70
71
  end
71
72
  end
72
73
 
74
+ def test_get_available_ipaddresses_count_response
75
+ assert_instance_of Fixnum, @subnet.get_available_ipaddresses_count(false)
76
+ end
77
+
73
78
  def test_destroy_method_response
74
79
  @service.stub :delete_subnet, true do
75
80
  assert @subnet.destroy
@@ -0,0 +1,106 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Test class for Container Collection
4
+ class TestDirectories < Minitest::Test
5
+ def setup
6
+ Fog.mock!
7
+ @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_directories = Fog::Storage::AzureRM::Directories.new(service: @mock_service)
9
+ Fog.unmock!
10
+ @service = Fog::Storage::AzureRM.new(storage_account_credentials)
11
+ @blob_client = @service.instance_variable_get(:@blob_client)
12
+ @directories = Fog::Storage::AzureRM::Directories.new(service: @service)
13
+ @get_metadata_result = ApiStub::Models::Storage::Directory.test_get_container_metadata
14
+ @list_results = ApiStub::Models::Storage::Directory.list_containers
15
+ @acl_results = ApiStub::Models::Storage::Directory.get_container_access_control_list
16
+ @mocked_response = mocked_storage_http_error
17
+ end
18
+
19
+ def test_collection_methods
20
+ methods = [
21
+ :get_metadata,
22
+ :set_metadata,
23
+ :all,
24
+ :get
25
+ ]
26
+ methods.each do |method|
27
+ assert @directories.respond_to? method, true
28
+ end
29
+ end
30
+
31
+ def test_all_method_http_exception
32
+ http_exception = -> (_option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
33
+ @blob_client.stub :list_containers, http_exception do
34
+ assert_raises(RuntimeError) do
35
+ @directories.all
36
+ end
37
+ end
38
+ end
39
+
40
+ def test_all_method_mock
41
+ assert_instance_of Fog::Storage::AzureRM::Directories, @mock_directories.all
42
+ assert @mock_directories.all.size >= 1
43
+ @mock_directories.all.each do |directory|
44
+ assert_instance_of Fog::Storage::AzureRM::Directory, directory
45
+ end
46
+ end
47
+
48
+ def test_get_container_metadata
49
+ @service.stub :get_container_metadata, @get_metadata_result do
50
+ assert_equal @get_metadata_result, @directories.get_metadata('Test-container')
51
+ end
52
+ end
53
+
54
+ def test_get_container_metadata_http_exception
55
+ http_exception = -> (_container_name, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
56
+ @blob_client.stub :get_container_metadata, http_exception do
57
+ assert_raises(RuntimeError) do
58
+ @directories.get_metadata 'Test-container'
59
+ end
60
+ end
61
+ end
62
+
63
+ def test_get_container_metadata_mock
64
+ directory = @mock_directories.get_metadata 'Test-container'
65
+ assert_instance_of Hash, directory
66
+ end
67
+
68
+ def test_set_container_metadata
69
+ @service.stub :set_container_metadata, true do
70
+ assert @directories.set_metadata('Test-container', @get_metadata_result)
71
+ end
72
+ end
73
+
74
+ def test_set_container_metadata_http_exception
75
+ http_exception = -> (_container_name, _metadata, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
76
+ @blob_client.stub :set_container_metadata, http_exception do
77
+ assert_raises(RuntimeError) do
78
+ @directories.set_metadata 'Test-container', @get_metadata_result
79
+ end
80
+ end
81
+ end
82
+
83
+ def test_set_container_metadata_mock
84
+ assert @mock_directories.set_metadata('Test-container', @get_metadata_result)
85
+ end
86
+
87
+ def test_all_method
88
+ directories = Fog::Storage::AzureRM::Directories.new(service: @service)
89
+ @service.stub :list_containers, @list_results do
90
+ assert_instance_of Fog::Storage::AzureRM::Directories, directories.all
91
+ assert directories.all.size >= 1
92
+ directories.all.each do |directory|
93
+ assert_instance_of Fog::Storage::AzureRM::Directory, directory
94
+ end
95
+ end
96
+ end
97
+
98
+ def test_get_method
99
+ @service.stub :list_containers, @list_results do
100
+ @service.stub :get_container_access_control_list, @acl_results do
101
+ assert_instance_of Fog::Storage::AzureRM::Directory, @directories.get('testcontainer1')
102
+ assert @directories.get('wrong-name').nil?, true
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,125 @@
1
+ require File.expand_path '../../test_helper', __dir__
2
+
3
+ # Test class for Storage Container Model
4
+ class TestDirectory < Minitest::Test
5
+ def setup
6
+ Fog.mock!
7
+ @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
+ @mock_directory = storage_container(@mock_service)
9
+ Fog.unmock!
10
+ @service = Fog::Storage::AzureRM.new(storage_account_credentials)
11
+ @directory = storage_container(@service)
12
+ @create_result = ApiStub::Models::Storage::Directory.create_container
13
+ @get_properties_result = ApiStub::Models::Storage::Directory.get_container_properties
14
+ @get_access_control_list_result = ApiStub::Models::Storage::Directory.get_container_access_control_list
15
+ @blob_client = @service.instance_variable_get(:@blob_client)
16
+ @mocked_response = mocked_storage_http_error
17
+ end
18
+
19
+ def test_model_methods
20
+ methods = [
21
+ :save,
22
+ :create,
23
+ :destroy
24
+ ]
25
+ methods.each do |method|
26
+ assert @directory.respond_to? method, true
27
+ end
28
+ end
29
+
30
+ def test_model_attributes
31
+ attributes = [
32
+ :key,
33
+ :etag,
34
+ :last_modified,
35
+ :lease_duration,
36
+ :lease_state,
37
+ :lease_status,
38
+ :metadata
39
+ ]
40
+ @service.stub :create_container, @create_result do
41
+ attributes.each do |attribute|
42
+ assert_respond_to @directory, attribute
43
+ end
44
+ end
45
+ end
46
+
47
+ def test_save_method_response
48
+ @service.stub :create_container, @create_result do
49
+ assert_instance_of Fog::Storage::AzureRM::Directory, @directory.save
50
+ end
51
+ @service.stub :create_container, @create_result do
52
+ assert_instance_of Fog::Storage::AzureRM::Directory, @directory.create
53
+ end
54
+ end
55
+
56
+ def test_save_http_exception
57
+ http_exception = -> (_container_name, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
58
+ @blob_client.stub :create_container, http_exception do
59
+ assert_raises(RuntimeError) do
60
+ @directory.save
61
+ end
62
+ end
63
+ end
64
+
65
+ def test_save_mock
66
+ assert_instance_of Fog::Storage::AzureRM::Directory, @mock_directory.save
67
+ end
68
+
69
+ def test_get_container_properties_method_response
70
+ @service.stub :get_container_properties, @get_properties_result do
71
+ assert_instance_of Fog::Storage::AzureRM::Directory, @directory.get_properties
72
+ end
73
+ end
74
+
75
+ def test_get_container_properties_http_exception
76
+ http_exception = -> (_container_name, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
77
+ @blob_client.stub :get_container_properties, http_exception do
78
+ assert_raises(RuntimeError) do
79
+ @directory.get_properties
80
+ end
81
+ end
82
+ end
83
+
84
+ def test_get_container_properties_mock
85
+ assert_instance_of Fog::Storage::AzureRM::Directory, @mock_directory.get_properties
86
+ end
87
+
88
+ def test_get_access_control_list_method_response
89
+ @service.stub :get_container_access_control_list, @get_access_control_list_result do
90
+ assert_instance_of Fog::Storage::AzureRM::Directory, @directory.access_control_list
91
+ end
92
+ end
93
+
94
+ def test_get_access_control_list_http_exception
95
+ http_exception = -> (_container_name, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
96
+ @blob_client.stub :get_container_acl, http_exception do
97
+ assert_raises(RuntimeError) do
98
+ @directory.access_control_list
99
+ end
100
+ end
101
+ end
102
+
103
+ def test_get_access_control_list_mock
104
+ assert_instance_of Fog::Storage::AzureRM::Directory, @mock_directory.access_control_list
105
+ end
106
+
107
+ def test_delete_method_true_response
108
+ @service.stub :delete_container, true do
109
+ assert @directory.destroy
110
+ end
111
+ end
112
+
113
+ def test_delete_method_exception
114
+ exception = -> (_container_name, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
115
+ @blob_client.stub :delete_container, exception do
116
+ assert_raises(RuntimeError) do
117
+ assert @directory.destroy
118
+ end
119
+ end
120
+ end
121
+
122
+ def test_delete_method_response_mock
123
+ assert @mock_directory.destroy
124
+ end
125
+ end