alert_test.go 425 B

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