<commit_before>require File.join(File.dirname(__FILE__), "..", "helpers.rb")

require "sensu/client/process"

describe "Sensu::Client::HTTPSocket" do
  include Helpers

  before do
    @client = Sensu::Client::Process.new(options)
  end

  it "can provide basic version and transport information" do
    async_wrapper do
      @client.setup_transport do
        @client.setup_http_socket
        timer(1) do
          http_request(3031, "/info") do |http, body|
            expect(http.response_header.status).to eq(200)
            expect(body[:sensu][:version]).to eq(Sensu::VERSION)
            expect(body[:transport][:connected]).to be(true)
            expect(body[:transport][:keepalives][:messages]).to be_kind_of(Integer)
            expect(body[:transport][:keepalives][:consumers]).to be_kind_of(Integer)
            expect(body[:transport][:results][:messages]).to be_kind_of(Integer)
            expect(body[:transport][:results][:consumers]).to be_kind_of(Integer)
            async_done
          end
        end
      end
    end
  end

  it "can accept external check result input" do
    async_wrapper do
      @client.setup_transport do
        @client.setup_http_socket
        result_queue do |payload|
          result = Sensu::JSON.load(payload)
          expect(result[:client]).to eq("i-424242")
          expect(result[:check][:name]).to eq("http")
          async_done
        end
        timer(1) do
          options = {:body => {:name => "http", :output => "http", :status => 1}}
          http_request(3031, "/results", :post, options)do |http, body|
            expect(http.response_header.status).to eq(202)
            expect(body).to eq({:response => "ok"})
          end
        end
      end
    end
  end

  it "can accept multiple external check results input" do
    async_wrapper do
      @client.setup_transport do
        @client.setup_http_socket
        result_queue do |payload|
          result = Sensu::JSON.load(payload)
          expect(result[:client]).to eq("i-424242")
          expect(result[:check][:name]).to eq("http")
          expect(result[:check][:name]).to eq("http2")
          expect(result[:check][:name]).to eq("http3")
          end
          async_done
        end
        timer(1) do
          options = {:body => [{:name => "http", :output => "http", :status => 1},
                               {:name => "http2", :output => "http2", :status => 0},
                               {:name => "http3", :output => "http3", :status => 2}]}
          http_request(3031, "/results", :post, options)do |http, body|
            len = options[:body].length-1
            expect(http.response_header.status).to eq(202)
            expect(body).to eq({:response => "ok"})
          end<commit_msg>Fix unit test<commit_after>require File.join(File.dirname(__FILE__), "..", "helpers.rb")

require "sensu/client/process"

describe "Sensu::Client::HTTPSocket" do
  include Helpers

  before do
    @client = Sensu::Client::Process.new(options)
  end

  it "can provide basic version and transport information" do
    async_wrapper do
      @client.setup_transport do
        @client.setup_http_socket
        timer(1) do
          http_request(3031, "/info") do |http, body|
            expect(http.response_header.status).to eq(200)
            expect(body[:sensu][:version]).to eq(Sensu::VERSION)
            expect(body[:transport][:connected]).to be(true)
            expect(body[:transport][:keepalives][:messages]).to be_kind_of(Integer)
            expect(body[:transport][:keepalives][:consumers]).to be_kind_of(Integer)
            expect(body[:transport][:results][:messages]).to be_kind_of(Integer)
            expect(body[:transport][:results][:consumers]).to be_kind_of(Integer)
            async_done
          end
        end
      end
    end
  end

  it "can accept external check result input" do
    async_wrapper do
      @client.setup_transport do
        @client.setup_http_socket
        result_queue do |payload|
          result = Sensu::JSON.load(payload)
          expect(result[:client]).to eq("i-424242")
          expect(result[:check][:name]).to eq("http")
          async_done
        end
        timer(1) do
          options = {:body => {:name => "http", :output => "http", :status => 1}}
          http_request(3031, "/results", :post, options)do |http, body|
            expect(http.response_header.status).to eq(202)
            expect(body).to eq({:response => "ok"})
          end
        end
      end
    end
  end

  it "can accept multiple external check results input" do
    async_wrapper do
      @client.setup_transport do
        @client.setup_http_socket
        result_queue do |payload|
          result = Sensu::JSON.load(payload)
          expect(result[:client]).to eq("i-424242")
          expect(result[:check][:name]).to eq("http")
          async_done
        end
        timer(1) do
          options = {:body => [{:name => "http", :output => "http", :status => 1},
                               {:name => "http", :output => "http2", :status => 0},
                               {:name => "http", :output => "http3", :status => 2}]}
          http_request(3031, "/results", :post, options)do |http, body|
            len = options[:body].length-1
            expect(http.response_header.status).to eq(202)
            expect(body).to eq({:response => "ok"})
          end
{'fraction_non_alphanumeric': 0.1432813659985152, 'fraction_numerical': 0.01670378619153675, 'mean_word_length': 2.355541718555417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '1055881', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1573, 'n_words': 340}