require 'spec_helper'

module Vcloud
  module Core
    describe EdgeGateway do

      required_env = {
        'VCLOUD_EDGE_GATEWAY' => 'to name of VSE',
      }

      error = false
      required_env.each do |var,message|
        unless ENV[var]
          puts "Must set #{var} #{message}" unless ENV[var]
          error = true
        end
      end
      Kernel.exit(2) if error

      it "configures a firewall service" do
        configuration = {
            :FirewallService =>
                {
                    :IsEnabled => "true",
                    :DefaultAction => "allow",
                    :LogDefaultAction => "false",
                    :FirewallRule =>
                        [
                            {
                                :Id => "999",
                                :IsEnabled => "false",
                                :MatchOnTranslate => "false",
                                :Description => "generated from edge_gateway_tests",
                                :Policy => "drop",
                                :Protocols => {:Tcp => "true"},
                                :Port => "3412",
                                :DestinationPortRange => "3412",
                                :DestinationIp => "internal",
                                :SourcePort => "3412",
                                :SourcePortRange => "3412",
                                :SourceIp => "internal",
                                :EnableLogging => "false"
                            }
                        ]
                }
        }
        edge_gateway = EdgeGateway.get_by_name(ENV['VCLOUD_EDGE_GATEWAY'])
        edge_gateway.update_configuration(configuration)

        actual_config = edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
        actual_config[:FirewallService].should == configuration[:FirewallService]
      end
    end
  end
end

require 'spec_helper'

module Vcloud
  module Core
    describe EdgeGateway do

      required_env = {
        'VCLOUD_EDGE_GATEWAY' => 'to name of VSE',
      }

      error = false
      required_env.each do |var,message|
        unless ENV[var]
          puts "Must set #{var} #{message}" unless ENV[var]
          error = true
        end
      end
      Kernel.exit(2) if error

      it "updates the edge gateway" do
        configuration = {
            :FirewallService =>
                {
                    :IsEnabled        => "true",
                    :FirewallRule     => [],
                    :DefaultAction    => "drop",
                    :LogDefaultAction => "false",
                },
            :LoadBalancerService =>
                {
                    :IsEnabled      => "true",
                    :Pool           => [],
                    :VirtualServer  => [],
                },
            :NatService =>
                {
                    :IsEnabled  => "true",
                    :NatRule    => [],
                },
        }

        edge_gateway = EdgeGateway.get_by_name(ENV['VCLOUD_EDGE_GATEWAY'])
        edge_gateway.update_configuration(configuration)

        actual_config = edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
        actual_config[:FirewallService].should == configuration[:FirewallService]
        actual_config[:LoadBalancerService].should == configuration[:LoadBalancerService]
        actual_config[:NatService].should == configuration[:NatService]
      end
    end
  end
end

Simplify edge gateway integration tests
Simplify edge gateway integration tests

Simplify the edge gateway integration tests such that we only test the
functionality implemented in vCloud Core.

After discussion with @annashipman and @dcarley, we decided that the
existing tests were doing too much by duplicating some of the tests in
vCloud Edge Gateway. Instead, we should only test the functionality
contained in this gem.

Replace the existing test with one test that asserts whether the
EdgeGateway#update_configuration method successfully updates the edge
gateway.

Note that we perform three separate assertions on the configuration
returned by the edge gateway on each of the `:FirewallService`,
`:NatService` and `:LoadBalancerService` hash members. This is necessary
because the edge gateway returns additional information such as
`:GatewayIpsecVpnService` and `:GatewayDhcpService` which we're not
concerned with.
