1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
require_relative 'spec_helper'
include MsRestAzure
include Azure::ARM::Resources
describe 'Resources' do
before(:each) do
@resource_helper = ResourceHelper.new()
@client = @resource_helper.resource_client.resources
@resource_group = @resource_helper.create_resource_group
@resource_type = 'sites'
@resource_provider = 'Microsoft.Web'
@resource_api_version = '2015-07-01'
@resource_identity = 'Microsoft.Web/sites'
@resource_name = 'testresource'
end
after(:each) do
@resource_helper.delete_resource_group(@resource_group.name)
end
it 'should create resource' do
params = build_resource_params(@resource_name)
result = @client.create_or_update_async(
@resource_group.name,
@resource_provider,
'',
@resource_type,
@resource_name,
@resource_api_version,
params
).value!
expect(result.response.status).to eq(200)
expect(result.body).not_to be_nil
expect(result.body.location).to eq(params.location)
expect(result.body.type).to eq(@resource_identity)
end
it 'should get resource' do
resource = create_resource
result = @client.get_async(
@resource_group.name,
@resource_provider,
'',
@resource_type,
resource.name,
@resource_api_version
).value!
expect(result.body).not_to be_nil
expect(result.body.name).to eq(resource.name)
expect(result.body.type).to eq(@resource_identity)
end
it 'should raise an error when attempting to get resource without any parameters' do
expect{@client.get(nil, nil, nil, nil, nil, nil)}.to raise_error(ArgumentError)
end
it 'should check existence of resource' do
pending('Skip for now since this method isn\'t supported by server - HTTP 405 is returned')
resource = create_resource
result = @client.check_existence(
@resource_group.name,
@resource_provider,
'',
@resource_type,
resource.name,
@resource_api_version
).value!
expect(result.body).to be_truthy
end
it 'should raise an error when attempting invoke get, create_or_update, check_existence or delete without api version' do
params = build_resource_params(@resource_name)
expect{@client.create_or_update(
@resource_group.name,
@resource_provider,
'',
@resource_type,
@resource_name,
nil,
params)}.to raise_error(ArgumentError)
expect{@client.get(
@resource_group.name,
@resource_provider,
'',
@resource_type,
@resource_name,
nil
)}.to raise_error(ArgumentError)
expect{@client.check_existence(
@resource_group.name,
@resource_provider,
'',
@resource_type,
@resource_name,
nil
)}.to raise_error(ArgumentError)
expect{@client.delete(
@resource_group.name,
@resource_provider,
'',
@resource_type,
@resource_name,
nil
)}.to raise_error(ArgumentError)
end
it 'should list resources' do
result = @client.list_async.value!
expect(result.body.value).not_to be_nil
expect(result.body.value).to be_a(Array)
while !result.body.next_link.nil? && !result.body.next_link.empty? do
result = @client.list_next(result.body.next_link).value!
expect(result.body.value).not_to be_nil
expect(result.body.value).to be_a(Array)
end
end
it 'should filter resources and work with top parameter' do
filter = "tagName eq 'tagName' and tagValue eq 'tagValue'"
result = @client.list_async(filter, 1).value!
expect(result.body.value).not_to be_nil
expect(result.body.value).to be_a(Array)
while !result.body.next_link.nil? && !result.body.next_link.empty?.empty? do
result = @client.list_next(result.body.next_link).value!
expect(result.body.value).not_to be_nil
expect(result.body.value).to be_a(Array)
end
end
it 'should move resources' do
target_resource_group_name = 'RubySDKTest_azure_mgmt_resources1'
params = Azure::ARM::Resources::Models::ResourceGroup.new()
params.location = 'westus'
target_rg = @resource_helper.resource_client.resource_groups.create_or_update_async(target_resource_group_name, params).value!.body
resource = create_resource
params = Models::ResourcesMoveInfo.new
params.target_resource_group = target_rg.id
params.resources = [resource.id]
result = @client.move_resources_async(@resource_group.name, params).value!
expect(result.response.status).to eq(204)
wait_resource_move
@resource_helper.delete_resource_group(target_resource_group_name)
end
it 'should delete resource' do
resource = create_resource
result = @client.delete_async(
@resource_group.name,
@resource_provider,
'',
@resource_type,
resource.name,
@resource_api_version
).value!
expect(result.response.status).to eq(200)
end
def create_resource
@client.create_or_update_async(
@resource_group.name,
@resource_provider,
'',
@resource_type,
@resource_name,
@resource_api_version,
build_resource_params(@resource_name)
).value!.body
end
def build_resource_params(name)
params = Models::GenericResource.new()
params.location = 'WestUS'
params.properties = {
'name' => name,
'siteMode' => 'Limited',
'computeMode' => 'Shared',
'sku' => 'Free',
'workerSize'=> 0
}
params
end
def wait_resource_move
count = 30
while @resource_helper.resource_client.resource_groups.get_async(@resource_group.name).value!.body.properties.provisioning_state == 'MovingResources'
sleep(1)
fail 'Waiting for resources to move took more than 30 requests. This seems broken' if count <= 0
count -= 1
end
end
end
|