<commit_before>require 'spec_helper'

module Vcloud
  module EdgeGateway
    module ConfigurationGenerator
      describe LoadBalancerService do

        before(:each) do
          @edge_gw_name = 'EdgeGateway1'
          @edge_gw_id = '1111111-7b54-43dd-9eb1-631dd337e5a7'
          edge_gateway = double(:edge_gateway,
            :vcloud_gateway_interface_by_id => {
              Network: {
                :name => 'ExternalNetwork',
                :href => 'https://example.com/api/admin/network/12345678-1234-1234-1234-123456789012'
              }
            }
          )
          expect(Vcloud::Core::EdgeGateway).
            to receive(:get_by_name).
            with(@edge_gw_name).
            and_return(edge_gateway)
        end

        context "top level LoadBalancer configuration defaults" do

          before(:each) do
            input = { } # minimum configuration
            @output = LoadBalancerService.new(@edge_gw_name).generate_fog_config(input)
          end

          it 'should default to LoadBalancerService enabled' do
            expect(@output[:IsEnabled]).to eq('true')
          end

          it 'should match our expected defaults' do
            expect(@output).to eq({
              :IsEnabled=>"true", :Pool=>[], :VirtualServer=>[]
            })
          end

        end

        test_cases = [
          {
            title: 'should expand out input config into Fog expected input',
            input: {
              enabled: 'true', #opt
              pools: [
                {
                  name: 'web-app',
                  description: 'web-app',#opt
                  service: {
                    http: {
                      enabled: 'true', #opt, default true
                      algorithm: 'ROUND_ROBIN', #opt default RRB
                      port: 80, #req
                      protocol: 'HTTP', #req
                      health_check: {<commit_msg>Add tests for default output for VirtualServer<commit_after>require 'spec_helper'

module Vcloud
  module EdgeGateway
    module ConfigurationGenerator
      describe LoadBalancerService do

        before(:each) do
          @edge_gw_name = 'EdgeGateway1'
          @edge_gw_id = '1111111-7b54-43dd-9eb1-631dd337e5a7'
          edge_gateway = double(:edge_gateway,
            :vcloud_gateway_interface_by_id => {
              Network: {
                :name => 'ExternalNetwork',
                :href => 'https://example.com/api/admin/network/12345678-1234-1234-1234-123456789012'
              }
            }
          )
          expect(Vcloud::Core::EdgeGateway).
            to receive(:get_by_name).
            with(@edge_gw_name).
            and_return(edge_gateway)
        end

        context "top level LoadBalancer configuration defaults" do

          before(:each) do
            input = { } # minimum configuration
            @output = LoadBalancerService.new(@edge_gw_name).generate_fog_config(input)
          end

          it 'should default to LoadBalancerService enabled' do
            expect(@output[:IsEnabled]).to eq('true')
          end

          it 'should match our expected defaults' do
            expect(@output).to eq({
              :IsEnabled=>"true", :Pool=>[], :VirtualServer=>[]
            })
          end

        end

        context "VirtualServer rule defaults" do

          before(:each) do
            input = { virtual_servers: [{
              name: "virtual-server-1",
              ip_address: '172.16.58.3',
              network: "12345678-1234-1234-1234-123456789aa",
              pool: "pool-1",
            }]} # minimum configuration for a virtual_server
            output = LoadBalancerService.new(@edge_gw_name).generate_fog_config(input)
            @rule = output[:VirtualServer].first
          end

          it 'should default to rule being enabled' do
            expect(@rule[:IsEnabled]).to eq('true')
          end

          it 'should default to description being empty' do
            expect(@rule[:Description]).to eq('')
          end

          it 'should match our expected complete entry' do
            expect(@rule).to eq({
              :IsEnabled=>"true",
              :Name=>"virtual-server-1",
              :Description=>"",
              :Interface=>{
                :name=>"ExternalNetwork",
                :href=>"https://example.com/api/admin/network/12345678-1234-1234-1234-123456789012",
                :type=>"application/vnd.vmware.vcloud.orgVdcNetwork+xml"
              },
              :IpAddress=>"172.16.58.3",
              :ServiceProfile=>[
                {
                  :IsEnabled=>"false",
                  :Protocol=>"HTTP",
                  :Port=>"",
                  :Persistence=>{:Method=>""}
                },
                {
                  :IsEnabled=>"false",
                  :Protocol=>"HTTPS",
                  :Port=>"",
                  :Persistence=>{:Method=>""}
                },
                {
                  :IsEnabled=>"false",
                  :Protocol=>"TCP",
                  :Port=>"",
                  :Persistence=>{:Method=>""}
                }
              ],
              :Logging=>"false",
              :Pool=>"pool-1"
            })
          end

        end


        test_cases = [
          {
            title: 'should expand out input config into Fog expected input',
            input: {
              enabled: 'true', #opt
              pools: [
                {
                  name: 'web-app',
                  description: 'web-app',#opt
                  service: {
                    http: {
                      enabled: 'true', #opt, default true
                      algorithm: 'ROUND_ROBIN', #opt default RRB
                      port: 80, #req
                      protocol: 'HTTP', #req
                      health_check: {
{'fraction_non_alphanumeric': 0.10874018436326391, 'fraction_numerical': 0.03328781153977467, 'mean_word_length': 1.3749493311714633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 2, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '378925', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1496, 'n_words': 308}