2021-09-23 19:57:05 +08:00
|
|
|
//go:build linux
|
2020-10-07 23:02:58 +08:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package stat
|
|
|
|
|
|
|
|
import (
|
2022-10-23 10:54:41 +08:00
|
|
|
"os"
|
2020-10-07 23:02:58 +08:00
|
|
|
"strconv"
|
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReport(t *testing.T) {
|
2022-10-23 10:54:41 +08:00
|
|
|
os.Setenv(clusterNameKey, "test-cluster")
|
|
|
|
defer os.Unsetenv(clusterNameKey)
|
|
|
|
|
2020-10-07 23:02:58 +08:00
|
|
|
var count int32
|
|
|
|
SetReporter(func(s string) {
|
|
|
|
atomic.AddInt32(&count, 1)
|
|
|
|
})
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
Report(strconv.Itoa(i))
|
|
|
|
}
|
|
|
|
assert.Equal(t, int32(1), count)
|
|
|
|
}
|