summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/health_checks/prometheus_text_format_spec.rb
blob: ed757ed60d87b2e6911a32fc86d7535ad21ece62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
describe Gitlab::HealthChecks::PrometheusTextFormat do
  let(:metric_class) { Gitlab::HealthChecks::Metric }
  subject { described_class.new }

  describe '#marshal' do
    let(:sample_metrics) do
      [metric_class.new('metric1', 1),
       metric_class.new('metric2', 2)]
    end

    it 'marshal to text with non repeating type definition' do
      expected = <<-EXPECTED.strip_heredoc
        # TYPE metric1 gauge
        metric1 1
        # TYPE metric2 gauge
        metric2 2
      EXPECTED

      expect(subject.marshal(sample_metrics)).to eq(expected)
    end

    context 'metrics where name repeats' do
      let(:sample_metrics) do
        [metric_class.new('metric1', 1),
         metric_class.new('metric1', 2),
         metric_class.new('metric2', 3)]
      end

      it 'marshal to text with non repeating type definition' do
        expected = <<-EXPECTED.strip_heredoc
          # TYPE metric1 gauge
          metric1 1
          metric1 2
          # TYPE metric2 gauge
          metric2 3
        EXPECTED
        expect(subject.marshal(sample_metrics)).to eq(expected)
      end
    end
  end
end