Sha256: 53e29d50e4a0cea3d2b60b5ad9defb4e37e6c7a4f4192924bb0a648f08ac9dfe

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'test_helper'

class CaptureSinktest < Minitest::Test
  def test_capture_sink_captures_datagram_instances
    capture_sink = StatsD::Instrument::CaptureSink.new(parent: [])
    capture_sink << 'foo:1|c'

    assert_equal 1, capture_sink.datagrams.length
    assert_kind_of StatsD::Instrument::Datagram, capture_sink.datagrams.first
    assert_equal 'foo:1|c', capture_sink.datagrams.first.source
  end

  def test_capture_sink_sends_datagrams_to_parent
    parent = []
    capture_sink = StatsD::Instrument::CaptureSink.new(parent: parent)
    capture_sink << 'foo:1|c' << 'bar:1|c'

    assert_equal ['foo:1|c', 'bar:1|c'], parent
  end

  def test_nesting_capture_sink_instances
    null_sink = StatsD::Instrument::NullSink.new
    outer_capture_sink = StatsD::Instrument::CaptureSink.new(parent: null_sink)
    inner_capture_sink = StatsD::Instrument::CaptureSink.new(parent: outer_capture_sink)

    outer_capture_sink << 'foo:1|c'
    inner_capture_sink << 'bar:1|c'

    assert_equal ['foo:1|c', 'bar:1|c'], outer_capture_sink.datagrams.map(&:source)
    assert_equal ['bar:1|c'], inner_capture_sink.datagrams.map(&:source)
  end

  def test_using_a_different_datagram_class
    sink = StatsD::Instrument::CaptureSink.new(parent: [], datagram_class: String)
    sink << 'foo:1|c'

    assert sink.datagrams.all? { |datagram| datagram.is_a?(String) }
    assert_equal ['foo:1|c'], sink.datagrams
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
statsd-instrument-2.8.0 test/capture_sink_test.rb
statsd-instrument-2.7.1 test/capture_sink_test.rb
statsd-instrument-2.7.0 test/capture_sink_test.rb