github.com/lingyao2333/mo-zero@v1.4.1/core/stat/alert_test.go (about)

     1  //go:build linux
     2  // +build linux
     3  
     4  package stat
     5  
     6  import (
     7  	"os"
     8  	"strconv"
     9  	"sync/atomic"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  func TestReport(t *testing.T) {
    16  	os.Setenv(clusterNameKey, "test-cluster")
    17  	defer os.Unsetenv(clusterNameKey)
    18  
    19  	var count int32
    20  	SetReporter(func(s string) {
    21  		atomic.AddInt32(&count, 1)
    22  	})
    23  	for i := 0; i < 10; i++ {
    24  		Report(strconv.Itoa(i))
    25  	}
    26  	assert.Equal(t, int32(1), count)
    27  }