Skip to content

Commit

Permalink
Add method all to VirtualMachineSizes
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinLoiseau committed Oct 30, 2018
1 parent 45c77ce commit b7680e6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/fog/azurerm/models/compute/virtual_machine_sizes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ class AzureRM
class VirtualMachineSizes < Fog::Collection
attribute :location
model Fog::Compute::AzureRM::VirtualMachineSize

def all(async = false)
requires :location
virtual_machine_sizes = service.list_virtual_machine_sizes(location, async).map do |virtual_machine_size|
Fog::Compute::AzureRM::VirtualMachineSize.parse(virtual_machine_size)
end
load(virtual_machine_sizes)
end
end
end
end
Expand Down
40 changes: 40 additions & 0 deletions test/api_stub/models/compute/virtual_machine_size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,46 @@ module ApiStub
module Models
module Compute
class VirtualMachineSize
def self.virtual_machine_sizes(sdk_compute_client)
virtual_machine_sizes = {
'value' => [
{
'max_data_disk_count' => 1,
'memory_in_mb' => 768,
'name' => 'Standard_A0',
'number_of_cores' => 1,
'os_disk_size_in_mb' => 1_047_552,
'resource_disk_size_in_mb' => 20_480,
},
{
'max_data_disk_count' => 2,
'memory_in_mb' => 1_792,
'name' => 'Standard_A1',
'number_of_cores' => 1,
'os_disk_size_in_mb'=> 1_047_552,
'resource_disk_size_in_mb' => 71_680,
},
{
'max_data_disk_count' => 4,
'memory_in_mb' => 3_584,
'name' => 'Standard_A2',
'number_of_cores' => 2,
'os_disk_size_in_mb' => 1_047_552,
'resource_disk_size_in_mb' => 138_240
},
{
'max_data_disk_count' => 1,
'memory_in_mb' => 768,
'name' => 'Basic_A0',
'number_of_cores' => 1,
'os_disk_size_in_mb' => 1_047_552,
'resource_disk_size_in_mb' => 20_480
}
]
}
virtual_machine_size_mapper = Azure::ARM::Compute::Models::VirtualMachineSizeListResult.mapper
sdk_compute_client.deserialize(virtual_machine_size_mapper, virtual_machine_sizes, 'result.body').value
end
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions test/models/compute/test_virtual_machine_sizes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@ class TestVirtualMachineSizes < Minitest::Test
def setup
@service = Fog::Compute::AzureRM.new(credentials)
@virtual_machine_sizes = Fog::Compute::AzureRM::VirtualMachineSizes.new(location: 'location', service: @service)
@compute_client = @service.instance_variable_get(:@compute_mgmt_client)
@response = ApiStub::Models::Compute::VirtualMachineSize.virtual_machine_sizes(@compute_client)
end

def test_collection_attributes
assert_respond_to @virtual_machine_sizes, :location
end

def test_collection_methods
methods = %i(all)
methods.each do |method|
assert_respond_to @virtual_machine_sizes, method
end
end

def test_all_method_response
@service.stub :list_virtual_machine_sizes, @response do
sizes = @virtual_machine_sizes.all

assert_instance_of Fog::Compute::AzureRM::VirtualMachineSizes, sizes
assert sizes.size >= 1
sizes.each do |size|
assert_instance_of Fog::Compute::AzureRM::VirtualMachineSize, size
end
end
end
end

0 comments on commit b7680e6

Please sign in to comment.