<commit_before>Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_tests', ['rackspace']) do

  pending if Fog.mocking?

  given_a_load_balancer_service do
    tests('success') do

      @lb_id = nil
      @lb_name = 'fog' + Time.now.to_i.to_s

      tests("#create_load_balancer(#{@lb_name}, 'HTTP', 80,...)").formats(LOAD_BALANCER_FORMAT) do
        data = @service.create_load_balancer(@lb_name, 'HTTP', 80, [{ :type => 'PUBLIC'}], [{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}]).body
        @lb_id = data['loadBalancer']['id']
        data
      end

      tests("#create_load_balancer(#{@lb_name}, 'HTTP', 80,...with algorithm)").formats(LOAD_BALANCER_FORMAT) do
        data = @service.create_load_balancer(@lb_name, 'HTTP', 80, [{ :type => 'PUBLIC'}],
                                             [{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}],
                                             { :algorithm => 'LEAST_CONNECTIONS', :timeout => 30 }).body
        @lb_id = data['loadBalancer']['id']
        returns('LEAST_CONNECTIONS') { data['loadBalancer']['algorithm'] }
        returns(30) { data['loadBalancer']['timeout'] }
        data
      end

      tests("#update_load_balancer(#{@lb_id}) while immutable").raises(Fog::Rackspace::LoadBalancers::ServiceError) do
        @service.update_load_balancer(@lb_id, { :port => 80 }).body
      end

      tests("#get_load_balancer(#{@lb_id})").formats(LOAD_BALANCER_FORMAT) do
        @service.get_load_balancer(@lb_id).body
      end

      tests("#list_load_balancers()").formats(LOAD_BALANCERS_FORMAT) do
        @service.list_load_balancers.body
      end

      until @service.get_load_balancer(@lb_id).body["loadBalancer"]["status"] == STATUS_ACTIVE
        sleep 10
      end

      tests("#list_load_balancers({:node_address => '1.1.1.1'})").formats(LOAD_BALANCERS_FORMAT) do
        @service.list_load_balancers({:node_address => '1.1.1.1'}).body
      end

      tests("#update_load_balancer(#{@lb_id}, { :port => 80 })").succeeds do
        @service.update_load_balancer(@lb_id, { :port => 80 }).body
      end

      until @service.get_load_balancer(@lb_id).body["loadBalancer"]["status"] == STATUS_ACTIVE
        sleep 10
      end

      tests("#delete_load_balancer(#{@ld_id})").succeeds do
        @service.delete_load_balancer(@lb_id).body
      end
    end

    tests('failure') do
      tests('#create_load_balancer(invalid name)').raises(Fog::Rackspace::LoadBalancers::BadRequest) do
        @service.create_load_balancer('', 'HTTP', 80, [{ :type => 'PUBLIC'}], [{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}])
      end

      tests('#get_load_balancer(0)').raises(Fog::Rackspace::LoadBalancers::NotFound) do
        @service.get_load_balancer(0)
      end
      tests('#delete_load_balancer(0)').raises(Fog::Rackspace::LoadBalancers::BadRequest) do
        @service.delete_load_balancer(0)
      end
      tests('#update_load_balancer(0)').raises(Fog::Rackspace::LoadBalancers::NotFound) do
        @service.update_load_balancer(0, { :name => 'newname' })
      end
    end
  end
end<commit_msg>Test different means of creating load balancers.<commit_after>Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_tests', ['rackspace']) do

  pending if Fog.mocking?

  given_a_load_balancer_service do
    tests('success') do

      @lb_id = nil
      @lb_ids = []
      @lb_name = 'fog' + Time.now.to_i.to_s

      tests("#create_load_balancer(#{@lb_name}, 'HTTP')").formats(LOAD_BALANCER_FORMAT) do
        data = @service.create_load_balancer(@lb_name, 'HTTP').body
        @lb_id = data['loadBalancer']['id']
        @lb_ids << @lb_id
        data
      end

      tests("#create_load_balancer(#{@lb_name}, 'HTTP', 80,...)").formats(LOAD_BALANCER_FORMAT) do
        data = @service.create_load_balancer(@lb_name, 'HTTP', 80, [{ :type => 'PUBLIC'}], [{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}]).body
        @lb_ids << data['loadBalancer']['id']
        data
      end

      tests("#create_load_balancer(#{@lb_name}, 'HTTP', 80,...with algorithm)").formats(LOAD_BALANCER_FORMAT) do
        data = @service.create_load_balancer(@lb_name, 'HTTP', 80, [{ :type => 'PUBLIC'}],
                                             [{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}],
                                             { :algorithm => 'LEAST_CONNECTIONS', :timeout => 30 }).body
        @lb_ids << data['loadBalancer']['id']
        returns('LEAST_CONNECTIONS') { data['loadBalancer']['algorithm'] }
        returns(30) { data['loadBalancer']['timeout'] }
        data
      end

      tests("#update_load_balancer(#{@lb_id}) while immutable").raises(Fog::Rackspace::LoadBalancers::ServiceError) do
        @service.update_load_balancer(@lb_id, { :port => 80 }).body
      end

      tests("#get_load_balancer(#{@lb_id})").formats(LOAD_BALANCER_FORMAT) do
        @service.get_load_balancer(@lb_id).body
      end

      tests("#list_load_balancers()").formats(LOAD_BALANCERS_FORMAT) do
        @service.list_load_balancers.body
      end

      until @service.get_load_balancer(@lb_id).body["loadBalancer"]["status"] == STATUS_ACTIVE
        sleep 10
      end

      tests("#list_load_balancers({:node_address => '1.1.1.1'})").formats(LOAD_BALANCERS_FORMAT) do
        @service.list_load_balancers({:node_address => '1.1.1.1'}).body
      end

      tests("#update_load_balancer(#{@lb_id}, { :port => 80 })").succeeds do
        @service.update_load_balancer(@lb_id, { :port => 80 }).body
      end

      until @service.get_load_balancer(@lb_id).body["loadBalancer"]["status"] == STATUS_ACTIVE
        sleep 10
      end

      @lb_ids.each do |id|
        tests("#delete_load_balancer(#{id})").succeeds do
          @service.delete_load_balancer(id).body
        end
      end
    end

    tests('failure') do
      tests('#create_load_balancer(invalid name)').raises(Fog::Rackspace::LoadBalancers::BadRequest) do
        @service.create_load_balancer('', 'HTTP', 80, [{ :type => 'PUBLIC'}], [{ :address => '1.1.1.1', :port => 80, :condition => 'ENABLED'}])
      end

      tests('#get_load_balancer(0)').raises(Fog::Rackspace::LoadBalancers::NotFound) do
        @service.get_load_balancer(0)
      end
      tests('#delete_load_balancer(0)').raises(Fog::Rackspace::LoadBalancers::BadRequest) do
        @service.delete_load_balancer(0)
      end
      tests('#update_load_balancer(0)').raises(Fog::Rackspace::LoadBalancers::NotFound) do
        @service.update_load_balancer(0, { :name => 'newname' })
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.169337768370124, 'fraction_numerical': 0.016933776837012398, 'mean_word_length': 3.264990328820116, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '531368', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2212, 'n_words': 322}