Sha256: aba5299ff237e0a5bc43b3dc70e195d51aef0fbb3b8422ed05a7bb510a9ad24f

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

require 'test_helper'

class UDPBackendTestWithDefaultTags < Minitest::Test
  def setup
    @backend = StatsD::Instrument::Backends::UDPBackend.new("localhost:8125", :collectd, {pod_ip: "10.0.0.42"})
  end

  
  def test_constructor_must_create_default_tags
    default_tags = @backend.instance_eval { self.default_metric_tags }

    assert_equal default_tags.class, Hash
    assert_includes default_tags.keys, :pod_ip
    assert_equal default_tags[:pod_ip], "10.0.0.42"
  end
  
  def test_metric_with_no_tags_must_have_default_tags
    metric = StatsD::Instrument::Metric.new(type: :c, name: 'test', sample_rate: 0.5)
    command = @backend.generate_packet(metric)
    assert command.include?("pod_ip=10.0.0.42")
  end
  
  def test_metric_with_other_tags_must_have_default_tags
    metric = StatsD::Instrument::Metric.new(type: :c, name: 'test', sample_rate: 0.5, tags: ["conduit:0.0"])
    command = @backend.generate_packet(metric)
    assert command.include?("pod_ip=10.0.0.42")
    assert command.include?("conduit=0.0")

  end
  
  def test_metric_with_same_tag_must_override_default_tags
    metric = StatsD::Instrument::Metric.new(type: :c, name: 'test', sample_rate: 0.5, tags: ["pod_ip:10.0.0.43", "conduit=0.0"])
    command = @backend.generate_packet(metric)
    assert command.include?("conduit=0.0")
    assert command.include?("pod_ip=10.0.0.43")
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qubole-statsd-instrument-2.1.6 test/udp_backend_with_default_tags.rb
qubole-statsd-instrument-2.1.5 test/udp_backend_with_default_tags.rb