From 3b0b334d9714394f2f5d2e0b22e59b6efe2e75a2 Mon Sep 17 00:00:00 2001 From: Maham Nazir Date: Fri, 23 Feb 2018 17:06:58 +0500 Subject: [PATCH 1/4] RSpec Integration Tests --- test/integration/managed_disk_spec.rb | 163 ++++++++++++++ .../network_security_group_spec.rb | 209 ++++++++++++++++++ .../integration/network_security_rule_spec.rb | 147 ++++++++++++ test/integration/resource_group_spec.rb | 79 +++++++ 4 files changed, 598 insertions(+) create mode 100644 test/integration/managed_disk_spec.rb create mode 100644 test/integration/network_security_group_spec.rb create mode 100644 test/integration/network_security_rule_spec.rb create mode 100644 test/integration/resource_group_spec.rb diff --git a/test/integration/managed_disk_spec.rb b/test/integration/managed_disk_spec.rb new file mode 100644 index 000000000..c286b2ff2 --- /dev/null +++ b/test/integration/managed_disk_spec.rb @@ -0,0 +1,163 @@ +require 'fog/azurerm' +require 'yaml' + +# Managed Disk Integration Test using RSpec + +describe 'Integration Testing of Managed Disk' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @rs = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @compute = Fog::Compute::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'], + environment: azure_credentials['environment'] + ) + + time = current_time + @resource_group_name = 'TestRG-MD' + @disk_name = 'MD' + @location = 'eastus' + @tags = { key1: 'value1', key2: 'value2' } + @disk_account_type = 'Premium_LRS' + @disk_size_gb = 1023 + @disk_create_option = 'Empty' + + @resource_group = @rs.resource_groups.create( + name: @resource_group_name, + location: @location + ) + end + + describe 'Check Existence' do + before 'checks existence of managed disk' do + @md_exists = @compute.managed_disks.check_managed_disk_exists(@resource_group_name, @disk_name) + end + + it 'should not exist yet' do + expect(@md_exists).to eq(false) + end + end + + describe 'Create' do + before :all do + @managed_disk = @compute.managed_disks.create( + name: @disk_name, + location: @location, + resource_group_name: @resource_group_name, + tags: @tags, + account_type: @disk_account_type, + disk_size_gb: @disk_size_gb, + creation_data: { + create_option: @disk_create_option + } + ) + end + + it 'should have name: \'MD\'' do + expect(@managed_disk.name).to eq(@disk_name) + end + + it 'should exist in location: \'eastus\'' do + expect(@managed_disk.location).to eq(@location) + end + + it 'should exist in resource group: \'TestRG-MD\'' do + expect(@managed_disk.resource_group_name).to eq(@resource_group_name) + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@managed_disk.tags['key1']).to eq(@tags[:key1]) + expect(@managed_disk.tags['key2']).to eq(@tags[:key2]) + end + + it 'should have account type: \'Premium LRS\'' do + expect(@managed_disk.account_type).to eq(@disk_account_type) + end + + it 'should have disk size: 1023' do + expect(@managed_disk.disk_size_gb).to eq(@disk_size_gb) + end + + it 'should have creation option: \'Empty\'' do + expect(@managed_disk.creation_data.create_option).to eq(@disk_create_option) + end + end + + describe 'Get' do + before 'gets managed disk' do + @managed_disk = @compute.managed_disks.get(@resource_group_name, @disk_name) + end + + it 'should have name: \'MD\'' do + expect(@managed_disk.name).to eq(@disk_name) + end + end + + describe 'Grant Access' do + before 'grants access to managed disk' do + @access_type = 'Read' + @access_duration_in_secs = 1000 + @access_sas = @compute.managed_disks.grant_access(@resource_group_name, @disk_name, @access_type, @access_duration_in_secs) + end + + it 'should have granted READ access' do + expect(@access_sas).not_to eq(nil) + end + end + + describe 'Revoke Access' do + before 'revokes access to the managed disk' do + @response = @compute.managed_disks.revoke_access(@resource_group_name, @disk_name) + end + + it 'should have revoked access' do + expect(@response).not_to eq(nil) + end + end + + describe 'List' do + context 'Within a Subscription' do + before 'lists all managed disks within a subscription' do + @managed_disks_in_subscription = @compute.managed_disks + end + + it 'should not be nil' do + expect(@managed_disks_in_subscription.length).not_to eq(0) + end + end + + context 'Within the Resouce Group' do + before 'lists all managed disks in the resource group' do + @managed_disks_list = @compute.managed_disks(resource_group: @resource_group_name) + end + + it 'should contain managed disk \'MD\'' do + contains_md = false + @managed_disks_list.each do |managed_disk| + contains_md = true if managed_disk.name == @disk_name + end + expect(contains_md).to eq(true) + end + end + end + + describe 'Delete' do + before 'gets managed disk' do + @managed_disk = @compute.managed_disks.get(@resource_group_name, @disk_name) + end + + it 'should not exist anymore' do + expect(@managed_disk.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end +end diff --git a/test/integration/network_security_group_spec.rb b/test/integration/network_security_group_spec.rb new file mode 100644 index 000000000..13fdfc23d --- /dev/null +++ b/test/integration/network_security_group_spec.rb @@ -0,0 +1,209 @@ +require 'fog/azurerm' +require 'yaml' + +# Network Security Group Integration Test using RSpec + +describe 'Integration Testing of Network Security Group' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @rs = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @network = Fog::Network::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @location = 'eastus' + @net_sec_group_name = 'testNetSecGroup' + @tags = { key1: 'value1', key2: 'value2' } + @security_rules = [ + { + name: 'testRule', + protocol: Fog::ARM::Network::Models::SecurityRuleProtocol::Tcp, + source_port_range: '22', + destination_port_range: '22', + source_address_prefix: '0.0.0.0/0', + destination_address_prefix: '0.0.0.0/0', + access: Fog::ARM::Network::Models::SecurityRuleAccess::Allow, + priority: 500, + direction: Fog::ARM::Network::Models::SecurityRuleDirection::Inbound + } + ] + + @resource_group = @rs.resource_groups.create( + name: 'TestRG-NSG', + location: @location + ) + end + + describe 'Check Existence' do + before 'checks existence' do + @nsg_exists = @network.network_security_groups.check_net_sec_group_exists(@resource_group.name, @net_sec_group_name) + end + + it 'should not exist yet' do + expect(@nsg_exists).to eq(false) + end + end + + describe 'Create' do + before :all do + @network_security_group = @network.network_security_groups.create( + name: @net_sec_group_name, + resource_group: @resource_group.name, + location: @location, + security_rules: @security_rules, + tags: @tags + ) + end + + it 'should have name: \'testNetSecGroup\'' do + expect(@network_security_group.name).to eq(@net_sec_group_name) + end + + it 'should exist in location: \'eastus\'' do + expect(@network_security_group.location).to eq(@location) + end + + it 'should exist in resource group: \'TestRG-NSG\'' do + expect(@network_security_group.resource_group).to eq(@resource_group.name) + end + + it 'should have the correct security rules setting' do + @security_rules.count.times do |i| + expect(@security_rules[i][:name]).to eq(@network_security_group.security_rules[i].name) + expect(@security_rules[i][:protocol]).to eq(@network_security_group.security_rules[i].protocol) + expect(@security_rules[i][:source_port_range]).to eq(@network_security_group.security_rules[i].source_port_range) + expect(@security_rules[i][:destination_port_range]).to eq(@network_security_group.security_rules[i].destination_port_range) + expect(@security_rules[i][:source_address_prefix]).to eq(@network_security_group.security_rules[i].source_address_prefix) + expect(@security_rules[i][:destination_address_prefix]).to eq(@network_security_group.security_rules[i].destination_address_prefix) + expect(@security_rules[i][:access]).to eq(@network_security_group.security_rules[i].access) + expect(@security_rules[i][:priority]).to eq(@network_security_group.security_rules[i].priority) + expect(@security_rules[i][:direction]).to eq(@network_security_group.security_rules[i].direction) + end + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@network_security_group.tags['key1']).to eq(@tags[:key1]) + expect(@network_security_group.tags['key2']).to eq(@tags[:key2]) + end + end + + describe 'Get' do + before 'gets network security group' do + @network_security_group = @network.network_security_groups.get(@resource_group.name, @net_sec_group_name) + end + + it 'should have name: \'testNetSecGroup\'' do + expect(@network_security_group.name).to eq(@net_sec_group_name) + end + end + + describe 'Update Security Rule' do + before 'updates security rule' do + @network_security_group = @network.network_security_groups.get(@resource_group.name, @net_sec_group_name) + @security_rules[0][:priority] = 500 + temp_nsg_hash = {security_rules: @security_rules} + @updated_nsg = @network_security_group.update_security_rules(temp_nsg_hash) + end + + it 'should have updated the security rule \'testRule\' correctly' do + @security_rules.count.times do |i| + expect(@security_rules[i][:name]).to eq(@updated_nsg.security_rules[i].name) + expect(@security_rules[i][:protocol]).to eq(@updated_nsg.security_rules[i].protocol) + expect(@security_rules[i][:source_port_range]).to eq(@updated_nsg.security_rules[i].source_port_range) + expect(@security_rules[i][:destination_port_range]).to eq(@updated_nsg.security_rules[i].destination_port_range) + expect(@security_rules[i][:source_address_prefix]).to eq(@updated_nsg.security_rules[i].source_address_prefix) + expect(@security_rules[i][:destination_address_prefix]).to eq(@updated_nsg.security_rules[i].destination_address_prefix) + expect(@security_rules[i][:access]).to eq(@updated_nsg.security_rules[i].access) + expect(@security_rules[i][:priority]).to eq(@updated_nsg.security_rules[i].priority) + expect(@security_rules[i][:direction]).to eq(@updated_nsg.security_rules[i].direction) + end + end + end + + describe 'Add Security Rule' do + before 'adds a new security rule' do + @network_security_group = @network.network_security_groups.get(@resource_group.name, @net_sec_group_name) + + new_security_rules = [ + { + name: 'testRule2', + protocol: Fog::ARM::Network::Models::SecurityRuleProtocol::Tcp, + source_port_range: '22', + destination_port_range: '22', + source_address_prefix: '0.0.0.0/0', + destination_address_prefix: '0.0.0.0/0', + access: Fog::ARM::Network::Models::SecurityRuleAccess::Allow, + priority: 102, + direction: Fog::ARM::Network::Models::SecurityRuleDirection::Inbound + } + ] + @security_rules << new_security_rules[0] + @updated_nsg = @network_security_group.add_security_rules(new_security_rules) + end + + it 'should have added a new security rule \'testRule2\' correctly' do + @security_rules.count.times do |i| + expect(@security_rules[i][:name]).to eq(@updated_nsg.security_rules[i].name) + expect(@security_rules[i][:protocol]).to eq(@updated_nsg.security_rules[i].protocol) + expect(@security_rules[i][:source_port_range]).to eq(@updated_nsg.security_rules[i].source_port_range) + expect(@security_rules[i][:destination_port_range]).to eq(@updated_nsg.security_rules[i].destination_port_range) + expect(@security_rules[i][:source_address_prefix]).to eq(@updated_nsg.security_rules[i].source_address_prefix) + expect(@security_rules[i][:destination_address_prefix]).to eq(@updated_nsg.security_rules[i].destination_address_prefix) + expect(@security_rules[i][:access]).to eq(@updated_nsg.security_rules[i].access) + expect(@security_rules[i][:priority]).to eq(@updated_nsg.security_rules[i].priority) + expect(@security_rules[i][:direction]).to eq(@updated_nsg.security_rules[i].direction) + end + end + end + + describe 'Remove Security Rule' do + before 'removes security rule' do + @network_security_group = @network.network_security_groups.get(@resource_group.name, @net_sec_group_name) + @rule_removed = @network_security_group.remove_security_rule('testRule') + end + + it 'should have removed the security rule \'testRule\'' do + expect(@rule_removed).not_to eq(nil) + end + end + + describe 'List' do + before :all do + @network_security_groups_list = @network.network_security_groups(resource_group: @resource_group.name) + end + + it 'should not be empty' do + expect(@network_security_groups_list.length).to_not eq(0) + end + + it 'should contain \'testNetSecGroup\'' do + contains_nsg = false + @network_security_groups_list.each do |sec_group| + contains_nsg = true if sec_group.name == @net_sec_group_name + end + expect(contains_nsg).to eq(true) + end + end + + describe 'Delete' do + before 'gets network security group' do + @network_security_group = @network.network_security_groups.get(@resource_group.name, @net_sec_group_name) + end + + it 'should not exist anymore' do + expect(@network_security_group.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end + +end \ No newline at end of file diff --git a/test/integration/network_security_rule_spec.rb b/test/integration/network_security_rule_spec.rb new file mode 100644 index 000000000..e1f7ef2c6 --- /dev/null +++ b/test/integration/network_security_rule_spec.rb @@ -0,0 +1,147 @@ +require 'fog/azurerm' +require 'yaml' + +# Network Security Rule Integration Test using RSpec + +describe 'Integration Testing of Network Security Rule' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @rs = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @network = Fog::Network::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @location = 'eastus' + @net_sec_group_name = 'testNetSecGroup' + @net_sec_rule_name = 'testRule' + + @resource_group = @rs.resource_groups.create( + name: 'TestRG-NSR', + location: @location + ) + + @net_sec_group = @network.network_security_groups.create( + name: @net_sec_group_name, + resource_group: @resource_group.name, + location: LOCATION + ) + + @security_rule = { + name: @net_sec_rule_name, + resource_group: @resource_group.name, + protocol: Fog::ARM::Network::Models::SecurityRuleProtocol::Tcp, + network_security_group_name: @net_sec_group_name, + source_port_range: '22', + destination_port_range: '22', + source_address_prefix: '0.0.0.0/0', + destination_address_prefix: '0.0.0.0/0', + access: Fog::ARM::Network::Models::SecurityRuleAccess::Allow, + priority: '100', + direction: Fog::ARM::Network::Models::SecurityRuleDirection::Inbound + } + end + + describe 'Check Existence' do + before 'checks existence of network security rule' do + @nsr_exists = @network.network_security_rules.check_net_sec_rule_exists(@resource_group.name, @net_sec_group_name, @net_sec_rule_name) + end + + it 'should not exist yet' do + expect(@nsr_exists).to eq(false) + end + end + + describe 'Create' do + before :all do + @network_security_rule = @network.network_security_rules.create(@security_rule) + end + + it 'should have name: \'testRule\'' do + expect(@network_security_rule.name).to eq(@security_rule[:name]) + end + + it 'should belong to resource group: \'TestRG-NSG\'' do + expect(@network_security_rule.resource_group).to eq(@security_rule[:resource_group]) + end + + it 'should belong to network security group: \'testNetSecGroup\'' do + expect(@network_security_rule.network_security_group_name).to eq(@security_rule[:network_security_group_name]) + end + + it 'should have protocol: \'TCP\'' do + expect(@network_security_rule.protocol).to eq(@security_rule[:protocol]) + end + + it 'should have priority: \'100\'' do + expect(@network_security_rule.priority).to eq(@security_rule[:priority].to_i) + end + + it 'should have source_port_range & destination_port_range: \'22\'' do + expect(@network_security_rule.source_port_range).to eq(@security_rule[:source_port_range]) + expect(@network_security_rule.destination_port_range).to eq(@security_rule[:destination_port_range]) + end + + it 'should have source_address_prefix & destination_address_prefix: \'10.0.0.0\'' do + expect(@network_security_rule.source_address_prefix).to eq(@security_rule[:source_address_prefix]) + expect(@network_security_rule.destination_address_prefix).to eq(@security_rule[:destination_address_prefix]) + end + + it 'should have allowed access' do + expect(@network_security_rule.access).to eq(@security_rule[:access]) + end + + it 'should have direction: Inbound' do + expect(@network_security_rule.direction).to eq(@security_rule[:direction]) + end + end + + describe 'Get' do + before 'gets network security rule' do + @network_security_rule = @network.network_security_rules.get(@resource_group.name, @net_sec_group_name, @net_sec_rule_name) + end + + it 'should have name: \'testRule\'' do + expect(@network_security_rule.name).to eq(@security_rule[:name]) + end + end + + describe 'List' do + before :all do + @network_security_rules = @network.network_security_rules(resource_group: @resource_group.name, network_security_group_name: @net_sec_group_name) + end + + it 'should not be empty' do + expect(@network_security_rules.length).to_not eq(0) + end + + it 'should contain security rule: \'testRule\'' do + contains_nsr = false + @network_security_rules.each do |sec_rule| + contains_nsr = true if sec_rule.name == @net_sec_rule_name + end + expect(contains_nsr).to eq(true) + end + end + + describe 'Delete' do + before 'gets network security group' do + @network_security_group = @network.network_security_groups.get(@resource_group.name, @net_sec_group_name) + end + + it 'should not exist anymore' do + expect(@network_security_group.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end + +end \ No newline at end of file diff --git a/test/integration/resource_group_spec.rb b/test/integration/resource_group_spec.rb new file mode 100644 index 000000000..c4088cd5c --- /dev/null +++ b/test/integration/resource_group_spec.rb @@ -0,0 +1,79 @@ +require 'fog/azurerm' +require 'yaml' + +# ResourceGroup integration test using RSpec + +describe 'Integration testing of ResourceGroup' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @resource_service = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @resource_group_name = 'TestRG-RG' + @location = 'eastus' + @tags = { key1: 'value1', key2: 'value2' } + end + + describe 'Create' do + before :all do + @resource_group = @resource_service.resource_groups.create(name: @resource_group_name, location: @location, tags: @tags) + end + + it 'it\'s name is TestRG-RG' do + expect(@resource_group.name).to eq(@resource_group_name) + end + + it 'it\'s in eastus' do + expect(@resource_group.location).to eq(@location) + end + + it 'it\'s tag values are \'value1\' and \'value2\'' do + expect(@resource_group.tags['key1']).to eq(@tags[:key1]) + expect(@resource_group.tags['key2']).to eq(@tags[:key2]) + end + end + + describe 'Get' do + before 'get resource group' do + @resource_group = @resource_service.resource_groups.get(@resource_group_name) + end + + it 'it\'s name is TestRG-RG' do + expect(@resource_group.name).to eq(@resource_group_name) + end + + end + + describe 'List' do + before :all do + @resource_group_list = @resource_service.resource_groups + end + + it 'it\'s not empty' do + expect(@resource_group_list.length).to_not eq(0) + end + + it 'contains TestRG-RG' do + contains_test_rg = false + @resource_group_list.each do |resource_group| + contains_test_rg = true if resource_group.name == 'TestRG-RG' + end + expect(contains_test_rg).to eq(true) + end + end + + describe 'Delete' do + before 'get resource group' do + @resource_group = @resource_service.resource_groups.get(@resource_group_name) + end + + it 'it\'s deleted' do + expect(@resource_group.destroy).to eq(true) + end + end +end \ No newline at end of file From 1ba7121c258577bb24386c225a72edd93393e903 Mon Sep 17 00:00:00 2001 From: Maham Nazir Date: Wed, 14 Mar 2018 12:42:19 +0500 Subject: [PATCH 2/4] ITs in Rspec Format --- .../availability_set_managed_spec.rb | 199 +++++++++++ .../availability_set_unmanaged_spec.rb | 190 ++++++++++ .../integration/local_network_gateway_spec.rb | 146 ++++++++ .../network_security_group_spec.rb | 3 +- test/integration/resource_group_spec.rb | 2 +- test/integration/storage_account_spec.rb | 330 ++++++++++++++++++ 6 files changed, 868 insertions(+), 2 deletions(-) create mode 100644 test/integration/availability_set_managed_spec.rb create mode 100644 test/integration/availability_set_unmanaged_spec.rb create mode 100644 test/integration/local_network_gateway_spec.rb create mode 100644 test/integration/storage_account_spec.rb diff --git a/test/integration/availability_set_managed_spec.rb b/test/integration/availability_set_managed_spec.rb new file mode 100644 index 000000000..9455a5342 --- /dev/null +++ b/test/integration/availability_set_managed_spec.rb @@ -0,0 +1,199 @@ +require 'fog/azurerm' +require 'yaml' + +# Managed Availability Set Integration Test using RSpec + +describe 'Integration Testing of Managed Availability Set' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @resource = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @compute = Fog::Compute::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'], + environment: azure_credentials['environment'] + ) + + @resource_group_name = 'TestRG-AS-M' + @location = 'eastus' + @managed_as_name_default = 'ASManagedDefault' + @managed_as_name_custom = 'ASManagedCustom' + + @resource_group = @resource.resource_groups.create( + name: @resource_group_name, + location: @location + ) + end + + describe 'Check Existence' do + before :all do + @as_md_exists = @compute.availability_sets.check_availability_set_exists(@resource_group_name, @managed_as_name_default) + @as_mc_exists = @compute.availability_sets.check_availability_set_exists(@resource_group_name, @managed_as_name_custom) + end + + context 'Managed Default Availability Set' do + it 'should not exist yet' do + expect(@as_md_exists).to eq(false) + end + end + + context 'Managed Custom Availability Set' do + it 'should not exist yet' do + expect(@as_mc_exists).to eq(false) + end + end + end + + describe 'Create' do + before :all do + @tags = { + key1: 'value1', + key2: 'value2' + } + end + + context 'Managed Default Availability Set' do + before :all do + @avail_set = @compute.availability_sets.create( + name: @managed_as_name_default, + location: @location, + resource_group: @resource_group_name, + tags: @tags, + use_managed_disk: true + ) + end + + it 'should have name: \'ASManagedDefault\'' do + expect(@avail_set.name).to eq(@managed_as_name_default) + end + + it 'should exist in resource group: \'TestRG-AS\'' do + expect(@avail_set.resource_group).to eq(@resource_group_name) + end + + it 'should exist in location: \'eastus\'' do + expect(@avail_set.location).to eq(@location) + end + + it 'should be a managed availability set' do + expect(@avail_set.use_managed_disk).to eq(true) + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@avail_set.tags['key1']).to eq(@tags[:key1]) + expect(@avail_set.tags['key2']).to eq(@tags[:key2]) + end + end + + context 'Managed Custom Availability Set' do + before :all do + @fault_domain_count = 3 + @update_domain_count = 10 + + @avail_set = @compute.availability_sets.create( + name: @managed_as_name_custom, + location: @location, + resource_group: @resource_group_name, + tags: @tags, + platform_fault_domain_count: @fault_domain_count, + platform_update_domain_count: @update_domain_count, + use_managed_disk: true + ) + end + + it 'should have name: \'ASManagedCustom\'' do + expect(@avail_set.name).to eq(@managed_as_name_custom) + end + + it 'should exist in resource group: \'TestRG-AS\'' do + expect(@avail_set.resource_group).to eq(@resource_group_name) + end + + it 'should exist in location: \'eastus\'' do + expect(@avail_set.location).to eq(@location) + end + + it 'should be a managed availability set' do + expect(@avail_set.use_managed_disk).to eq(true) + end + + it 'should have fault domain count: 3' do + expect(@avail_set.platform_fault_domain_count).to eq(@fault_domain_count) + end + + it 'should have update domain count: 10' do + expect(@avail_set.platform_update_domain_count).to eq(@update_domain_count) + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@avail_set.tags['key1']).to eq(@tags[:key1]) + expect(@avail_set.tags['key2']).to eq(@tags[:key2]) + end + end + end + + + describe 'Get' do + context 'Managed Default Availability Set' do + before :all do + @avail_set = @compute.availability_sets.get(@resource_group_name, @managed_as_name_default) + end + + it 'should have name: \'ASManagedDefault\'' do + expect(@avail_set.name).to eq(@managed_as_name_default) + end + end + + context 'Managed Custom Availability Set' do + before :all do + @avail_set = @compute.availability_sets.get(@resource_group_name, @managed_as_name_custom) + end + + it 'should have name: \'ASManagedCustom\'' do + expect(@avail_set.name).to eq(@managed_as_name_custom) + end + end + end + + describe 'List' do + before :all do + @avail_sets = @compute.availability_sets(resource_group: @resource_group_name) + end + + it 'should not be empty' do + expect(@avail_sets.length).to_not eq(0) + end + + it 'should contain availability sets: \'ASManagedDefault\' & \'ASManagedCustom\'' do + contains_as_default = false + contains_as_custom = false + @avail_sets.each do |avail_set| + contains_as_default = true if avail_set.name == @managed_as_name_default + contains_as_custom = true if avail_set.name == @managed_as_name_custom + end + expect(contains_as_default).to eq(true) + expect(contains_as_custom).to eq(true) + end + end + + describe 'Delete' do + before 'gets managed availability sets' do + @avail_set_default = @compute.availability_sets.get(@resource_group_name, @managed_as_name_default) + @avail_set_custom = @compute.availability_sets.get(@resource_group_name, @managed_as_name_custom) + end + + it 'should not exist anymore' do + expect(@avail_set_default.destroy).to eq(true) + expect(@avail_set_custom.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end +end \ No newline at end of file diff --git a/test/integration/availability_set_unmanaged_spec.rb b/test/integration/availability_set_unmanaged_spec.rb new file mode 100644 index 000000000..3b8ac2895 --- /dev/null +++ b/test/integration/availability_set_unmanaged_spec.rb @@ -0,0 +1,190 @@ +require 'fog/azurerm' +require 'yaml' + +# Unmanaged Availability Set Integration Test using RSpec + +describe 'Integration Testing of Un-Managed Availability Set' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @resource = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @compute = Fog::Compute::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'], + environment: azure_credentials['environment'] + ) + + @resource_group_name = 'TestRG-AS-U' + @location = 'eastus' + @unmanaged_as_name_default = 'ASUnmanagedDefault' + @unmanaged_as_name_custom = 'ASUnmanagedCustom' + @managed_as_name_default = 'ASManagedDefault' + @managed_as_name_custom = 'ASManagedCustom' + + @resource_group = @resource.resource_groups.create( + name: @resource_group_name, + location: @location + ) + end + + describe 'Check Existence' do + before :all do + @as_ud_exists = @compute.availability_sets.check_availability_set_exists(@resource_group_name, @unmanaged_as_name_default) + @as_uc_exists = @compute.availability_sets.check_availability_set_exists(@resource_group_name, @unmanaged_as_name_custom) + end + + context 'Unmanaged Default Availability Set' do + it 'should not exist yet' do + expect(@as_ud_exists).to eq(false) + end + end + + context 'Unmanaged Custom Availability Set' do + it 'should not exist yet' do + expect(@as_uc_exists).to eq(false) + end + end + end + + describe 'Create' do + before :all do + @tags = { + key1: 'value1', + key2: 'value2' + } + end + + context 'Unmanaged Default Availability Set' do + before :all do + @avail_set = @compute.availability_sets.create( + name: @unmanaged_as_name_default, + location: @location, + resource_group: @resource_group_name, + tags: @tags + ) + end + + it 'should have name: \'ASUnmanagedDefault\'' do + expect(@avail_set.name).to eq(@unmanaged_as_name_default) + end + + it 'should exist in resource group: \'TestRG-AS\'' do + expect(@avail_set.resource_group).to eq(@resource_group_name) + end + + it 'should exist in location: \'eastus\'' do + expect(@avail_set.location).to eq(@location) + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@avail_set.tags['key1']).to eq(@tags[:key1]) + expect(@avail_set.tags['key2']).to eq(@tags[:key2]) + end + end + + context 'Unmanaged Custom Availability Set' do + before :all do + @fault_domain_count = 3 + @update_domain_count = 10 + + @avail_set = @compute.availability_sets.create( + name: @unmanaged_as_name_custom, + location: @location, + resource_group: @resource_group_name, + tags: @tags, + platform_fault_domain_count: @fault_domain_count, + platform_update_domain_count: @update_domain_count + ) + end + + it 'should have name: \'ASUnmanagedCustom\'' do + expect(@avail_set.name).to eq(@unmanaged_as_name_custom) + end + + it 'should exist in resource group: \'TestRG-AS\'' do + expect(@avail_set.resource_group).to eq(@resource_group_name) + end + + it 'should exist in location: \'eastus\'' do + expect(@avail_set.location).to eq(@location) + end + + it 'should have fault domain count: 3' do + expect(@avail_set.platform_fault_domain_count).to eq(@fault_domain_count) + end + + it 'should have update domain count: 10' do + expect(@avail_set.platform_update_domain_count).to eq(@update_domain_count) + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@avail_set.tags['key1']).to eq(@tags[:key1]) + expect(@avail_set.tags['key2']).to eq(@tags[:key2]) + end + end + end + + describe 'Get' do + context 'Un-Managed Default Availability Set' do + before :all do + @avail_set = @compute.availability_sets.get(@resource_group_name, @unmanaged_as_name_default) + end + + it 'should have name: \'ASUnmanagedDefault\'' do + expect(@avail_set.name).to eq(@unmanaged_as_name_default) + end + end + + context 'Un-Managed Custom Availability Set' do + before :all do + @avail_set = @compute.availability_sets.get(@resource_group_name, @unmanaged_as_name_custom) + end + + it 'should have name: \'ASUnmanagedCustom\'' do + expect(@avail_set.name).to eq(@unmanaged_as_name_custom) + end + end + end + + describe 'List' do + before :all do + @avail_sets = @compute.availability_sets(resource_group: @resource_group_name) + end + + it 'should not be empty' do + expect(@avail_sets.length).to_not eq(0) + end + + it 'should contain availability sets: \'ASUnmanagedDefault\' & \'ASUnmanagedCustom\'' do + contains_as_default = false + contains_as_custom = false + @avail_sets.each do |avail_set| + contains_as_default = true if avail_set.name == @unmanaged_as_name_default + contains_as_custom = true if avail_set.name == @unmanaged_as_name_custom + end + expect(contains_as_default).to eq(true) + expect(contains_as_custom).to eq(true) + end + end + + describe 'Delete' do + before 'gets unmanaged availability sets' do + @avail_set_default = @compute.availability_sets.get(@resource_group_name, @unmanaged_as_name_default) + @avail_set_custom = @compute.availability_sets.get(@resource_group_name, @unmanaged_as_name_custom) + end + + it 'should not exist anymore' do + expect(@avail_set_default.destroy).to eq(true) + expect(@avail_set_custom.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end +end \ No newline at end of file diff --git a/test/integration/local_network_gateway_spec.rb b/test/integration/local_network_gateway_spec.rb new file mode 100644 index 000000000..d1986eb1c --- /dev/null +++ b/test/integration/local_network_gateway_spec.rb @@ -0,0 +1,146 @@ +require 'fog/azurerm' +require 'yaml' + +# Local Network Gateway Integration Test using RSpec + +describe 'Integration Testing of Local Network Gateway' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @resource = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @network = Fog::Network::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @location = 'eastus' + @local_net_gateway_name = 'testLocalNetGateway' + + @resource_group = @resource.resource_groups.create( + name: 'TestRG-LNG', + location: @location + ) + + end + + describe 'Check Existence' do + before 'checks existence of local network gateway' do + @lng_exists = @network.local_network_gateways.check_local_net_gateway_exists(@resource_group.name, @local_net_gateway_name) + end + + it 'should not exist yet' do + expect(@lng_exists).to eq(false) + end + end + + describe 'Create' do + before :all do + + @tags = { + key1: 'value1', + key2: 'value2' + } + @gateway_IP = '192.168.1.1' + @asn = 100 + @bgp_peering_address = '192.168.1.2' + @peer_weight = 3 + + @local_network_gateway = @network.local_network_gateways.create( + name: @local_net_gateway_name, + location: @location, + tags: @tags, + resource_group: @resource_group.name, + gateway_ip_address: @gateway_IP, + local_network_address_space_prefixes: [], + asn: @asn, + bgp_peering_address: @bgp_peering_address, + peer_weight: @peer_weight + ) + end + + it 'should have name: \'testLocalNetGateway\'' do + expect(@local_network_gateway.name).to eq(@local_net_gateway_name) + end + + it 'should belong to resource group: \'TestRG-LNG\'' do + expect(@local_network_gateway.resource_group).to eq(@resource_group.name) + end + + it 'should exist in location: \'eastus\'' do + expect(@local_network_gateway.location).to eq(@location) + end + + it 'should have gateway IP address: \'192.168.1.1\'' do + expect(@local_network_gateway.gateway_ip_address).to eq(@gateway_IP) + end + + it 'should have peer weight: \'3\'' do + expect(@local_network_gateway.peer_weight).to eq(@peer_weight) + end + + it 'should have ASN: \'100\'' do + expect(@local_network_gateway.asn).to eq(@asn) + end + + it 'should have BPG peering address: \'192.168.1.2\'' do + expect(@local_network_gateway.bgp_peering_address).to eq(@bgp_peering_address) + end + + it 'should have no local network address space prefixes' do + expect(@local_network_gateway.local_network_address_space_prefixes.empty?).to eq(true) + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@local_network_gateway.tags['key1']).to eq(@tags[:key1]) + expect(@local_network_gateway.tags['key2']).to eq(@tags[:key2]) + end + end + + describe 'Get' do + before 'gets network security rule' do + @local_network_gateway = @network.local_network_gateways.get(@resource_group.name, @local_net_gateway_name) + end + + it 'should have name: \'testLocalNetGateway\'' do + expect(@local_network_gateway.name).to eq(@local_net_gateway_name) + end + end + + describe 'List' do + before :all do + @local_network_gateways = @network.local_network_gateways(resource_group: @resource_group.name) + end + + it 'should not be empty' do + expect(@local_network_gateways.length).to_not eq(0) + end + + it 'should contain local network gateway: \'testLocalNetGateway\'' do + contains_lng = false + @local_network_gateways.each do |gateway| + contains_lng = true if gateway.name == @local_net_gateway_name + end + expect(contains_lng).to eq(true) + end + end + + describe 'Delete' do + before 'gets local network gateway' do + @local_network_gateway = @network.local_network_gateways.get(@resource_group.name, @local_net_gateway_name) + end + + it 'should not exist anymore' do + expect(@local_network_gateway.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end + +end \ No newline at end of file diff --git a/test/integration/network_security_group_spec.rb b/test/integration/network_security_group_spec.rb index 13fdfc23d..110d15100 100644 --- a/test/integration/network_security_group_spec.rb +++ b/test/integration/network_security_group_spec.rb @@ -23,7 +23,6 @@ @location = 'eastus' @net_sec_group_name = 'testNetSecGroup' - @tags = { key1: 'value1', key2: 'value2' } @security_rules = [ { name: 'testRule', @@ -56,6 +55,8 @@ describe 'Create' do before :all do + @tags = { key1: 'value1', key2: 'value2' } + @network_security_group = @network.network_security_groups.create( name: @net_sec_group_name, resource_group: @resource_group.name, diff --git a/test/integration/resource_group_spec.rb b/test/integration/resource_group_spec.rb index c4088cd5c..e0a1b3e4d 100644 --- a/test/integration/resource_group_spec.rb +++ b/test/integration/resource_group_spec.rb @@ -16,11 +16,11 @@ @resource_group_name = 'TestRG-RG' @location = 'eastus' - @tags = { key1: 'value1', key2: 'value2' } end describe 'Create' do before :all do + @tags = { key1: 'value1', key2: 'value2' } @resource_group = @resource_service.resource_groups.create(name: @resource_group_name, location: @location, tags: @tags) end diff --git a/test/integration/storage_account_spec.rb b/test/integration/storage_account_spec.rb new file mode 100644 index 000000000..1a60455e2 --- /dev/null +++ b/test/integration/storage_account_spec.rb @@ -0,0 +1,330 @@ +require 'fog/azurerm' +require 'yaml' + +# Storage Account Integration Test using RSpec + +describe 'Integration Testing of Storage Account' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @resource = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @storage = Fog::Storage::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'], + environment: azure_credentials['environment'] + ) + + @location = 'eastus' + @lrs_sa_name = 'testlrssa' + @grs_sa_name = 'testgrssa' + @premium_sa_name = 'testpremiumsa' + + @resource_group = @resource.resource_groups.create( + name: 'TestRG-SA', + location: @location + ) + end + + describe "Check Name Availability" do + context "Standard LRS Storage Account" do + before "checks name availability" do + @is_available = @storage.storage_accounts.check_name_availability(@lrs_sa_name) + end + + it "should be available, name: \'testlrssa\'" do + expect(@is_available).to eq(true) + end + end + + context "Standard GRS Storage Account" do + before "checks name availability" do + @is_available = @storage.storage_accounts.check_name_availability(@grs_sa_name) + end + + it "should be available, name: \'testgrssa\'" do + expect(@is_available).to eq(true) + end + end + + context "Premium LRS Storage Account" do + before "checks name availability" do + @is_available = @storage.storage_accounts.check_name_availability(@premium_sa_name) + end + + it "should be available, name: \'testpremiumsa\'" do + expect(@is_available).to eq(true) + end + end + end + + describe "Check Existence" do + context "Standard LRS Storage Account" do + before "checks existence" do + @sa_exists = @storage.storage_accounts.check_storage_account_exists(@resource_group.name, @lrs_sa_name) + end + + it "should not exist yet" do + expect(@sa_exists).to eq(false) + end + end + + context "Standard GRS Storage Account" do + before "checks existence" do + @sa_exists = @storage.storage_accounts.check_storage_account_exists(@resource_group.name, @grs_sa_name) + end + + it "should not exist yet" do + expect(@sa_exists).to eq(false) + end + end + + context "Premium LRS Storage Account" do + before "checks existence" do + @sa_exists = @storage.storage_accounts.check_storage_account_exists(@resource_group.name, @premium_sa_name) + end + + it "should not exist yet" do + expect(@sa_exists).to eq(false) + end + end + end + + describe "Create" do + before :all do + @tags = { key1: 'value1', key2: 'value2' } + end + + context "Standard LRS Storage Account" do + before :all do + @storage_account = @storage.storage_accounts.create( + name: @lrs_sa_name, + location: @location, + resource_group: @resource_group.name, + tags: @tags + ) + end + + it "should have name: \'testlrssa\'" do + expect(@storage_account.name).to eq(@lrs_sa_name) + end + + it 'should belong to resource group: \'TestRG-SA\'' do + expect(@storage_account.resource_group).to eq(@resource_group.name) + end + + it 'should exist in location: \'eastus\'' do + expect(@storage_account.location).to eq(@location) + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@storage_account.tags['key1']).to eq(@tags[:key1]) + expect(@storage_account.tags['key2']).to eq(@tags[:key2]) + end + end + + context "Standard GRS Storage Account" do + before :all do + @replication = 'GRS' + @sku_name = Fog::ARM::Storage::Models::SkuTier::Standard + + @storage_account = @storage.storage_accounts.create( + name: @grs_sa_name, + location: @location, + resource_group: @resource_group.name, + sku_name: @sku_name, + replication: @replication, + encryption: true, + tags: @tags + ) + end + + it "should have name: \'testgrssa\'" do + expect(@storage_account.name).to eq(@grs_sa_name) + end + + it 'should belong to resource group: \'TestRG-SA\'' do + expect(@storage_account.resource_group).to eq(@resource_group.name) + end + + it 'should exist in location: \'eastus\'' do + expect(@storage_account.location).to eq(@location) + end + + it "should have replication: \'GRS\'" do + expect(@storage_account.replication).to eq(@replication) + end + + it "should be encrypted" do + expect(@storage_account.encryption).to eq(true) + end + + it "should have SKU type: \'Standard\'" do + expect(@storage_account.sku_name).to eq(@sku_name) + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@storage_account.tags['key1']).to eq(@tags[:key1]) + expect(@storage_account.tags['key2']).to eq(@tags[:key2]) + end + end + + context "Premium LRS Storage Account" do + before :all do + @replication = 'LRS' + @sku_name = Fog::ARM::Storage::Models::SkuTier::Premium + + @storage_account = @storage.storage_accounts.create( + name: @premium_sa_name, + location: @location, + resource_group: @resource_group.name, + sku_name: @sku_name, + replication: @replication, + tags: @tags + ) + end + + it "should have name: \'testpremiumsa\'" do + expect(@storage_account.name).to eq(@premium_sa_name) + end + + it 'should belong to resource group: \'TestRG-SA\'' do + expect(@storage_account.resource_group).to eq(@resource_group.name) + end + + it 'should exist in location: \'eastus\'' do + expect(@storage_account.location).to eq(@location) + end + + it "should have replication: \'LRS\'" do + expect(@storage_account.replication).to eq(@replication) + end + + it "should have SKU type: \'Premium\'" do + expect(@storage_account.sku_name).to eq(@sku_name) + end + + it 'should contain tag values \'value1\' and \'value2\'' do + expect(@storage_account.tags['key1']).to eq(@tags[:key1]) + expect(@storage_account.tags['key2']).to eq(@tags[:key2]) + end + end + end + + describe "Update" do + context "Premium LRS Storage Account" do + before "updates premium storage account" do + @premium_sa = @storage.storage_accounts.get(@resource_group.name, @premium_sa_name) + @updated_premium_sa = @premium_sa.update(encryption: true) + end + + it "should be encrypted" do + expect(@updated_premium_sa.encryption).to eq(true) + end + end + end + + describe "Get" do + context "Standard LRS Storage Account" do + before "gets standard LRS account" do + @lrs_sa = @storage.storage_accounts.get(@resource_group.name, @lrs_sa_name) + end + + it "should have name: \'testlrssa\'" do + expect(@lrs_sa.name).to eq(@lrs_sa_name) + end + end + + context "Standard GRS Storage Account" do + before "gets standard GRS account" do + @grs_sa = @storage.storage_accounts.get(@resource_group.name, @grs_sa_name) + end + + it "should have name: \'testgrssa\'" do + expect(@grs_sa.name).to eq(@grs_sa_name) + end + end + + context "Premium LRS Storage Account" do + before "gets standard GRS account" do + @premium_sa = @storage.storage_accounts.get(@resource_group.name, @premium_sa_name) + end + + it "should have name: \'testpremiumsa\'" do + expect(@premium_sa.name).to eq(@premium_sa_name) + end + end + end + + describe "List" do + context 'Within a Subscription' do + before 'lists all storage accounts within a subscription' do + @sa_in_subscription = @storage.storage_accounts + end + + it 'should not be empty' do + expect(@sa_in_subscription.length).not_to eq(0) + end + end + + context 'Within the Resource Group' do + before 'lists all storage accounts in the resource group' do + @storage_accounts_list = @storage.storage_accounts(resource_group: @resource_group.name) + end + + it 'should contain storage accounts: \'testlrssa\', \'testgrssa\', \'testpremiumsa\'' do + contains_lrs_sa = false + contains_grs_sa = false + contains_premium_sa = false + @storage_accounts_list.each do |storage_account| + contains_lrs_sa = true if storage_account.name == @lrs_sa_name + contains_grs_sa = true if storage_account.name == @grs_sa_name + contains_premium_sa = true if storage_account.name == @premium_sa_name + end + expect(contains_lrs_sa).to eq(true) + expect(contains_grs_sa).to eq(true) + expect(contains_premium_sa).to eq(true) + end + end + end + + describe "Delete" do + context "Standard LRS Storage Account" do + before "gets standard LRS account" do + @lrs_sa = @storage.storage_accounts.get(@resource_group.name, @lrs_sa_name) + end + + it "should not exist anymore" do + expect(@lrs_sa.destroy).to eq(true) + end + end + + context "Standard GRS Storage Account" do + before "gets standard GRS account" do + @grs_sa = @storage.storage_accounts.get(@resource_group.name, @grs_sa_name) + end + + it "should not exist anymore" do + expect(@grs_sa.destroy).to eq(true) + end + end + + context "Premium LRS Storage Account" do + before "gets standard GRS account" do + @premium_sa = @storage.storage_accounts.get(@resource_group.name, @premium_sa_name) + end + + it "should not exist anymore" do + expect(@premium_sa.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end + end +end \ No newline at end of file From 69d2812262ea04428410b1113b287da44a9c9aae Mon Sep 17 00:00:00 2001 From: Muhammad Asad Date: Fri, 16 Mar 2018 13:10:41 +0500 Subject: [PATCH 3/4] Public Ip/ Resource Tags/ Traffic Manager rspec tests added --- test/integration/public_ip_spec.rb | 129 ++++++++++++ test/integration/resource_tag_spec.rb | 95 +++++++++ test/integration/sql_server_spec.rb | 118 +++++++++++ test/integration/traffic_manager_spec.rb | 243 +++++++++++++++++++++++ 4 files changed, 585 insertions(+) create mode 100644 test/integration/public_ip_spec.rb create mode 100644 test/integration/resource_tag_spec.rb create mode 100644 test/integration/sql_server_spec.rb create mode 100644 test/integration/traffic_manager_spec.rb diff --git a/test/integration/public_ip_spec.rb b/test/integration/public_ip_spec.rb new file mode 100644 index 000000000..40963a96d --- /dev/null +++ b/test/integration/public_ip_spec.rb @@ -0,0 +1,129 @@ +require 'fog/azurerm' +require 'yaml' + +# Public Ip integration test using RSpec + +describe 'Integration testing of Public Ip' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @resource_service = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @network_service = Fog::Network::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @resource_group_name = 'TestRG-PB' + @location = 'eastus' + @public_ip_name = 'Test-Public-IP' + @public_ip_allocation_method = 'Dynamic' + @domain_label = 'newdomainlabel' + @resource_group = @resource_service.resource_groups.create(name: @resource_group_name, location: @location) + end + + describe 'Check Existence' do + before :all do + @public_ip_exits = @network_service.public_ips.check_public_ip_exists(@resource_group_name, @public_ip_name) + end + + context 'Public Ip' do + it 'should not exist yet' do + expect(@public_ip_exits).to eq(false) + end + end + end + + describe 'Create' do + before :all do + @tags = { key1: 'value1', key2: 'value2' } + @public_ip = @network_service.public_ips.create( + name: @public_ip_name, + resource_group: @resource_group_name, + location: @location, + public_ip_allocation_method: Fog::ARM::Network::Models::IPAllocationMethod::Dynamic, + tags: @tags + ) + end + + it 'it\'s name is Test-Public-IP' do + expect(@public_ip.name).to eq(@public_ip_name) + end + + it 'should exist in resource group: \'TestRG-PB\'' do + expect(@public_ip.resource_group).to eq(@resource_group_name) + end + + it 'it\'s in eastus' do + expect(@public_ip.location).to eq(@location) + end + + it 'it\'s tag values are \'value1\' and \'value2\'' do + expect(@public_ip.tags['key1']).to eq(@tags[:key1]) + expect(@public_ip.tags['key2']).to eq(@tags[:key2]) + end + + it 'it\'s idle timeout in minutes is \'4\'' do + expect(@public_ip.idle_timeout_in_minutes).to eq(4) + end + + it 'it\'s public IP allocation method is \'Dynamic\'' do + expect(@public_ip.public_ip_allocation_method).to eq(@public_ip_allocation_method) + end + + it 'it\'s domain name label is \'nil\'' do + expect(@public_ip.domain_name_label).to eq(nil) + end + end + + describe 'Get' do + before :all do + @public_ip = @network_service.public_ips.get(@resource_group_name, @public_ip_name) + end + + it 'should have name: \'Test-Public-IP\'' do + expect(@public_ip.name).to eq(@public_ip_name) + end + end + + describe 'Update' do + before :all do + @public_ip = @network_service.public_ips.get(@resource_group_name, @public_ip_name) + @public_ip.update( + public_ip_allocation_method: Fog::ARM::Network::Models::IPAllocationMethod::Dynamic, + idle_timeout_in_minutes: '10', + domain_name_label: @domain_label + ) + end + + it 'it\'s idle timeout in minutes is \'10\'' do + expect(@public_ip.idle_timeout_in_minutes).to eq(10) + end + + it 'it\'s public IP allocation method is \'Dynamic\'' do + expect(@public_ip.public_ip_allocation_method).to eq(@public_ip_allocation_method) + end + + it 'it\'s domain name label is \'newdomainlabel\'' do + expect(@public_ip.domain_name_label).to eq(@domain_label) + end + end + + describe 'Delete' do + before :all do + @public_ip = @network_service.public_ips.get(@resource_group_name, @public_ip_name) + end + + it 'should not exist anymore' do + expect(@public_ip.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end +end diff --git a/test/integration/resource_tag_spec.rb b/test/integration/resource_tag_spec.rb new file mode 100644 index 000000000..b7994d212 --- /dev/null +++ b/test/integration/resource_tag_spec.rb @@ -0,0 +1,95 @@ +require 'fog/azurerm' +require 'yaml' + +# Resource Tag integration test using RSpec + +describe 'Integration testing of Resource Tag' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @resource_service = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @network_service = Fog::Network::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @resource_group_name = 'TestRG-RT' + @location = 'eastus' + @resource_name = 'Test-Public-IP' + @resource_group = @resource_service.resource_groups.create(name: @resource_group_name, location: @location) + @resource_id = @network_service.public_ips.create( + name: @resource_name, + resource_group: @resource_group_name, + location: @location, + public_ip_allocation_method: Fog::ARM::Network::Models::IPAllocationMethod::Dynamic + ).id + end + + describe 'Check Existence' do + before :all do + @resource_exits = @resource_service.azure_resources.check_azure_resource_exists(@resource_id, '2016-09-01') + end + + context 'Azure Resource' do + it 'should exist' do + expect(@resource_exits).to eq(false) + end + end + end + + describe 'Tag Resource' do + before :all do + @tag_resource = @resource_service.tag_resource( + @resource_id, + 'test-key', + 'test-value', + '2016-06-01' + ) + end + + it 'Resource should be tagged' do + expect(@tag_resource).to eq(true) + end + end + + describe 'Get' do + before :all do + @resources = @resource_service.azure_resources(tag_name: 'test-key', tag_value: 'test-value') + @resource = @resource_service.azure_resources(tag_name: 'test-key').get(@resource_id) + end + + it 'should have resources' do + expect(@resources.length).not_to eq(0) + end + + it 'should have a resource attached' do + expect(@resource.id).to eq(@resource_id) + end + end + + describe 'Delete' do + before :all do + @public_ip = @network_service.public_ips.get(@resource_group_name, @resource_name) + @resource_tag_removed = @resource_service.delete_resource_tag( + @resource_id, + 'test-key', + 'test-value', + '2016-06-01' + ) + end + + it 'should not exist anymore' do + expect(@resource_tag_removed).to eq(true) + expect(@public_ip.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end +end diff --git a/test/integration/sql_server_spec.rb b/test/integration/sql_server_spec.rb new file mode 100644 index 000000000..10d3a7d76 --- /dev/null +++ b/test/integration/sql_server_spec.rb @@ -0,0 +1,118 @@ +require 'fog/azurerm' +require 'yaml' + +# Sql Serverintegration test using RSpec + +describe 'Integration testing of Sql Server' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @resource_service = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @azure_sql_service = Fog::Sql::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @resource_group_name = 'TestRG-SQL' + @location = 'eastus2' + @tags = { key1: 'value1', key2: 'value2' } + @server_name = rand(0...999_99) + @database_name = rand(0...999_99) + @version = '12.0' + @administrator_login = 'testserveradmin', + @administrator_login_password = 'db@admin=123' + @resource_group = @resource_service.resource_groups.create(name: @resource_group_name, location: @location) + end + + describe 'Check Sql Server Existence' do + before :all do + @sql_server_exits = @azure_sql_service.sql_servers.check_sql_server_exists(@resource_group_name, @server_name) + end + + it 'should not exist yet' do + expect(@sql_server_exits).to eq(false) + end + end + + describe 'Create Sql Server' do + before :all do + @sql_server = @azure_sql_service.sql_servers.create( + name: @server_name, + resource_group: @resource_group_name, + location: @location, + tags: @tags, + version: @version, + administrator_login: @administrator_login, + administrator_login_password: @administrator_login_password + ) + end + + it "it\'s name is #{@server_name}" do + expect(@sql_server.name).to eq(@server_name) + end + + it 'should exist in resource group: \'TestRG-SQL\'' do + expect(@sql_server.resource_group).to eq(@resource_group_name) + end + + it 'it\'s in eastus' do + expect(@sql_server.location).to eq(@location) + end + + it 'it\'s tag values are \'value1\' and \'value2\'' do + expect(@sql_server.tags['key1']).to eq(@tags[:key1]) + expect(@sql_server.tags['key2']).to eq(@tags[:key2]) + end + end + + describe 'Check Sql Database Existence' do + before :all do + @sql_database = @azure_sql_service.sql_databases.check_database_exists(@resource_group_name, @server_name, @database_name) + end + + it "should have name: '#{@database_name}'" do + expect(@sql_database.name).to eq(@database_name) + end + end + + describe 'Create Sql Database' do + before :all do + @sql_database = @azure_sql_service.sql_databases.create( + name: @database_name, + resource_group: @resource_group_name, + location: @location, + tags: @tags, + server_name: @server_name + ) + end + + it "it\'s name is #{@database_name}" do + expect(@sql_database.name).to eq(@database_name) + end + + it 'should exist in resource group: \'TestRG-SQL\'' do + expect(@sql_database.resource_group).to eq(@resource_group_name) + end + + it 'it\'s in eastus' do + expect(@sql_database.location).to eq(@location) + end + + it "it's in sql server: '#{@server_name}'" do + expect(@sql_database.server_name).to eq(@server_name) + end + + it 'it\'s tag values are \'value1\' and \'value2\'' do + expect(@sql_database.tags['key1']).to eq(@tags[:key1]) + expect(@sql_database.tags['key2']).to eq(@tags[:key2]) + end + end +end diff --git a/test/integration/traffic_manager_spec.rb b/test/integration/traffic_manager_spec.rb new file mode 100644 index 000000000..047c29a8c --- /dev/null +++ b/test/integration/traffic_manager_spec.rb @@ -0,0 +1,243 @@ +require 'fog/azurerm' +require 'yaml' + +# Traffic Manager integration test using RSpec + +describe 'Integration testing of Traffic Manager' do + before :all do + azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) + + @resource_service = Fog::Resources::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @traffic_manager_service = Fog::TrafficManager::AzureRM.new( + tenant_id: azure_credentials['tenant_id'], + client_id: azure_credentials['client_id'], + client_secret: azure_credentials['client_secret'], + subscription_id: azure_credentials['subscription_id'] + ) + + @resource_group_name = 'TestRG-TM' + @location = 'eastus' + @traffic_manager_profile_name = 'test-tmp' + @traffic_manager_endpoint_name = 'myendpoint' + @endpoint_type = 'externalEndpoints' + @resource_group = @resource_service.resource_groups.create(name: @resource_group_name, location: @location) + end + + describe 'Check Existence of Traffic Manager Profile' do + before :all do + @traffic_manager_profile_exits = @traffic_manager_service.traffic_manager_profiles.check_traffic_manager_profile_exists(@resource_group_name, @traffic_manager_profile_name) + end + + it 'should not exist yet' do + expect(@traffic_manager_profile_exits).to eq(false) + end + end + + describe 'Create Profile' do + before :all do + @tags = { key1: 'value1', key2: 'value2' } + @traffic_manager_profile = @traffic_manager_service.traffic_manager_profiles.create( + name: @traffic_manager_profile_name, + resource_group: @resource_group_name, + tags: @tags, + traffic_routing_method: 'Performance', + relative_name: 'testapplication', + ttl: '30', + protocol: 'http', + port: '80', + path: '/monitorpage.aspx', + endpoints: [{ + name: 'endpoint1', + type: @endpoint_type, + target: 'test-app.com', + endpoint_location: 'eastus', + endpoint_status: 'Enabled', + priority: 5, + weight: 10 + }] + ) + end + + it 'it\'s name is test-tmp' do + expect(@traffic_manager_profile.name).to eq(@traffic_manager_profile_name) + end + + it 'should exist in resource group: \'TestRG-TM\'' do + expect(@traffic_manager_profile.resource_group).to eq(@resource_group_name.downcase) + end + + it 'it\'s in global' do + expect(@traffic_manager_profile.location).to eq('global') + end + + it 'it\'s tag values are \'value1\' and \'value2\'' do + expect(@traffic_manager_profile.tags['key1']).to eq(@tags[:key1]) + expect(@traffic_manager_profile.tags['key2']).to eq(@tags[:key2]) + end + + it 'it\'s traffic routing method is \'Performance\'' do + expect(@traffic_manager_profile.traffic_routing_method).to eq('Performance') + end + + it 'it\'s ttl is \'30\'' do + expect(@traffic_manager_profile.ttl).to eq(30) + end + + it 'it\'s protocol is \'HTTP\'' do + expect(@traffic_manager_profile.protocol).to eq('HTTP') + end + + it 'it\'s port is \'80\'' do + expect(@traffic_manager_profile.port).to eq(80) + end + end + + describe 'Check Existence of Traffic Manager Endpoint' do + before :all do + @traffic_manager_endpoint_exits = @traffic_manager_service.traffic_manager_end_points.check_traffic_manager_endpoint_exists(@resource_group_name, @traffic_manager_profile_name, @traffic_manager_endpoint_name, @endpoint_type) + end + + it 'should not exist yet' do + expect(@traffic_manager_endpoint_exits).to eq(false) + end + end + + describe 'Create Endpoint' do + before :all do + @traffic_manager_endpoint = @traffic_manager_service.traffic_manager_end_points.create( + name: @traffic_manager_endpoint_name, + resource_group: @resource_group_name, + traffic_manager_profile_name: @traffic_manager_profile_name, + type: @endpoint_type, + target: 'test-app1.com', + endpoint_location: @location + ) + end + + it 'it\'s name is: \'myendpoint\'' do + expect(@traffic_manager_endpoint.name).to eq(@traffic_manager_endpoint_name) + end + + it 'should exist in resource group: \'TestRG-TM\'' do + expect(@traffic_manager_endpoint.resource_group).to eq(@resource_group_name.downcase) + end + + it 'it\'s endpoint location is: \'East US\'' do + expect(@traffic_manager_endpoint.endpoint_location).to eq('East US') + end + + it 'it\'s type is: \'externalEndpoints\'' do + expect(@traffic_manager_endpoint.type).to eq(@endpoint_type) + end + + it 'it\'s in: \'test-tmp\' profile' do + expect(@traffic_manager_endpoint.traffic_manager_profile_name).to eq(@traffic_manager_profile_name) + end + + it 'it\'s target is: \'test-app1.com\'' do + expect(@traffic_manager_endpoint.target).to eq('test-app1.com') + end + end + + describe 'Get Endpoint' do + before :all do + @traffic_manager_endpoint = @traffic_manager_service.traffic_manager_end_points.get(@resource_group_name, @traffic_manager_profile_name, @traffic_manager_endpoint_name, @endpoint_type) + end + + it 'should have name: \'myendpoint\'' do + expect(@traffic_manager_endpoint.name).to eq(@traffic_manager_endpoint_name) + end + it 'should have profile: \'test-tmp\'' do + expect(@traffic_manager_endpoint.traffic_manager_profile_name).to eq(@traffic_manager_profile_name) + end + end + + describe 'Update Endpoint' do + before :all do + @traffic_manager_endpoint = @traffic_manager_service.traffic_manager_end_points.get(@resource_group_name, @traffic_manager_profile_name, @traffic_manager_endpoint_name, @endpoint_type) + @traffic_manager_endpoint.update( + type: @endpoint_type, + target: 'test-app2.com', + endpoint_location: 'centralus' + ) + end + + it 'it\'s endpoint location is: \'Central US\'' do + expect(@traffic_manager_endpoint.endpoint_location).to eq('Central US') + end + + it 'it\'s type is \'externalEndpoints\'' do + expect(@traffic_manager_endpoint.type).to eq(@endpoint_type) + end + + it 'it\'s target is: \'test-app2.com\'' do + expect(@traffic_manager_endpoint.target).to eq('test-app2.com') + end + end + + describe 'Delete Endpoint' do + before :all do + @traffic_manager_endpoint = @traffic_manager_service.traffic_manager_end_points.get(@resource_group_name, @traffic_manager_profile_name, @traffic_manager_endpoint_name, @endpoint_type) + end + + it 'should not exist anymore' do + expect(@traffic_manager_endpoint.destroy).to eq(true) + end + end + + describe 'Get Profile' do + before :all do + @traffic_manager_profile = @traffic_manager_service.traffic_manager_profiles.get(@resource_group_name, @traffic_manager_profile_name) + end + + it 'should have name: \'test-tmp\'' do + expect(@traffic_manager_profile.name).to eq(@traffic_manager_profile_name) + end + end + + describe 'Update Profile' do + before :all do + @traffic_manager_profile = @traffic_manager_service.traffic_manager_profiles.get(@resource_group_name, @traffic_manager_profile_name) + @traffic_manager_profile.update( + traffic_routing_method: 'Weighted', + ttl: '35', + protocol: 'https', + port: '90', + path: '/monitorpage1.aspx' + ) + end + + it 'it\'s traffic routing method is \'Weighted\'' do + expect(@traffic_manager_profile.traffic_routing_method).to eq('Weighted') + end + + it 'it\'s ttl is \'35\'' do + expect(@traffic_manager_profile.ttl).to eq(35) + end + + it 'it\'s protocol is \'HTTPS\'' do + expect(@traffic_manager_profile.protocol).to eq('HTTPS') + end + + it 'it\'s port is \'90\'' do + expect(@traffic_manager_profile.port).to eq(90) + end + end + + describe 'Delete Profile' do + before :all do + @traffic_manager_profile = @traffic_manager_service.traffic_manager_profiles.get(@resource_group_name, @traffic_manager_profile_name) + end + + it 'should not exist anymore' do + expect(@traffic_manager_profile.destroy).to eq(true) + expect(@resource_group.destroy).to eq(true) + end + end +end From e630faf997ae66941e8e664a58e456c2a9b1ee19 Mon Sep 17 00:00:00 2001 From: Muhammad Asad Date: Tue, 20 Mar 2018 10:54:32 +0500 Subject: [PATCH 4/4] Sql Server rspec test removed --- test/integration/sql_server_spec.rb | 118 ---------------------------- 1 file changed, 118 deletions(-) delete mode 100644 test/integration/sql_server_spec.rb diff --git a/test/integration/sql_server_spec.rb b/test/integration/sql_server_spec.rb deleted file mode 100644 index efc37275e..000000000 --- a/test/integration/sql_server_spec.rb +++ /dev/null @@ -1,118 +0,0 @@ -require 'fog/azurerm' -require 'yaml' - -# Sql Serverintegration test using RSpec - -describe 'Integration testing of Sql Server' do - before :all do - azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) - - @resource_service = Fog::Resources::AzureRM.new( - tenant_id: azure_credentials['tenant_id'], - client_id: azure_credentials['client_id'], - client_secret: azure_credentials['client_secret'], - subscription_id: azure_credentials['subscription_id'] - ) - - @azure_sql_service = Fog::Sql::AzureRM.new( - tenant_id: azure_credentials['tenant_id'], - client_id: azure_credentials['client_id'], - client_secret: azure_credentials['client_secret'], - subscription_id: azure_credentials['subscription_id'] - ) - - @resource_group_name = 'TestRG-SQL' - @location = 'eastus2' - @tags = { key1: 'value1', key2: 'value2' } - @server_name = rand(0...999_99) - @database_name = rand(0...999_99) - @version = '12.0' - @administrator_username = 'testserveradmin', - @administrator_login_password = 'db@admin=123' - @resource_group = @resource_service.resource_groups.create(name: @resource_group_name, location: @location) - end - - describe 'Check Sql Server Existence' do - before :all do - @sql_server_exits = @azure_sql_service.sql_servers.check_sql_server_exists(@resource_group_name, @server_name) - end - - it 'should not exist yet' do - expect(@sql_server_exits).to eq(false) - end - end - - describe 'Create Sql Server' do - before :all do - @sql_server = @azure_sql_service.sql_servers.create( - name: @server_name, - resource_group: @resource_group_name, - location: @location, - tags: @tags, - version: @version, - administrator_username: @administrator_username, - administrator_login_password: @administrator_login_password - ) - end - - it "it\'s name is #{@server_name}" do - expect(@sql_server.name).to eq(@server_name) - end - - it 'should exist in resource group: \'TestRG-SQL\'' do - expect(@sql_server.resource_group).to eq(@resource_group_name) - end - - it 'it\'s in eastus' do - expect(@sql_server.location).to eq(@location) - end - - it 'it\'s tag values are \'value1\' and \'value2\'' do - expect(@sql_server.tags['key1']).to eq(@tags[:key1]) - expect(@sql_server.tags['key2']).to eq(@tags[:key2]) - end - end - - describe 'Check Sql Database Existence' do - before :all do - @sql_database = @azure_sql_service.sql_databases.check_database_exists(@resource_group_name, @server_name, @database_name) - end - - it "should have name: '#{@database_name}'" do - expect(@sql_database.name).to eq(@database_name) - end - end - - describe 'Create Sql Database' do - before :all do - @sql_database = @azure_sql_service.sql_databases.create( - name: @database_name, - resource_group: @resource_group_name, - location: @location, - tags: @tags, - server_name: @server_name - ) - end - - it "it\'s name is #{@database_name}" do - expect(@sql_database.name).to eq(@database_name) - end - - it 'should exist in resource group: \'TestRG-SQL\'' do - expect(@sql_database.resource_group).to eq(@resource_group_name) - end - - it 'it\'s in eastus' do - expect(@sql_database.location).to eq(@location) - end - - it "it's in sql server: '#{@server_name}'" do - expect(@sql_database.server_name).to eq(@server_name) - end - - it 'it\'s tag values are \'value1\' and \'value2\'' do - expect(@sql_database.tags['key1']).to eq(@tags[:key1]) - expect(@sql_database.tags['key2']).to eq(@tags[:key2]) - end - end -end