<commit_before>require File.dirname(__FILE__) + '/helpers.rb'
require 'sensu/socket'

describe Sensu::Socket do
  include Helpers

  before(:each) do
    MultiJson.load_options = {:symbolize_keys => true}
  end

  subject { described_class.new(nil) }

  let(:logger) { double('Logger') }
  let(:transport) { double('Transport') }

  let(:settings) do
    {
      :client => client_template
    }
  end

  before(:each) do
    subject.logger = logger
    subject.settings = settings
    subject.transport = transport
  end

  describe '#receive_data' do
    it 'allows incremental receipt of data for tcp connections' do
      check_result = result_template
      expect(logger).to receive(:info).with('publishing check result', {:payload => check_result})<commit_msg>[client_socket] socket spec, test process_check_result()<commit_after>require File.dirname(__FILE__) + '/helpers.rb'
require 'sensu/socket'

describe Sensu::Socket do
  include Helpers

  before(:each) do
    MultiJson.load_options = {:symbolize_keys => true}
  end

  subject { described_class.new(nil) }

  let(:logger) { double('Logger') }
  let(:transport) { double('Transport') }

  let(:settings) do
    {
      :client => client_template
    }
  end

  before(:each) do
    subject.logger = logger
    subject.settings = settings
    subject.transport = transport
  end

  describe '#process_check_result' do
    it 'rejects invalid check results' do
      invalid_check = result_template[:check].merge(:status => "2")
      expect { subject.process_check_result(invalid_check) }.to \
        raise_error(described_class::DataError)
    end

    it 'publishes valid check results' do
      check = result_template[:check]
      expect(subject).to receive(:validate_check_result).with(check)
      expect(subject).to receive(:publish_check_result).with(check)
      subject.protocol = :udp
      subject.process_check_result(check)
    end
  end

  describe '#receive_data' do
    it 'allows incremental receipt of data for tcp connections' do
      check_result = result_template
      expect(logger).to receive(:info).with('publishing check result', {:payload => check_result})
{'fraction_non_alphanumeric': 0.11198884758364312, 'fraction_numerical': 0.00046468401486988845, 'mean_word_length': 3.838202247191011, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '7419061', 'n_tokens_mistral': 648, 'n_tokens_neox': 616, 'n_words': 151}