aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/core/metrics/prometheus/counter_test.go
diff options
context:
space:
mode:
authorhcpp <hcpp@ydb.tech>2023-11-08 12:09:41 +0300
committerhcpp <hcpp@ydb.tech>2023-11-08 12:56:14 +0300
commita361f5b98b98b44ea510d274f6769164640dd5e1 (patch)
treec47c80962c6e2e7b06798238752fd3da0191a3f6 /library/go/core/metrics/prometheus/counter_test.go
parent9478806fde1f4d40bd5a45e7cbe77237dab613e9 (diff)
downloadydb-a361f5b98b98b44ea510d274f6769164640dd5e1.tar.gz
metrics have been added
Diffstat (limited to 'library/go/core/metrics/prometheus/counter_test.go')
-rw-r--r--library/go/core/metrics/prometheus/counter_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/library/go/core/metrics/prometheus/counter_test.go b/library/go/core/metrics/prometheus/counter_test.go
new file mode 100644
index 0000000000..04f0c894f8
--- /dev/null
+++ b/library/go/core/metrics/prometheus/counter_test.go
@@ -0,0 +1,38 @@
+package prometheus
+
+import (
+ "testing"
+
+ "github.com/prometheus/client_golang/prometheus"
+ dto "github.com/prometheus/client_model/go"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestCounter_Add(t *testing.T) {
+ c := &Counter{cnt: prometheus.NewCounter(prometheus.CounterOpts{
+ Name: "test_counter_add",
+ })}
+
+ var expectValue int64 = 42
+ c.Add(expectValue)
+
+ var res dto.Metric
+ err := c.cnt.Write(&res)
+
+ assert.NoError(t, err)
+ assert.Equal(t, expectValue, int64(res.GetCounter().GetValue()))
+}
+
+func TestCounter_Inc(t *testing.T) {
+ c := &Counter{cnt: prometheus.NewCounter(prometheus.CounterOpts{
+ Name: "test_counter_inc",
+ })}
+
+ var res dto.Metric
+ for i := 1; i <= 10; i++ {
+ c.Inc()
+ err := c.cnt.Write(&res)
+ assert.NoError(t, err)
+ assert.Equal(t, int64(i), int64(res.GetCounter().GetValue()))
+ }
+}