-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7dc131
commit 8ff81af
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Fog | ||
module Compute | ||
class AzureRM | ||
# Real class for Compute Request | ||
class Real | ||
def list_images(resource_group_name, async = false) | ||
msg = 'Listing all Images' | ||
Fog::Logger.debug msg | ||
begin | ||
if async | ||
response = @compute_mgmt_client.images.list_by_resource_group_async(resource_group_name) | ||
else | ||
images = @compute_mgmt_client.images.list_by_resource_group(resource_group_name) | ||
end | ||
rescue MsRestAzure::AzureOperationError => e | ||
raise_azure_exception(e, msg) | ||
end | ||
if async | ||
response | ||
else | ||
Fog::Logger.debug 'Image listed successfully.' | ||
images | ||
end | ||
end | ||
end | ||
|
||
# Mock class for Compute Request | ||
class Mock | ||
def list_images(*) | ||
images = '[{ | ||
"id": "/subscriptions/########-####-####-####-############/resourceGroups/TestRG/providers/Microsoft.Compute/images/TestImage", | ||
"name": "TestImage", | ||
"resource_group": "TestRG", | ||
"location": "West US", | ||
"storage_profile": { | ||
"os_disk": { | ||
"os_type": "Linux", | ||
"os_state": "Generalized", | ||
"blob_uri": "https://myblob.blob.core.windows.net/images/testimage.vhd", | ||
"caching": "ReadWrite", | ||
"disk_size_gb": "5" | ||
}, | ||
"data_disks": [] | ||
}, | ||
"provisioning_state": "Succeeded" | ||
}]' | ||
image_mapper = Azure::ARM::Compute::Models::ImageListResult.mapper | ||
compute_client.deserialize(image_mapper, images, 'result.body') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require File.expand_path '../../test_helper', __dir__ | ||
# Test class for List Images | ||
class TestListVirtualMachineSizes < Minitest::Test | ||
def setup | ||
@service = Fog::Compute::AzureRM.new(credentials) | ||
@client = @service.instance_variable_get(:@compute_mgmt_client) | ||
@images = @client.images | ||
end | ||
|
||
def test_list_images_success | ||
mocked_response = ApiStub::Requests::Compute::Image.list_response(@client) | ||
@images.stub :list_by_resource_group, mocked_response do | ||
assert_equal mocked_response, @service.list_images('fog-test-rg') | ||
end | ||
async_response = Concurrent::Promise.execute { 10 } | ||
@images.stub :list_by_resource_group_async, async_response do | ||
assert_equal async_response, @service.list_images('fog-test-rg', true) | ||
end | ||
end | ||
|
||
def test_list_images_failure | ||
response = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) } | ||
@images.stub :list_by_resource_group, response do | ||
assert_raises(MsRestAzure::AzureOperationError) { @service.list_images('fog-test-rg') } | ||
end | ||
end | ||
end |