1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-01 19:45:24 +00:00
v2fly/app/stats/stats_test.go

36 lines
705 B
Go
Raw Normal View History

2018-03-30 17:56:59 +00:00
package stats_test
import (
2018-03-30 21:17:28 +00:00
"context"
2018-03-30 17:56:59 +00:00
"testing"
. "v2ray.com/core/app/stats"
2018-03-30 21:17:28 +00:00
"v2ray.com/core/common"
"v2ray.com/core/features/stats"
2018-03-30 17:56:59 +00:00
)
func TestInternface(t *testing.T) {
2019-01-08 22:27:02 +00:00
_ = (stats.Manager)(new(Manager))
2018-03-30 17:56:59 +00:00
}
2018-03-30 21:17:28 +00:00
func TestStatsCounter(t *testing.T) {
raw, err := common.CreateObject(context.Background(), &Config{})
2019-01-08 22:27:02 +00:00
common.Must(err)
2018-03-30 21:17:28 +00:00
m := raw.(stats.Manager)
2018-03-30 21:17:28 +00:00
c, err := m.RegisterCounter("test.counter")
2019-01-08 22:27:02 +00:00
common.Must(err)
if v := c.Add(1); v != 1 {
t.Fatal("unpexcted Add(1) return: ", v, ", wanted ", 1)
}
if v := c.Set(0); v != 1 {
t.Fatal("unexpected Set(0) return: ", v, ", wanted ", 1)
}
2018-03-30 21:17:28 +00:00
2019-01-08 22:27:02 +00:00
if v := c.Value(); v != 0 {
t.Fatal("unexpected Value() return: ", v, ", wanted ", 0)
}
2018-03-30 21:17:28 +00:00
}