1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-03 16:57:38 -05:00
v2fly/app/stats/stats_test.go

36 lines
705 B
Go
Raw Normal View History

2018-03-30 13:56:59 -04:00
package stats_test
import (
2018-03-30 17:17:28 -04:00
"context"
2018-03-30 13:56:59 -04:00
"testing"
. "v2ray.com/core/app/stats"
2018-03-30 17:17:28 -04:00
"v2ray.com/core/common"
"v2ray.com/core/features/stats"
2018-03-30 13:56:59 -04:00
)
func TestInternface(t *testing.T) {
2019-01-08 17:27:02 -05:00
_ = (stats.Manager)(new(Manager))
2018-03-30 13:56:59 -04:00
}
2018-03-30 17:17:28 -04:00
func TestStatsCounter(t *testing.T) {
raw, err := common.CreateObject(context.Background(), &Config{})
2019-01-08 17:27:02 -05:00
common.Must(err)
2018-03-30 17:17:28 -04:00
m := raw.(stats.Manager)
2018-03-30 17:17:28 -04:00
c, err := m.RegisterCounter("test.counter")
2019-01-08 17:27:02 -05: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 17:17:28 -04:00
2019-01-08 17:27:02 -05:00
if v := c.Value(); v != 0 {
t.Fatal("unexpected Value() return: ", v, ", wanted ", 0)
}
2018-03-30 17:17:28 -04:00
}