github.com/v2fly/v2ray-core/v4@v4.45.2/app/stats/counter_test.go (about)

     1  package stats_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	. "github.com/v2fly/v2ray-core/v4/app/stats"
     8  	"github.com/v2fly/v2ray-core/v4/common"
     9  	"github.com/v2fly/v2ray-core/v4/features/stats"
    10  )
    11  
    12  func TestStatsCounter(t *testing.T) {
    13  	raw, err := common.CreateObject(context.Background(), &Config{})
    14  	common.Must(err)
    15  
    16  	m := raw.(stats.Manager)
    17  	c, err := m.RegisterCounter("test.counter")
    18  	common.Must(err)
    19  
    20  	if v := c.Add(1); v != 1 {
    21  		t.Fatal("unpexcted Add(1) return: ", v, ", wanted ", 1)
    22  	}
    23  
    24  	if v := c.Set(0); v != 1 {
    25  		t.Fatal("unexpected Set(0) return: ", v, ", wanted ", 1)
    26  	}
    27  
    28  	if v := c.Value(); v != 0 {
    29  		t.Fatal("unexpected Value() return: ", v, ", wanted ", 0)
    30  	}
    31  }