Sha256: f8a59bcc56a24138f01c4d4a75568bac5934b8ab502483a7537c29e0cffbb75b

Contents?: true

Size: 1.42 KB

Versions: 32

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

32 entries across 32 versions & 1 rubygems

Version Path
statsd-instrument-3.5.4 test/capture_sink_test.rb
statsd-instrument-3.5.3 test/capture_sink_test.rb
statsd-instrument-3.5.2 test/capture_sink_test.rb
statsd-instrument-3.5.1 test/capture_sink_test.rb
statsd-instrument-3.5.0 test/capture_sink_test.rb
statsd-instrument-3.4.0 test/capture_sink_test.rb
statsd-instrument-3.3.0 test/capture_sink_test.rb
statsd-instrument-3.2.1 test/capture_sink_test.rb
statsd-instrument-3.2.0 test/capture_sink_test.rb
statsd-instrument-3.1.2 test/capture_sink_test.rb
statsd-instrument-3.1.1 test/capture_sink_test.rb
statsd-instrument-3.1.0 test/capture_sink_test.rb