fog-azure-rm 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +2 -1
  4. data/fog-azure-rm.gemspec +11 -9
  5. data/lib/fog/azurerm.rb +1 -0
  6. data/lib/fog/azurerm/compute.rb +3 -3
  7. data/lib/fog/azurerm/config.rb +33 -0
  8. data/lib/fog/azurerm/credentials.rb +1 -1
  9. data/lib/fog/azurerm/dns.rb +2 -2
  10. data/lib/fog/azurerm/docs/storage.md +120 -66
  11. data/lib/fog/azurerm/models/application_gateway/gateway.rb +30 -31
  12. data/lib/fog/azurerm/models/application_gateway/gateways.rb +4 -4
  13. data/lib/fog/azurerm/models/compute/availability_sets.rb +4 -4
  14. data/lib/fog/azurerm/models/compute/server.rb +14 -14
  15. data/lib/fog/azurerm/models/compute/servers.rb +4 -4
  16. data/lib/fog/azurerm/models/compute/virtual_machine_extension.rb +3 -5
  17. data/lib/fog/azurerm/models/compute/virtual_machine_extensions.rb +5 -5
  18. data/lib/fog/azurerm/models/dns/record_sets.rb +4 -4
  19. data/lib/fog/azurerm/models/dns/zones.rb +4 -4
  20. data/lib/fog/azurerm/models/network/express_route_circuit.rb +2 -5
  21. data/lib/fog/azurerm/models/network/express_route_circuit_authorization.rb +1 -1
  22. data/lib/fog/azurerm/models/network/express_route_circuit_authorizations.rb +4 -4
  23. data/lib/fog/azurerm/models/network/express_route_circuit_peering.rb +3 -5
  24. data/lib/fog/azurerm/models/network/express_route_circuit_peerings.rb +4 -4
  25. data/lib/fog/azurerm/models/network/express_route_circuits.rb +4 -4
  26. data/lib/fog/azurerm/models/network/express_route_service_providers.rb +2 -2
  27. data/lib/fog/azurerm/models/network/load_balancers.rb +5 -5
  28. data/lib/fog/azurerm/models/network/local_network_gateway.rb +1 -1
  29. data/lib/fog/azurerm/models/network/local_network_gateways.rb +4 -4
  30. data/lib/fog/azurerm/models/network/network_interfaces.rb +5 -5
  31. data/lib/fog/azurerm/models/network/network_security_groups.rb +5 -5
  32. data/lib/fog/azurerm/models/network/network_security_rule.rb +3 -4
  33. data/lib/fog/azurerm/models/network/network_security_rules.rb +4 -4
  34. data/lib/fog/azurerm/models/network/public_ips.rb +4 -4
  35. data/lib/fog/azurerm/models/network/subnets.rb +4 -4
  36. data/lib/fog/azurerm/models/network/virtual_network_gateway.rb +6 -7
  37. data/lib/fog/azurerm/models/network/virtual_network_gateway_connection.rb +5 -5
  38. data/lib/fog/azurerm/models/network/virtual_network_gateway_connections.rb +4 -4
  39. data/lib/fog/azurerm/models/network/virtual_network_gateways.rb +4 -4
  40. data/lib/fog/azurerm/models/network/virtual_networks.rb +4 -4
  41. data/lib/fog/azurerm/models/resources/azure_resources.rb +2 -2
  42. data/lib/fog/azurerm/models/resources/deployments.rb +4 -4
  43. data/lib/fog/azurerm/models/resources/resource_groups.rb +4 -4
  44. data/lib/fog/azurerm/models/sql/firewall_rule.rb +1 -1
  45. data/lib/fog/azurerm/models/sql/firewall_rules.rb +4 -4
  46. data/lib/fog/azurerm/models/sql/sql_database.rb +28 -24
  47. data/lib/fog/azurerm/models/sql/sql_databases.rb +5 -6
  48. data/lib/fog/azurerm/models/sql/sql_servers.rb +4 -4
  49. data/lib/fog/azurerm/models/storage/directories.rb +49 -24
  50. data/lib/fog/azurerm/models/storage/directory.rb +126 -40
  51. data/lib/fog/azurerm/models/storage/file.rb +226 -114
  52. data/lib/fog/azurerm/models/storage/files.rb +168 -13
  53. data/lib/fog/azurerm/models/storage/recovery_vault.rb +1 -1
  54. data/lib/fog/azurerm/models/storage/recovery_vaults.rb +4 -4
  55. data/lib/fog/azurerm/models/storage/storage_account.rb +5 -5
  56. data/lib/fog/azurerm/models/storage/storage_accounts.rb +4 -4
  57. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_end_point.rb +1 -1
  58. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_end_points.rb +4 -4
  59. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profile.rb +4 -4
  60. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profiles.rb +4 -4
  61. data/lib/fog/azurerm/network.rb +1 -1
  62. data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +17 -13
  63. data/lib/fog/azurerm/requests/network/list_virtual_networks.rb +1 -1
  64. data/lib/fog/azurerm/requests/resources/create_deployment.rb +1 -1
  65. data/lib/fog/azurerm/requests/resources/create_resource_group.rb +1 -1
  66. data/lib/fog/azurerm/requests/resources/delete_deployment.rb +1 -1
  67. data/lib/fog/azurerm/requests/resources/delete_resource_group.rb +1 -1
  68. data/lib/fog/azurerm/requests/resources/get_deployment.rb +1 -1
  69. data/lib/fog/azurerm/requests/resources/get_resource_group.rb +1 -1
  70. data/lib/fog/azurerm/requests/resources/list_deployments.rb +1 -1
  71. data/lib/fog/azurerm/requests/resources/list_resource_groups.rb +1 -1
  72. data/lib/fog/azurerm/requests/resources/list_tagged_resources.rb +1 -1
  73. data/lib/fog/azurerm/requests/resources/tag_resource.rb +1 -1
  74. data/lib/fog/azurerm/requests/sql/create_or_update_database.rb +3 -3
  75. data/lib/fog/azurerm/requests/sql/create_or_update_firewall_rule.rb +3 -3
  76. data/lib/fog/azurerm/requests/sql/create_or_update_sql_server.rb +3 -3
  77. data/lib/fog/azurerm/requests/sql/delete_database.rb +2 -2
  78. data/lib/fog/azurerm/requests/sql/delete_firewall_rule.rb +4 -4
  79. data/lib/fog/azurerm/requests/sql/delete_sql_server.rb +4 -4
  80. data/lib/fog/azurerm/requests/sql/get_database.rb +3 -3
  81. data/lib/fog/azurerm/requests/sql/get_firewall_rule.rb +3 -3
  82. data/lib/fog/azurerm/requests/sql/get_sql_server.rb +3 -3
  83. data/lib/fog/azurerm/requests/sql/list_databases.rb +3 -3
  84. data/lib/fog/azurerm/requests/sql/list_firewall_rules.rb +3 -3
  85. data/lib/fog/azurerm/requests/sql/list_sql_servers.rb +3 -3
  86. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +5 -2
  87. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +5 -2
  88. data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
  89. data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
  90. data/lib/fog/azurerm/requests/storage/copy_blob.rb +8 -8
  91. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +8 -8
  92. data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
  93. data/lib/fog/azurerm/requests/storage/create_container.rb +12 -10
  94. data/lib/fog/azurerm/requests/storage/create_disk.rb +45 -19
  95. data/lib/fog/azurerm/requests/storage/create_or_update_recovery_vault.rb +2 -2
  96. data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
  97. data/lib/fog/azurerm/requests/storage/create_storage_account.rb +2 -2
  98. data/lib/fog/azurerm/requests/storage/delete_blob.rb +10 -5
  99. data/lib/fog/azurerm/requests/storage/delete_container.rb +6 -2
  100. data/lib/fog/azurerm/requests/storage/delete_disk.rb +19 -16
  101. data/lib/fog/azurerm/requests/storage/get_all_backup_jobs.rb +2 -2
  102. data/lib/fog/azurerm/requests/storage/get_backup_container.rb +2 -2
  103. data/lib/fog/azurerm/requests/storage/get_backup_item.rb +2 -2
  104. data/lib/fog/azurerm/requests/storage/get_backup_job_for_vm.rb +1 -1
  105. data/lib/fog/azurerm/requests/storage/get_backup_protection_policy.rb +2 -2
  106. data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
  107. data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
  108. data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
  109. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +37 -35
  110. data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
  111. data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
  112. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +16 -12
  113. data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
  114. data/lib/fog/azurerm/requests/storage/get_recovery_vault.rb +2 -2
  115. data/lib/fog/azurerm/requests/storage/get_storage_access_keys.rb +4 -3
  116. data/lib/fog/azurerm/requests/storage/get_storage_account.rb +2 -2
  117. data/lib/fog/azurerm/requests/storage/list_blobs.rb +110 -24
  118. data/lib/fog/azurerm/requests/storage/list_containers.rb +46 -23
  119. data/lib/fog/azurerm/requests/storage/list_recovery_vaults.rb +2 -2
  120. data/lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb +2 -2
  121. data/lib/fog/azurerm/requests/storage/list_storage_accounts.rb +2 -2
  122. data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
  123. data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
  124. data/lib/fog/azurerm/requests/storage/{set_blob_metadata.rb → put_blob_metadata.rb} +7 -3
  125. data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
  126. data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
  127. data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
  128. data/lib/fog/azurerm/requests/storage/{set_container_metadata.rb → put_container_metadata.rb} +7 -3
  129. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +4 -1
  130. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +4 -1
  131. data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
  132. data/lib/fog/azurerm/requests/storage/start_backup.rb +1 -1
  133. data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
  134. data/lib/fog/azurerm/resources.rb +2 -2
  135. data/lib/fog/azurerm/storage.rb +33 -19
  136. data/lib/fog/azurerm/traffic_manager.rb +1 -1
  137. data/lib/fog/azurerm/utilities/general.rb +70 -3
  138. data/lib/fog/azurerm/version.rb +1 -1
  139. data/rake-script.sh +5 -2
  140. data/test/api_stub/models/application_gateway/gateway.rb +1 -1
  141. data/test/api_stub/models/compute/server.rb +1 -1
  142. data/test/api_stub/models/dns/record_set.rb +2 -2
  143. data/test/api_stub/models/dns/zone.rb +1 -1
  144. data/test/api_stub/models/network/express_route_circuit.rb +1 -1
  145. data/test/api_stub/models/network/express_route_circuit_authorization.rb +1 -1
  146. data/test/api_stub/models/network/express_route_circuit_peering.rb +1 -1
  147. data/test/api_stub/models/network/express_route_service_provider.rb +1 -1
  148. data/test/api_stub/models/network/load_balancer.rb +1 -1
  149. data/test/api_stub/models/network/network_interface.rb +1 -1
  150. data/test/api_stub/models/network/network_security_group.rb +1 -1
  151. data/test/api_stub/models/network/network_security_rule.rb +1 -1
  152. data/test/api_stub/models/network/public_ip.rb +1 -1
  153. data/test/api_stub/models/network/subnet.rb +1 -1
  154. data/test/api_stub/models/network/virtual_network.rb +1 -1
  155. data/test/api_stub/models/network/virtual_network_gateway.rb +1 -1
  156. data/test/api_stub/models/network/virtual_network_gateway_connection.rb +1 -1
  157. data/test/api_stub/models/resources/resource.rb +2 -2
  158. data/test/api_stub/models/resources/resource_group.rb +1 -1
  159. data/test/api_stub/models/storage/directory.rb +148 -62
  160. data/test/api_stub/models/storage/file.rb +122 -119
  161. data/test/api_stub/models/traffic_manager/traffic_manager_end_point.rb +1 -1
  162. data/test/api_stub/models/traffic_manager/traffic_manager_profile.rb +1 -1
  163. data/test/api_stub/requests/application_gateway/gateway.rb +2 -2
  164. data/test/api_stub/requests/compute/availability_set.rb +3 -3
  165. data/test/api_stub/requests/compute/virtual_machine.rb +9 -9
  166. data/test/api_stub/requests/dns/record_set.rb +3 -3
  167. data/test/api_stub/requests/dns/zone.rb +18 -18
  168. data/test/api_stub/requests/network/express_route_circuit.rb +2 -2
  169. data/test/api_stub/requests/network/express_route_circuit_authorization.rb +1 -1
  170. data/test/api_stub/requests/network/express_route_circuit_peering.rb +2 -2
  171. data/test/api_stub/requests/network/express_route_service_provider.rb +1 -1
  172. data/test/api_stub/requests/network/load_balancer.rb +2 -2
  173. data/test/api_stub/requests/network/network_interface.rb +4 -4
  174. data/test/api_stub/requests/network/network_security_group.rb +3 -3
  175. data/test/api_stub/requests/network/network_security_rule.rb +2 -2
  176. data/test/api_stub/requests/network/public_ip.rb +2 -2
  177. data/test/api_stub/requests/network/subnet.rb +2 -2
  178. data/test/api_stub/requests/network/virtual_network.rb +2 -2
  179. data/test/api_stub/requests/network/virtual_network_gateway.rb +2 -2
  180. data/test/api_stub/requests/network/virtual_network_gateway_connection.rb +3 -3
  181. data/test/api_stub/requests/resources/resource.rb +2 -2
  182. data/test/api_stub/requests/resources/resource_group.rb +2 -2
  183. data/test/api_stub/requests/storage/directory.rb +59 -65
  184. data/test/api_stub/requests/storage/file.rb +183 -113
  185. data/test/api_stub/requests/storage/storageaccount.rb +1 -1
  186. data/test/api_stub/requests/traffic_manager/traffic_manager_endpoint.rb +1 -1
  187. data/test/api_stub/requests/traffic_manager/traffic_manager_profile.rb +2 -2
  188. data/test/integration/Virtual_network_gateway_connection.rb +189 -182
  189. data/test/integration/application_gateway.rb +208 -183
  190. data/test/integration/availability_set.rb +44 -27
  191. data/test/integration/blob.rb +293 -169
  192. data/test/integration/container.rb +93 -42
  193. data/test/integration/data_disk.rb +57 -46
  194. data/test/integration/deployment.rb +40 -32
  195. data/test/integration/express_route_circuit.rb +86 -82
  196. data/test/integration/external_load_balancer.rb +108 -100
  197. data/test/integration/internal_load_balancer.rb +115 -106
  198. data/test/integration/local_network_gateway.rb +46 -39
  199. data/test/integration/network_interface.rb +119 -107
  200. data/test/integration/network_security_group.rb +86 -74
  201. data/test/integration/network_security_rule.rb +65 -57
  202. data/test/integration/public_ip.rb +50 -42
  203. data/test/integration/record_set.rb +90 -78
  204. data/test/integration/resource_group.rb +26 -14
  205. data/test/integration/resource_tag.rb +56 -45
  206. data/test/integration/server.rb +152 -135
  207. data/test/integration/server_custom_image.rb +85 -76
  208. data/test/integration/sql_server.rb +130 -117
  209. data/test/integration/storage_account.rb +82 -70
  210. data/test/integration/subnet.rb +87 -74
  211. data/test/integration/traffic_manager.rb +86 -74
  212. data/test/integration/virtual_machine_extension.rb +115 -106
  213. data/test/integration/virtual_network.rb +121 -100
  214. data/test/integration/virtual_network_gateway.rb +86 -79
  215. data/test/integration/virtual_network_gateway_connection_to_express_route.rb +94 -87
  216. data/test/integration/zone.rb +36 -28
  217. data/test/models/storage/test_directories.rb +26 -71
  218. data/test/models/storage/test_directory.rb +111 -58
  219. data/test/models/storage/test_file.rb +179 -143
  220. data/test/models/storage/test_files.rb +197 -30
  221. data/test/models/storage/test_storage_account.rb +1 -1
  222. data/test/requests/compute/test_attach_data_disk_to_vm.rb +15 -17
  223. data/test/requests/storage/test_acquire_blob_lease.rb +23 -4
  224. data/test/requests/storage/test_acquire_container_lease.rb +24 -5
  225. data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
  226. data/test/requests/storage/test_compare_container_blobs.rb +36 -0
  227. data/test/requests/storage/test_copy_blob.rb +22 -3
  228. data/test/requests/storage/test_copy_blob_from_uri.rb +23 -4
  229. data/test/requests/storage/test_create_block_blob.rb +80 -0
  230. data/test/requests/storage/test_create_container.rb +18 -13
  231. data/test/requests/storage/test_create_disk.rb +57 -4
  232. data/test/requests/storage/test_create_page_blob.rb +34 -0
  233. data/test/requests/storage/test_delete_blob.rb +25 -5
  234. data/test/requests/storage/test_delete_container.rb +21 -9
  235. data/test/requests/storage/test_delete_disk.rb +14 -7
  236. data/test/requests/storage/test_get_blob.rb +141 -0
  237. data/test/requests/storage/test_get_blob_http_url.rb +30 -0
  238. data/test/requests/storage/test_get_blob_https_url.rb +30 -0
  239. data/test/requests/storage/test_get_blob_properties.rb +29 -7
  240. data/test/requests/storage/test_get_blob_url.rb +33 -0
  241. data/test/requests/storage/test_get_container_acl.rb +37 -0
  242. data/test/requests/storage/test_get_container_properties.rb +25 -11
  243. data/test/requests/storage/test_get_container_url.rb +33 -0
  244. data/test/requests/storage/test_list_blobs.rb +77 -0
  245. data/test/requests/storage/test_list_containers.rb +38 -7
  246. data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
  247. data/test/requests/storage/test_put_blob_block.rb +34 -0
  248. data/test/requests/storage/test_put_blob_metadata.rb +36 -0
  249. data/test/requests/storage/test_put_blob_pages.rb +34 -0
  250. data/test/requests/storage/test_put_blob_properties.rb +39 -0
  251. data/test/requests/storage/test_put_container_acl.rb +34 -0
  252. data/test/requests/storage/test_put_container_metadata.rb +36 -0
  253. data/test/requests/storage/test_release_blob_lease.rb +20 -2
  254. data/test/requests/storage/test_release_container_lease.rb +21 -3
  255. data/test/requests/storage/test_save_page_blob.rb +115 -0
  256. data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
  257. data/test/test_helper.rb +34 -21
  258. metadata +92 -46
  259. data/lib/fog/azurerm/requests/storage/check_blob_exist.rb +0 -25
  260. data/lib/fog/azurerm/requests/storage/compare_blob.rb +0 -73
  261. data/lib/fog/azurerm/requests/storage/download_blob_to_file.rb +0 -56
  262. data/lib/fog/azurerm/requests/storage/get_blob_metadata.rb +0 -59
  263. data/lib/fog/azurerm/requests/storage/get_container_access_control_list.rb +0 -30
  264. data/lib/fog/azurerm/requests/storage/get_container_metadata.rb +0 -32
  265. data/lib/fog/azurerm/requests/storage/set_blob_properties.rb +0 -26
  266. data/lib/fog/azurerm/requests/storage/upload_block_blob_from_file.rb +0 -60
  267. data/test/requests/storage/test_check_blob_exist.rb +0 -17
  268. data/test/requests/storage/test_compare_blob.rb +0 -17
  269. data/test/requests/storage/test_download_blob_to_file.rb +0 -25
  270. data/test/requests/storage/test_get_blob_metadata.rb +0 -18
  271. data/test/requests/storage/test_get_container_access_control_list.rb +0 -31
  272. data/test/requests/storage/test_get_container_metadata.rb +0 -18
  273. data/test/requests/storage/test_list_blobs_in_container.rb +0 -23
  274. data/test/requests/storage/test_set_blob_metadata.rb +0 -17
  275. data/test/requests/storage/test_set_blob_properties.rb +0 -16
  276. data/test/requests/storage/test_set_container_metadata.rb +0 -17
  277. data/test/requests/storage/test_upload_block_blob_from_file.rb +0 -23
@@ -27,39 +27,47 @@ dns = Fog::DNS.new(
27
27
  ###################### Prerequisites ######################
28
28
  ########################################################################################################################
29
29
 
30
- rs.resource_groups.create(
31
- name: 'TestRG-ZN',
32
- location: 'eastus'
33
- )
30
+ begin
31
+ resource_group = rs.resource_groups.create(
32
+ name: 'TestRG-ZN',
33
+ location: LOCATION
34
+ )
34
35
 
35
- ########################################################################################################################
36
- ###################### Create Zone ######################
37
- ########################################################################################################################
36
+ ########################################################################################################################
37
+ ###################### Create Zone ######################
38
+ ########################################################################################################################
38
39
 
39
- dns.zones.create(
40
- name: 'test-zone.com',
41
- location: 'global',
42
- resource_group: 'TestRG-ZN'
43
- )
40
+ zone = dns.zones.create(
41
+ name: 'test-zone.com',
42
+ location: 'global',
43
+ resource_group: 'TestRG-ZN'
44
+ )
45
+ puts "Created zone: #{zone.name}"
44
46
 
45
- ########################################################################################################################
46
- ###################### Get All Zones in a Subscription ######################
47
- ########################################################################################################################
47
+ ########################################################################################################################
48
+ ###################### Get All Zones in a Subscription ######################
49
+ ########################################################################################################################
48
50
 
49
- dns.zones.each do |z|
50
- puts "Resource Group:#{z.resource_group} name:#{z.name}"
51
- end
51
+ puts 'List zones in a subscription:'
52
+ dns.zones.each do |z|
53
+ puts "Resource Group:#{z.resource_group} name:#{z.name}"
54
+ end
52
55
 
53
- ########################################################################################################################
54
- ###################### Get and Destroy Zone in a Resource Group ######################
55
- ########################################################################################################################
56
+ ########################################################################################################################
57
+ ###################### Get and Destroy Zone in a Resource Group ######################
58
+ ########################################################################################################################
56
59
 
57
- zone = dns.zones.get('TestRG-ZN', 'test-zone.com')
58
- zone.destroy
60
+ zone = dns.zones.get('TestRG-ZN', 'test-zone.com')
61
+ puts "Get zone: #{zone.name}"
62
+ puts "Deleted zone: #{zone.destroy}"
59
63
 
60
- ########################################################################################################################
61
- ###################### CleanUp ######################
62
- ########################################################################################################################
64
+ ########################################################################################################################
65
+ ###################### CleanUp ######################
66
+ ########################################################################################################################
63
67
 
64
- rg = rs.resource_groups.get('TestRG-ZN')
65
- rg.destroy
68
+ rg = rs.resource_groups.get('TestRG-ZN')
69
+ rg.destroy
70
+ rescue
71
+ puts 'Integration Test for zone is failing'
72
+ resource_group.destroy unless resource_group.nil?
73
+ end
@@ -3,23 +3,16 @@ require File.expand_path '../../test_helper', __dir__
3
3
  # Test class for Container Collection
4
4
  class TestDirectories < Minitest::Test
5
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
6
  @service = Fog::Storage::AzureRM.new(storage_account_credentials)
11
- @blob_client = @service.instance_variable_get(:@blob_client)
12
7
  @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
8
+
9
+ @container_list = ApiStub::Models::Storage::Directory.container_list
10
+ @container = ApiStub::Models::Storage::Directory.container
11
+ @blob_list = ApiStub::Models::Storage::Directory.blob_list
17
12
  end
18
13
 
19
14
  def test_collection_methods
20
15
  methods = [
21
- :get_metadata,
22
- :set_metadata,
23
16
  :all,
24
17
  :get
25
18
  ]
@@ -28,78 +21,40 @@ class TestDirectories < Minitest::Test
28
21
  end
29
22
  end
30
23
 
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
24
+ def test_all_method_success
25
+ @service.stub :list_containers, @container_list do
26
+ dirs = @directories.all
27
+ assert_instance_of Fog::Storage::AzureRM::Directories, dirs
28
+ assert_equal @container_list.size, dirs.size
29
+ dirs.each do |directory|
30
+ assert_instance_of Fog::Storage::AzureRM::Directory, directory
31
+ assert_equal 'unknown', directory.attributes[:acl]
36
32
  end
37
33
  end
38
34
  end
39
35
 
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'
36
+ def test_get_method_success
37
+ @service.stub :get_container_properties, @container do
38
+ @service.stub :list_blobs, @blob_list do
39
+ directory = @directories.get('test_container')
40
+ assert_instance_of Fog::Storage::AzureRM::Directory, directory
41
+ assert_equal 'unknown', directory.attributes[:acl]
59
42
  end
60
43
  end
61
44
  end
62
45
 
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)
46
+ def test_get_method_container_not_found
47
+ exception = ->(*) { raise 'NotFound' }
48
+ @service.stub :get_container_properties, exception do
49
+ assert @directories.get('test_container').nil?
71
50
  end
72
51
  end
73
52
 
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
53
+ def test_get_method_exception
54
+ exception = ->(*) { raise 'Error' }
55
+ @service.stub :get_container_properties, exception do
77
56
  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
57
+ @directories.get('test_container')
103
58
  end
104
59
  end
105
60
  end
@@ -3,24 +3,24 @@ require File.expand_path '../../test_helper', __dir__
3
3
  # Test class for Storage Container Model
4
4
  class TestDirectory < Minitest::Test
5
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
6
  @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
7
+ @directory = directory(@service)
8
+
9
+ @container = ApiStub::Models::Storage::Directory.container
10
+ @container_acl = ApiStub::Models::Storage::Directory.container_acl
11
+ @container_https_url = ApiStub::Models::Storage::Directory.container_https_url
17
12
  end
18
13
 
19
14
  def test_model_methods
20
15
  methods = [
16
+ :acl=,
17
+ :acl,
18
+ :destroy,
19
+ :files,
20
+ :public=,
21
+ :public_url,
21
22
  :save,
22
- :create,
23
- :destroy
23
+ :persisted?
24
24
  ]
25
25
  methods.each do |method|
26
26
  assert_respond_to @directory, method
@@ -37,89 +37,142 @@ class TestDirectory < Minitest::Test
37
37
  :lease_status,
38
38
  :metadata
39
39
  ]
40
- @service.stub :create_container, @create_result do
40
+ @service.stub :create_container, @container do
41
41
  attributes.each do |attribute|
42
42
  assert_respond_to @directory, attribute
43
43
  end
44
44
  end
45
45
  end
46
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
47
+ def test_set_acl_method_success
48
+ result = @directory.acl = 'container'
49
+ assert_equal 'container', result
50
+ assert_equal 'container', @directory.attributes[:acl]
51
+ end
52
+
53
+ def test_set_acl_method_exception
54
+ assert_raises(ArgumentError) do
55
+ @directory.acl = 'invalid-acl'
53
56
  end
54
57
  end
55
58
 
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
59
+ def test_get_acl_method_success
60
+ # Return 'unknonw' when directory is not persist and acl is 'unknown'
61
+ @directory.acl = 'unknown'
62
+ @directory.stub :persisted?, false do
63
+ assert_equal 'unknown', @directory.acl
64
+ end
65
+
66
+ # Return actual value directly when directory is not persist and acl is not 'unknown'
67
+ @directory.acl = 'blob'
68
+ @directory.stub :persisted?, false do
69
+ assert_equal 'blob', @directory.acl
70
+ end
71
+
72
+ # Query actual value and return it when directory is persist and acl is 'unknown'
73
+ @directory.acl = 'unknown'
74
+ @directory.stub :persisted?, true do
75
+ @service.stub :get_container_acl, @container_acl do
76
+ assert_equal 'container', @directory.acl
77
+ assert_equal 'container', @directory.attributes[:acl]
61
78
  end
62
79
  end
63
80
  end
64
81
 
65
- def test_save_mock
66
- assert_instance_of Fog::Storage::AzureRM::Directory, @mock_directory.save
82
+ def test_get_acl_method_without_key_exception
83
+ @directory.attributes.delete(:key)
84
+ assert_raises(ArgumentError) do
85
+ @directory.acl
86
+ end
67
87
  end
68
88
 
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
89
+ def test_destroy_method_success
90
+ @service.stub :delete_container, true do
91
+ assert @directory.destroy
72
92
  end
73
93
  end
74
94
 
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
95
+ def test_destroy_method_without_key_exception
96
+ @directory.attributes.delete(:key)
97
+ assert_raises(ArgumentError) do
98
+ @directory.destroy
81
99
  end
82
100
  end
83
101
 
84
- def test_get_container_properties_mock
85
- assert_instance_of Fog::Storage::AzureRM::Directory, @mock_directory.get_properties
102
+ def test_files_method_success
103
+ assert_instance_of Fog::Storage::AzureRM::Files, @directory.files
86
104
  end
87
105
 
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
106
+ def test_set_public_method_success
107
+ # Set public
108
+ result = @directory.public = true
109
+ assert result
110
+ assert_equal 'container', @directory.attributes[:acl]
111
+
112
+ # Set private
113
+ result = @directory.public = false
114
+ assert !result
115
+ assert_equal nil, @directory.attributes[:acl]
92
116
  end
93
117
 
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
118
+ def test_public_url_method_with_public_success
119
+ @directory.stub :acl, 'container' do
120
+ @service.stub :get_container_url, @container_https_url do
121
+ assert_equal @container_https_url, @directory.public_url
99
122
  end
100
123
  end
101
124
  end
102
125
 
103
- def test_get_access_control_list_mock
104
- assert_instance_of Fog::Storage::AzureRM::Directory, @mock_directory.access_control_list
126
+ def test_public_url_method_with_private_success
127
+ @directory.stub :acl, nil do
128
+ assert @directory.public_url.nil?
129
+ end
105
130
  end
106
131
 
107
- def test_delete_method_true_response
108
- @service.stub :delete_container, true do
109
- assert @directory.destroy
132
+ def test_public_url_method_without_key_exception
133
+ @directory.attributes.delete(:key)
134
+ assert_raises(ArgumentError) do
135
+ @directory.public_url
136
+ end
137
+ end
138
+
139
+ def test_save_method_create_success
140
+ @service.stub :create_container, @container do
141
+ assert @directory.save
142
+ assert @directory.attributes[:is_persisted]
110
143
  end
111
144
  end
112
145
 
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
146
+ def test_save_method_update_success
147
+ options = { is_create: false }
148
+ @service.stub :put_container_acl, true do
149
+ @service.stub :put_container_metadata, true do
150
+ @service.stub :get_container_properties, @container do
151
+ assert @directory.save(options)
152
+ assert @directory.attributes[:is_persisted]
153
+ end
118
154
  end
119
155
  end
120
156
  end
121
157
 
122
- def test_delete_method_response_mock
123
- assert @mock_directory.destroy
158
+ def test_save_method_without_key_exception
159
+ @directory.attributes.delete(:key)
160
+ assert_raises(ArgumentError) do
161
+ @directory.save
162
+ end
163
+ end
164
+
165
+ def test_persisted_method_success
166
+ @directory.attributes[:is_persisted] = true
167
+ @directory.attributes[:last_modified] = nil
168
+ assert @directory.persisted?
169
+
170
+ @directory.attributes[:is_persisted] = false
171
+ @directory.attributes[:last_modified] = 'datetime'
172
+ assert @directory.persisted?
173
+
174
+ @directory.attributes[:is_persisted] = false
175
+ @directory.attributes[:last_modified] = nil
176
+ assert !@directory.persisted?
124
177
  end
125
178
  end
@@ -3,31 +3,29 @@ require File.expand_path '../../test_helper', __dir__
3
3
  # Test class for Storage Container Model
4
4
  class TestFile < Minitest::Test
5
5
  def setup
6
- Fog.mock!
7
- @mock_service = Fog::Storage::AzureRM.new(storage_account_credentials)
8
- @mock_file = storage_blob(@mock_service)
9
- Fog.unmock!
10
6
  @service = Fog::Storage::AzureRM.new(storage_account_credentials)
11
- @file = storage_blob(@service)
12
- @cloud_blob = storage_cloud_blob
13
- @blob_client = @service.instance_variable_get(:@blob_client)
7
+ @directory = directory(@service)
8
+ @file = file(@service)
9
+ @raw_cloud_blob = storage_blob
10
+
14
11
  @mocked_response = mocked_storage_http_error
15
- @content = Array.new(1024 * 1024) { 'a' }.join
16
- @get_metadata_result = ApiStub::Models::Storage::File.test_get_blob_metadata
17
- @create_result = ApiStub::Models::Storage::File.upload_block_blob_from_file
18
- @download_result = ApiStub::Models::Storage::File.download_blob_to_file
19
- @get_properties_result = ApiStub::Models::Storage::File.get_blob_properties
12
+ @blob = ApiStub::Models::Storage::File.blob
13
+ @metadata = ApiStub::Models::Storage::File.blob_metadata
14
+ @blob_list = ApiStub::Models::Storage::File.blob_list
15
+ @blob_https_url = ApiStub::Models::Storage::File.blob_https_url
20
16
  end
21
17
 
22
18
  def test_model_methods
23
19
  methods = [
24
20
  :save,
25
- :save_to_file,
26
- :get_properties,
27
- :set_properties,
28
- :set_metadata,
29
- :get_metadata,
30
- :destroy
21
+ :body,
22
+ :body=,
23
+ :copy,
24
+ :copy_from_uri,
25
+ :destroy,
26
+ :public?,
27
+ :public_url,
28
+ :url
31
29
  ]
32
30
  methods.each do |method|
33
31
  assert_respond_to @file, method
@@ -37,14 +35,15 @@ class TestFile < Minitest::Test
37
35
  def test_model_attributes
38
36
  attributes = [
39
37
  :key,
38
+ :body,
39
+ :directory,
40
40
  :accept_ranges,
41
- :cache_control,
42
- :committed_block_count,
43
41
  :content_length,
44
42
  :content_type,
45
43
  :content_md5,
46
44
  :content_encoding,
47
45
  :content_language,
46
+ :cache_control,
48
47
  :content_disposition,
49
48
  :copy_completion_time,
50
49
  :copy_status,
@@ -52,207 +51,244 @@ class TestFile < Minitest::Test
52
51
  :copy_id,
53
52
  :copy_progress,
54
53
  :copy_source,
55
- :directory,
56
54
  :etag,
57
- :file_path,
58
55
  :last_modified,
59
56
  :lease_duration,
60
57
  :lease_state,
61
58
  :lease_status,
62
- :metadata,
63
59
  :sequence_number,
64
- :blob_type
60
+ :blob_type,
61
+ :metadata
65
62
  ]
66
63
  attributes.each do |attribute|
67
64
  assert_respond_to @file, attribute
68
65
  end
69
66
  end
70
67
 
71
- def test_save_method_response
72
- @file.file_path = 'test.txt'
73
- @service.stub :upload_block_blob_from_file, @create_result do
74
- assert_instance_of Fog::Storage::AzureRM::File, @file.save
75
- end
76
- @service.stub :upload_block_blob_from_file, @create_result do
77
- assert_instance_of Fog::Storage::AzureRM::File, @file.create
68
+ def test_save_method_with_small_block_blob_success
69
+ @file.body = 'd' * 1025 # SINGLE_BLOB_PUT_THRESHOLD is 32 * 1024 * 1024
70
+
71
+ @service.stub :create_block_blob, @raw_cloud_blob do
72
+ assert @file.save
78
73
  end
79
74
  end
80
75
 
81
- def test_save_small_blob_method_response
82
- small_file_name = 'small_test_file.dat'
83
- small_file = File.new(small_file_name, 'w')
84
- small_file.puts(@content)
85
- small_file.close
86
- @file.file_path = small_file_name
87
- @blob_client.stub :create_block_blob, @create_result do
88
- assert_instance_of Fog::Storage::AzureRM::File, @file.create
89
- end
90
- io_exception = -> (_container_name, _blob_name, _file_path, _option) { raise IOError.new }
91
- @blob_client.stub :create_block_blob, io_exception do
92
- assert_raises(RuntimeError) do
93
- @file.create
94
- end
95
- end
96
- http_exception = -> (_container_name, _blob_name, _file_path, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
97
- @blob_client.stub :create_block_blob, http_exception do
98
- assert_raises(RuntimeError) do
99
- @file.create
76
+ def test_save_method_with_large_block_blob_success
77
+ @file.body = 'd' * (32 * 1024 * 1024 + 1) # SINGLE_BLOB_PUT_THRESHOLD is 32 * 1024 * 1024
78
+
79
+ @service.stub :multipart_save_block_blob, true do
80
+ @service.stub :get_blob_properties, @raw_cloud_blob do
81
+ assert @file.save
100
82
  end
101
83
  end
102
- File.delete(small_file_name)
103
84
  end
104
85
 
105
- def test_save_large_blob_method_response
106
- large_file_name = 'large_test_file.dat'
107
- large_file = File.new(large_file_name, 'w')
108
- 33.times do
109
- large_file.puts(@content)
110
- end
111
- large_file.close
112
- @file.file_path = large_file_name
113
- @blob_client.stub :put_blob_block, true do
114
- @blob_client.stub :commit_blob_blocks, @create_result do
115
- assert_instance_of Fog::Storage::AzureRM::File, @file.create
86
+ def test_save_method_with_page_blob_success
87
+ options = { blob_type: 'PageBlob' }
88
+ @file.metadata = @metadata
89
+ @file.body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024
90
+
91
+ @service.stub :save_page_blob, true do
92
+ @service.stub :get_blob_properties, @raw_cloud_blob do
93
+ assert @file.save(options)
116
94
  end
117
95
  end
118
- File.delete(large_file_name)
119
96
  end
120
97
 
121
- def test_save_method_response_mock
122
- @mock_file.file_path = 'mock_test.txt'
123
- assert_instance_of Fog::Storage::AzureRM::File, @mock_file.save
98
+ def test_save_method_with_not_update_body_success
99
+ options = { update_body: false }
100
+ @file.metadata = @metadata
101
+
102
+ @service.stub :put_blob_metadata, true do
103
+ @service.stub :put_blob_properties, true do
104
+ @service.stub :get_blob_properties, @raw_cloud_blob do
105
+ assert @file.save(options)
106
+ end
107
+ end
108
+ end
124
109
  end
125
110
 
126
- def test_save_to_file
127
- @service.stub :download_blob_to_file, @download_result do
128
- assert_instance_of Fog::Storage::AzureRM::File, @file.save_to_file('test.txt')
111
+ def test_save_method_without_directory_exception
112
+ assert_raises(ArgumentError) do
113
+ @file.attributes.delete(:directory)
114
+ @file.save
129
115
  end
130
116
  end
131
117
 
132
- def test_save_to_file_io_exception
133
- io_exception = -> (_container_name, _blob_name, _option) { raise IOError.new }
134
- @blob_client.stub :get_blob, io_exception do
135
- assert_raises(RuntimeError) do
136
- @file.save_to_file('test.txt')
137
- end
118
+ def test_save_method_without_key_exception
119
+ assert_raises(ArgumentError) do
120
+ @file.attributes.delete(:key)
121
+ @file.save
138
122
  end
139
123
  end
140
124
 
141
- def test_save_to_file_http_exception
142
- http_exception = -> (_container_name, _blob_name, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
143
- @blob_client.stub :get_blob, http_exception do
144
- assert_raises(RuntimeError) do
145
- @file.save_to_file('test.txt')
146
- end
125
+ def test_save_method_create_without_body_exception
126
+ assert_raises(ArgumentError) do
127
+ @file.attributes.delete(:body)
128
+ @file.save
147
129
  end
148
130
  end
149
131
 
150
- def test_save_to_file_mock
151
- assert_instance_of Fog::Storage::AzureRM::File, @mock_file.save_to_file('test.txt')
132
+ def test_get_body_method_local_success
133
+ @file.attributes[:body] = 'body'
134
+ assert_equal 'body', @file.body
135
+
136
+ @file.attributes[:body] = nil
137
+ @file.attributes[:last_modified] = nil
138
+ assert_equal '', @file.body
152
139
  end
153
140
 
154
- def test_get_blob_properties
155
- @service.stub :get_blob_properties, @get_properties_result do
156
- assert_instance_of Fog::Storage::AzureRM::File, @file.get_properties
141
+ def test_get_body_method_remote_success
142
+ @file.attributes[:body] = nil
143
+ remote_file = @file.dup
144
+ body_content = 'data'
145
+ @file.collection.stub :get, remote_file do
146
+ remote_file.stub :body, body_content do
147
+ body = @file.body
148
+ assert_equal body_content, body
149
+ assert_equal body_content, @file.attributes[:body]
150
+ end
157
151
  end
158
152
  end
159
153
 
160
- def test_get_cloud_blob_properties
161
- @service.stub :get_blob_properties, @cloud_blob do
162
- assert_instance_of Fog::Storage::AzureRM::File, @file.get_properties
154
+ def test_get_body_method_remote_not_found_success
155
+ @file.attributes[:body] = nil
156
+ @file.collection.stub :get, nil do
157
+ body = @file.body
158
+ assert_equal '', body
159
+ assert_equal '', @file.attributes[:body]
163
160
  end
164
161
  end
165
162
 
166
- def test_get_blob_properties_http_exception
167
- http_exception = -> (_container_name, _blob_name, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
168
- @blob_client.stub :get_blob_properties, http_exception do
169
- assert_raises(RuntimeError) do
170
- @file.get_properties
163
+ def test_set_body_method_success
164
+ @file.body = 'new_body'
165
+ assert_equal 'new_body', @file.attributes[:body]
166
+ end
167
+
168
+ def test_copy_method_success
169
+ copy_id = @raw_cloud_blob.properties[:copy_id]
170
+ copy_status = 'pending'
171
+
172
+ @service.stub :get_blob_properties, @raw_cloud_blob do
173
+ @service.stub :copy_blob, [copy_id, copy_status] do
174
+ @service.stub :wait_blob_copy_operation_to_finish, true do
175
+ target_file = @file.copy('target_container', 'target_blob')
176
+ assert_instance_of Fog::Storage::AzureRM::File, target_file
177
+ end
171
178
  end
172
179
  end
173
180
  end
174
181
 
175
- def test_get_blob_properties_mock
176
- assert_instance_of Fog::Storage::AzureRM::File, @mock_file.get_properties
182
+ def test_copy_from_uri_method_success
183
+ copy_id = @raw_cloud_blob.properties[:copy_id]
184
+ copy_status = 'pending'
185
+
186
+ @service.stub :get_blob_properties, @raw_cloud_blob do
187
+ @service.stub :copy_blob_from_uri, [copy_id, copy_status] do
188
+ @service.stub :wait_blob_copy_operation_to_finish, true do
189
+ assert @file.copy_from_uri('source_uri')
190
+ end
191
+ end
192
+ end
177
193
  end
178
194
 
179
- def test_set_blob_properties
180
- @service.stub :set_blob_properties, true do
181
- assert @file.set_properties
195
+ def test_copy_from_uri_method_without_directory_exception
196
+ assert_raises(ArgumentError) do
197
+ @file.attributes.delete(:directory)
198
+ @file.copy_from_uri('source_uri')
182
199
  end
183
200
  end
184
201
 
185
- def test_set_blob_properties_http_exception
186
- http_exception = -> (_container_name, _blob_name, _properties) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
187
- @blob_client.stub :set_blob_properties, http_exception do
188
- assert_raises(RuntimeError) do
189
- @file.set_properties
190
- end
202
+ def test_copy_from_uri_method_without_key_exception
203
+ assert_raises(ArgumentError) do
204
+ @file.attributes.delete(:key)
205
+ @file.copy_from_uri('source_uri')
191
206
  end
192
207
  end
193
208
 
194
- def test_set_blob_properties_mock
195
- assert @mock_file.set_properties
209
+ def test_destroy_method_success
210
+ @service.stub :delete_blob, true do
211
+ assert @file.destroy
212
+ assert @file.attributes[:body].nil?
213
+ end
196
214
  end
197
215
 
198
- def test_get_blob_metadata
199
- @service.stub :get_blob_metadata, @get_metadata_result do
200
- file = @file.get_metadata
201
- assert_instance_of Fog::Storage::AzureRM::File, file
202
- assert_equal @get_metadata_result, file.metadata
216
+ def test_destroy_method_without_directory_exception
217
+ assert_raises(ArgumentError) do
218
+ @file.attributes.delete(:directory)
219
+ @file.destroy
203
220
  end
204
221
  end
205
222
 
206
- def test_get_blob_metadata_http_exception
207
- http_exception = -> (_container_name, _blob_name, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
208
- @blob_client.stub :get_blob_metadata, http_exception do
209
- assert_raises(RuntimeError) do
210
- @file.get_metadata
211
- end
223
+ def test_destroy_method_without_key_exception
224
+ assert_raises(ArgumentError) do
225
+ @file.attributes.delete(:key)
226
+ @file.destroy
212
227
  end
213
228
  end
214
229
 
215
- def test_get_blob_metadata_mock
216
- blob = @mock_file.get_metadata
217
- assert_instance_of Fog::Storage::AzureRM::File, blob
218
- assert_equal @get_metadata_result, blob.metadata
230
+ def test_public_method_success
231
+ @file.directory.acl = 'container'
232
+ assert @file.public?
233
+
234
+ @file.directory.acl = 'blob'
235
+ assert @file.public?
236
+
237
+ @file.directory.acl = nil
238
+ assert !@file.public?
219
239
  end
220
240
 
221
- def test_set_blob_metadata
222
- @service.stub :set_blob_metadata, true do
223
- assert @file.set_metadata(@get_metadata_result)
241
+ def test_public_method_without_directory_exception
242
+ assert_raises(ArgumentError) do
243
+ @file.attributes.delete(:directory)
244
+ @file.public?
224
245
  end
225
246
  end
226
247
 
227
- def test_set_blob_metadata_http_exception
228
- http_exception = -> (_container_name, _blob_name, _metadata, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
229
- @blob_client.stub :set_blob_metadata, http_exception do
230
- assert_raises(RuntimeError) do
231
- @file.set_metadata @get_metadata_result
248
+ def test_public_url_method_success
249
+ @file.stub :public?, false do
250
+ assert @file.public_url.nil?
251
+ end
252
+
253
+ @file.stub :public?, true do
254
+ @service.stub :get_blob_url, @blob_https_url do
255
+ assert @file.public_url, @blob_https_url
256
+ end
257
+ end
258
+
259
+ http_url = @blob_https_url.gsub('https:', 'http:')
260
+ options = { scheme: 'https' }
261
+ @file.stub :public?, true do
262
+ @service.stub :get_blob_url, http_url do
263
+ assert @file.public_url(options), http_url
232
264
  end
233
265
  end
234
266
  end
235
267
 
236
- def test_set_blob_metadata_mock
237
- assert @mock_file.set_metadata(@get_metadata_result)
268
+ def test_public_url_method_without_directory_exception
269
+ assert_raises(ArgumentError) do
270
+ @file.attributes.delete(:directory)
271
+ @file.public_url
272
+ end
238
273
  end
239
274
 
240
- def test_delete_method_true_response
241
- @service.stub :delete_blob, true do
242
- assert @file.destroy
275
+ def test_public_url_method_without_key_exception
276
+ assert_raises(ArgumentError) do
277
+ @file.attributes.delete(:key)
278
+ @file.public_url
243
279
  end
244
280
  end
245
281
 
246
- def test_delete_method_exception
247
- exception = -> (_container_name, _blob_name, _option) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
248
- @blob_client.stub :delete_blob, exception do
249
- assert_raises(RuntimeError) do
250
- assert @file.destroy
251
- end
282
+ def test_url_method_success
283
+ @file.collection.stub :get_url, @blob_https_url do
284
+ assert @file.url(Time.now + 3600), @blob_https_url
252
285
  end
253
286
  end
254
287
 
255
- def test_delete_method_response_mock
256
- assert @mock_file.destroy
288
+ def test_url_method_without_key_exception
289
+ assert_raises(ArgumentError) do
290
+ @file.attributes.delete(:key)
291
+ @file.url(Time.now + 3600)
292
+ end
257
293
  end
258
294
  end