File: network_interfaces_spec.rb

package info (click to toggle)
ruby-azure-sdk 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 22,400 kB
  • ctags: 12,388
  • sloc: ruby: 168,299; sh: 6; makefile: 2
file content (90 lines) | stat: -rw-r--r-- 3,452 bytes parent folder | download
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
# 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
include Azure::ARM::Network

describe 'Network Interfaces' do
  before(:each) do
    @resource_helper = ResourceHelper.new()
    @client = @resource_helper.network_client.network_interfaces
    @resource_group = @resource_helper.create_resource_group
    @location = 'westus'
    @virtual_network = @resource_helper.create_virtual_network(@resource_group.name)
    @subnet = @resource_helper.create_subnet(@virtual_network, @resource_group, @resource_helper.network_client.subnets)
  end

  after(:each) do
    @resource_helper.delete_resource_group(@resource_group.name)
  end

  it 'should create network interface' do
    params = build_network_interface_param
    result = @client.create_or_update_async(@resource_group.name, params.name, params).value!
    expect(result.response.status).to eq(201)
    expect(result.body).not_to be_nil
    expect(result.body.name).to eq(params.name)
  end

  it 'should get network interface' do
    network_interface = create_network_interface
    result = @client.get_async(@resource_group.name, network_interface.name).value!
    expect(result.response.status).to eq(200)
    expect(result.body).not_to be_nil
    expect(result.body.name).to eq(network_interface.name)
  end

  it 'should delete network interface' do
    network_interface = create_network_interface
    result = @client.delete_async(@resource_group.name, network_interface.name).value!
    expect(result.response.status).to eq(200)
  end

  it 'should list all the network interfaces in a subscription' do
    result = @client.list_all_async.value!
    expect(result.response.status).to eq(200)
    expect(result.body).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_all_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 list all the network interfaces in a resource group' do
    result = @client.list_async(@resource_group.name).value!
    expect(result.response.status).to eq(200)
    expect(result.body).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

  def create_network_interface
    params = build_network_interface_param
    @client.create_or_update(@resource_group.name, params.name, params)
  end

  def build_network_interface_param
    params = NetworkInterface.new
    params.location = @location
    network_interface_name = 'nic8474'
    ip_config_name = 'ip_name_36282'
    params.name = network_interface_name
    ip_configuration = NetworkInterfaceIPConfiguration.new
    params.ip_configurations = [ip_configuration]
    ip_configuration.name = ip_config_name
    ip_configuration.private_ipallocation_method = 'Dynamic'
    ip_configuration.public_ipaddress = @resource_helper.create_public_ip_address(@location, @resource_group)
    ip_configuration.subnet = @subnet
    params
  end
end