Skip to content

Commit

Permalink
Add tests covering 0 value passed to set() and observe()
Browse files Browse the repository at this point in the history
Updates #172
  • Loading branch information
knyar committed Aug 27, 2024
1 parent 1c26a72 commit 313303f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions prometheus_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ function TestPrometheus:testCounters()
luaunit.assertEquals(self.dict:get('metric2{f2="v2",f1="v1"}'), 4)
luaunit.assertEquals(ngx.logs, nil)
end
function TestPrometheus:testGaugeSet()
self.gauge1:set(100)
luaunit.assertEquals(self.dict:get("gauge1"), 100)
self.gauge1:set(0)
luaunit.assertEquals(self.dict:get("gauge1"), 0)
self.gauge1:set(-5)
luaunit.assertEquals(self.dict:get("gauge1"), -5)
luaunit.assertEquals(self.dict:get("nginx_metric_errors_total"), 0)
end
function TestPrometheus:testGaugeIncDec()
self.gauge1:inc(-1)
luaunit.assertEquals(self.dict:get("gauge1"), -1)
Expand Down Expand Up @@ -598,7 +607,19 @@ function TestPrometheus:testLatencyHistogram()
luaunit.assertEquals(self.dict:get('l2_bucket{var="ok",site="site1",le="Inf"}'), 2)
luaunit.assertEquals(self.dict:get('l2_count{var="ok",site="site1"}'), 2)
luaunit.assertEquals(self.dict:get('l2_sum{var="ok",site="site1"}'), 0.151)

-- test observing a zero value
self.hist1:observe(0)
self.p._counter:sync()
luaunit.assertEquals(self.dict:get('l1_bucket{le="00.300"}'), 1)
luaunit.assertEquals(self.dict:get('l1_bucket{le="00.400"}'), 3)
luaunit.assertEquals(self.dict:get('l1_bucket{le="00.500"}'), 3)
luaunit.assertEquals(self.dict:get('l1_bucket{le="Inf"}'), 3)
luaunit.assertEquals(self.dict:get('l1_count'), 3)
luaunit.assertEquals(self.dict:get('l1_sum'), 0.75)

luaunit.assertEquals(ngx.logs, nil)
luaunit.assertEquals(self.dict:get("nginx_metric_errors_total"), 0)
end
function TestPrometheus:testLabelEscaping()
self.counter2:inc(1, {"v2", "\""})
Expand Down

0 comments on commit 313303f

Please sign in to comment.