Sha256: 6c198c7f196ae066b7fc8e02138c37b5f630a78f69f599ad4e68b4d2c6d63f4a

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require File.expand_path '../../test_helper', __dir__

# Test class for Create Network Security Group
class TestCreateNetworkSecurityGroup < Minitest::Test
  def setup
    @service = Fog::Network::AzureRM.new(credentials)
    client = @service.instance_variable_get(:@network_client)
    @network_security_groups = client.network_security_groups
    @promise = Concurrent::Promise.execute do
    end
  end

  def test_create_network_security_group_success
    mocked_response = ApiStub::Requests::Network::NetworkSecurityGroup.create_network_security_group_response
    expected_response = Azure::ARM::Network::Models::NetworkSecurityGroup.serialize_object(mocked_response.body)
    security_rule = {
      name: 'testRule',
      protocol: 'tcp',
      source_port_range: '22',
      destination_port_range: '22',
      source_address_prefix: '0.0.0.0/0',
      destination_address_prefix: '0.0.0.0/0',
      access: 'Allow',
      priority: '100',
      direction: 'Inbound',
      description: 'This is a test rule'
    }
    @promise.stub :value!, mocked_response do
      @network_security_groups.stub :begin_create_or_update, @promise do
        assert_equal @service.create_or_update_network_security_group('fog-test-rg', 'fog-test-nsg', 'West US', [security_rule]), expected_response
      end
    end
  end

  def test_create_network_security_group_failure
    response = -> { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
    @promise.stub :value!, response do
      @network_security_groups.stub :begin_create_or_update, @promise do
        assert_raises RuntimeError do
          @service.create_or_update_network_security_group('fog-test-rg', 'fog-test-nsg', 'West US', [])
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-azure-rm-0.0.4 test/requests/network/test_create_network_security_group.rb