File: gauge_spec.rb

package info (click to toggle)
ruby-prometheus-client-mmap 1.2.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 700 kB
  • sloc: ruby: 3,149; sh: 54; makefile: 21
file content (70 lines) | stat: -rw-r--r-- 1,829 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'prometheus/client'
require 'prometheus/client/gauge'
require 'examples/metric_example'

describe Prometheus::Client::Gauge do
  let(:gauge) { Prometheus::Client::Gauge.new(:foo, 'foo description', test: nil) }

  before do
    allow(Prometheus::Client.configuration).to receive(:value_class).and_return(Prometheus::Client::SimpleValue)
  end

  it_behaves_like Prometheus::Client::Metric do
    let(:type) { Float }
  end

  describe '#set' do
    it 'sets a metric value' do
      expect do
        gauge.set({}, 42)
      end.to change { gauge.get }.from(0).to(42)
    end

    it 'sets a metric value for a given label set' do
      expect do
        expect do
          gauge.set({ test: 'value' }, 42)
        end.to(change { gauge.get(test: 'value') }.from(0).to(42))
      end.to_not(change { gauge.get })
    end
  end

  describe '#increment' do
    it 'increments a metric value' do
      gauge.set({}, 1)

      expect do
        gauge.increment({}, 42)
      end.to change { gauge.get }.from(1).to(43)
    end

    it 'sets a metric value for a given label set' do
      gauge.increment({ test: 'value' }, 1)
      expect do
        expect do
          gauge.increment({ test: 'value' }, 42)
        end.to(change { gauge.get(test: 'value') }.from(1).to(43))
      end.to_not(change { gauge.get })
    end
  end

  describe '#decrement' do
    it 'decrements a metric value' do
      gauge.set({}, 10)

      expect do
        gauge.decrement({}, 1)
      end.to change { gauge.get }.from(10).to(9)
    end

    it 'sets a metric value for a given label set' do
      gauge.set({ test: 'value' }, 10)
      expect do
        expect do
          gauge.decrement({ test: 'value' }, 5)
        end.to(change { gauge.get(test: 'value') }.from(10).to(5))
      end.to_not(change { gauge.get })
    end
  end

end