Sha256: d04fee9cf2791505244cea6b25def9c0f3134a9f719bc7ae099ab51296285108

Contents?: true

Size: 1.93 KB

Versions: 7

Compression:

Stored size: 1.93 KB

Contents

require 'test_helper'
require 'ostruct'
require 'harness/adapters/statsd_adapter'

class StatsdAdapterTest < MiniTest::Unit::TestCase
  def setup
    @adapter = Harness::StatsdAdapter.new

    @gauge = Harness::Gauge.new
    @gauge.id = "fake-gauge"
    @gauge.name = "Fake Gauge"
    @gauge.source = "minitest"
    @gauge.time = Time.now
    @gauge.value = 55

    @counter = Harness::Counter.new
    @counter.id = "fake-counter"
    @counter.name = "Fake Counter"
    @counter.source = "minitest"
    @counter.time = Time.now
    @counter.value = 1337
    @counter.units = :bytes
    Harness.config.namespace = nil
  end

  def test_gauge_is_logged
    mock_backend = MiniTest::Mock.new
    mock_backend.expect :host, 'foo'
    mock_backend.expect :port, 'bar'

    Harness::StatsdAdapter.config.backend = mock_backend
    mock_backend.expect :gauge, true, [String, 55] 

    assert @adapter.log_gauge(@gauge)
    assert mock_backend.verify
  end

  def test_logging_gauge_raises_an_exception_when_not_configured
    mock_backend = MiniTest::Mock.new
    mock_backend.expect :host, nil
    mock_backend.expect :port, nil

    Harness::StatsdAdapter.config.backend = mock_backend
    mock_backend.expect :gauge, true, [String, 55] 

    assert_raises RuntimeError do
      @adapter.log_gauge @gauge
    end
  end

  def test_counter_is_logged
    mock_backend = MiniTest::Mock.new
    mock_backend.expect :host, 'foo'
    mock_backend.expect :port, 'bar'

    Harness::StatsdAdapter.config.backend = mock_backend
    mock_backend.expect :increment, true, [String, 1337]

    assert @adapter.log_counter(@counter)
    assert mock_backend.verify
  end

  def test_logging_counter_raises_an_exception_when_not_configured
    mock_backend = MiniTest::Mock.new
    mock_backend.expect :host, nil
    mock_backend.expect :port, nil

    Harness::StatsdAdapter.config.backend = mock_backend

    assert_raises RuntimeError do
      @adapter.log_counter @counter
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
harness-0.9.1 test/unit/adapters/statsd_adapter_test.rb
harness-0.9.0 test/unit/adapters/statsd_adapter_test.rb
harness-0.8.1 test/unit/adapters/statsd_adapter_test.rb
harness-0.8.0 test/unit/adapters/statsd_adapter_test.rb
harness-0.7.0 test/unit/adapters/statsd_adapter_test.rb
harness-0.6.0 test/unit/adapters/statsd_adapter_test.rb
harness-0.5.0 test/unit/adapters/statsd_adapter_test.rb