github.com/EagleQL/Xray-core@v1.4.3/app/stats/counter_test.go (about)

     1  package stats_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	. "github.com/xtls/xray-core/app/stats"
     8  	"github.com/xtls/xray-core/common"
     9  	"github.com/xtls/xray-core/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  }