summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/metrics/metric_spec.rb
blob: f26fca52c5067a77d0d7679fc6fabc802ee462a0 (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
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
require 'spec_helper'

describe Gitlab::Metrics::Metric do
  let(:metric) do
    described_class.new('foo', { number: 10 }, { host: 'localtoast' })
  end

  describe '#series' do
    subject { metric.series }

    it { is_expected.to eq('foo') }
  end

  describe '#values' do
    subject { metric.values }

    it { is_expected.to eq({ number: 10 }) }
  end

  describe '#tags' do
    subject { metric.tags }

    it { is_expected.to eq({ host: 'localtoast' }) }
  end

  describe '#type' do
    subject { metric.type }

    it { is_expected.to eq(:metric) }
  end

  describe '#event?' do
    it 'returns false for a regular metric' do
      expect(metric.event?).to eq(false)
    end

    it 'returns true for an event metric' do
      expect(metric).to receive(:type).and_return(:event)

      expect(metric.event?).to eq(true)
    end
  end

  describe '#to_hash' do
    it 'returns a Hash' do
      expect(metric.to_hash).to be_an_instance_of(Hash)
    end

    describe 'the returned Hash' do
      let(:hash) { metric.to_hash }

      it 'includes the series' do
        expect(hash[:series]).to eq('foo')
      end

      it 'includes the tags' do
        expect(hash[:tags]).to be_an_instance_of(Hash)
      end

      it 'includes the values' do
        expect(hash[:values]).to eq({ number: 10 })
      end

      it 'includes the timestamp' do
        expect(hash[:timestamp]).to be_an_instance_of(Fixnum)
      end
    end
  end
end