alert_test.go 409 B

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