-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathprometheus_spec.lua
52 lines (39 loc) · 1.32 KB
/
prometheus_spec.lua
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
describe('prometheus', function()
before_each(function() package.loaded['apicast.prometheus'] = nil end)
describe('shared dictionary is missing', function()
before_each(function() ngx.shared.prometheus_metrics = nil end)
it('can be called', function()
assert.is_nil(require('apicast.prometheus')())
end)
it('can be collected', function()
assert.is_nil(require('apicast.prometheus'):collect())
end)
end)
describe('shared dictionary is there', function()
before_each(function()
ngx.shared.prometheus_metrics = {
set = function() end,
get_keys = function() return {} end
}
end)
local prometheus
local Prometheus
before_each(function()
prometheus = assert(require('apicast.prometheus'))
Prometheus = getmetatable(prometheus).__index
end)
for _,metric_type in pairs{ 'counter', 'gauge', 'histogram' } do
describe(metric_type, function()
it('can be called', function()
stub(Prometheus, metric_type)
prometheus(metric_type, 'some_metric')
assert.stub(Prometheus[metric_type]).was.called_with(Prometheus, 'some_metric')
end)
end)
end
it('can be collected', function()
ngx.header = { }
assert.is_nil(require('apicast.prometheus'):collect())
end)
end)
end)