prometheus_text_format_spec.rb 1.1 KB
Newer Older
P
Pawel Chojnacki 已提交
1 2 3 4 5 6
describe Gitlab::HealthChecks::PrometheusTextFormat do
  let(:metric_class) { Gitlab::HealthChecks::Metric }
  subject { described_class.new }

  describe '#marshal' do
    let(:sample_metrics) do
7 8
      [metric_class.new('metric1', 1),
       metric_class.new('metric2', 2)]
P
Pawel Chojnacki 已提交
9 10 11
    end

    it 'marshal to text with non repeating type definition' do
12 13 14 15 16 17 18
      expected = <<-EXPECTED.strip_heredoc
        # TYPE metric1 gauge
        metric1 1
        # TYPE metric2 gauge
        metric2 2
      EXPECTED

19
      expect(subject.marshal(sample_metrics)).to eq(expected)
P
Pawel Chojnacki 已提交
20 21 22 23
    end

    context 'metrics where name repeats' do
      let(:sample_metrics) do
24 25 26
        [metric_class.new('metric1', 1),
         metric_class.new('metric1', 2),
         metric_class.new('metric2', 3)]
P
Pawel Chojnacki 已提交
27 28 29
      end

      it 'marshal to text with non repeating type definition' do
30 31 32 33 34 35
        expected = <<-EXPECTED.strip_heredoc
          # TYPE metric1 gauge
          metric1 1
          metric1 2
          # TYPE metric2 gauge
          metric2 3
P
Pawel Chojnacki 已提交
36
        EXPECTED
37
        expect(subject.marshal(sample_metrics)).to eq(expected)
P
Pawel Chojnacki 已提交
38 39 40 41
      end
    end
  end
end