<commit_before>require "minitest/autorun"
require "mocha/setup"
require_relative "../lib/mini_graphite"

class MiniGraphiteTest < MiniTest::Unit::TestCase

	def test_datapoint
		Dalia::MiniGraphite.config({ :graphite_host => "graphite.host.com", :graphite_port => 2003 })

		socket_mock = mock()
		TCPSocket.expects(:new).with("graphite.host.com", 2003).returns(socket_mock)
		socket_mock.expects(:print).with("test.age 31 1357117860\n")
		socket_mock.expects(:close)

		Dalia::MiniGraphite.datapoint("test.age", 31, Time.new(2013,1,2,10,11))
	end

	def test_counter
		Dalia::MiniGraphite.config({ :statsd_host => "statsd.host.com", :statsd_port => 8125 })

		socket_mock = mock()
		UDPSocket.expects(:new).returns(socket_mock)
		socket_mock.expects(:send).with("height:231|c", 0, "graphite.host.com", 8125 )

		Dalia::MiniGraphite.counter("height", 231)
	end

	def test_on_config_should_debug
		Dalia::MiniGraphite::Logger.any_instance.expects(:debug).at_least_once
		Dalia::MiniGraphite.config()
	end

	def test_on_counter_should_debug
		Dalia::MiniGraphite.expects(:send_udp)
		Dalia::MiniGraphite.config()

		Dalia::MiniGraphite::Logger.any_instance.expects(:debug).with("Sending counter: 'test.age:31|c'")
		Dalia::MiniGraphite.counter("test.age", 31)
	end

	def test_on_datapoint_should_debug
		Dalia::MiniGraphite.expects(:send_tcp)
		Dalia::MiniGraphite.config()

		Dalia::MiniGraphite::Logger.any_instance.expects(:debug).with("Sending datapoint: 'test.age 31 1357117860'")
		Dalia::MiniGraphite.datapoint("test.age", 31, Time.new(2013,1,2,10,11))
	end

	def test_on_datapoint_not_send_tcp_if_mock_mode
		Dalia::MiniGraphite.config(:mock_mode => true)
		TCPSocket.expects(:new).never<commit_msg>Fixing tests<commit_after>require "minitest/autorun"
require "mocha/setup"
require_relative "../lib/mini_graphite"

class MiniGraphiteTest < MiniTest::Unit::TestCase

	def test_datapoint
		Dalia::MiniGraphite.config({ :graphite_host => "graphite.host.com", :graphite_port => 2003 })

		socket_mock = mock()
		TCPSocket.expects(:new).with("graphite.host.com", 2003).returns(socket_mock)
		socket_mock.expects(:print).with("test.age 31 1357117860\n")
		socket_mock.expects(:close)

		Dalia::MiniGraphite.datapoint("test.age", 31, Time.new(2013,1,2,10,11))
	end

	def test_counter
		Dalia::MiniGraphite.config({ :statsd_host => "statsd.host.com", :statsd_port => 8125 })

		socket_mock = mock()
		UDPSocket.expects(:new).returns(socket_mock)
		socket_mock.expects(:send).with("height:231|c", 0, "statsd.host.com", 8125 )

		Dalia::MiniGraphite.counter("height", 231)
	end

	def test_on_config_should_debug
		Dalia::MiniGraphite::Logger.any_instance.expects(:debug).at_least_once
		Dalia::MiniGraphite.config()
	end

	def test_on_counter_should_debug
		Dalia::MiniGraphite.expects(:send_udp)
		Dalia::MiniGraphite.config()

		Dalia::MiniGraphite::Logger.any_instance.expects(:debug).with("Sending counter: 'test.age:31|c'")
		Dalia::MiniGraphite.counter("test.age", 31)
	end

	def test_on_datapoint_should_debug
		Dalia::MiniGraphite.expects(:send_tcp)
		Dalia::MiniGraphite.config()

		Dalia::MiniGraphite::Logger.any_instance.expects(:debug).with("Sending datapoint: 'test.age 31 1357117860'")
		Dalia::MiniGraphite.datapoint("test.age", 31, Time.new(2013,1,2,10,11))
	end

	def test_on_datapoint_not_send_tcp_if_mock_mode
		Dalia::MiniGraphite.config(:mock_mode => true)
		TCPSocket.expects(:new).never
{'fraction_non_alphanumeric': 0.15036710719530103, 'fraction_numerical': 0.04405286343612335, 'mean_word_length': 6.920930232558139, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1847781', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1290, 'n_words': 156}