Skip to content

Commit 8ce3fc9

Browse files
committed
Add method all to images collection
1 parent 8ff81af commit 8ce3fc9

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/fog/azurerm/docs/compute.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ fog_compute_service.images.create(
526526
)
527527
```
528528

529+
## List Images
530+
531+
```ruby
532+
images = fog_compute_service..images(resource_group: '<Resource Group Name>').all
533+
```
534+
529535
## Get Image
530536

531537
Retrieves the given image

lib/fog/azurerm/models/compute/images.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ def create(attributes)
1010
image.save
1111
end
1212

13+
def all(async = false)
14+
requires :resource_group
15+
images = service.list_images(resource_group, async).map do |image|
16+
Fog::Compute::AzureRM::Image.parse(image)
17+
end
18+
load(images)
19+
end
20+
1321
def get(resource_group_name, image_name)
1422
response = service.get_image(resource_group_name, image_name)
1523
image = Fog::Compute::AzureRM::Image.new(service: service)

test/models/compute/test_images.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,23 @@ def test_collection_attributes
1313
end
1414

1515
def test_collection_methods
16-
methods = %i(get create)
16+
methods = %i(all get create)
1717
methods.each do |method|
1818
assert_respond_to @images, method
1919
end
2020
end
2121

22+
def test_all_method_response
23+
@service.stub :list_images, [@image] do
24+
images_list = @images.all
25+
assert_instance_of Fog::Compute::AzureRM::Images, images_list
26+
assert images_list.size >= 1
27+
images_list.each do |image|
28+
assert_instance_of Fog::Compute::AzureRM::Image, image
29+
end
30+
end
31+
end
32+
2233
def test_get_method_response
2334
@service.stub :get_image, @image do
2435
assert_instance_of Fog::Compute::AzureRM::Image, @images.get('fog-test-rg', 'fog-test-image')

0 commit comments

Comments
 (0)