mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
21 lines
214 B
Go
21 lines
214 B
Go
package syncx
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestOnce(t *testing.T) {
|
|
var v int
|
|
add := Once(func() {
|
|
v++
|
|
})
|
|
|
|
for i := 0; i < 5; i++ {
|
|
add()
|
|
}
|
|
|
|
assert.Equal(t, 1, v)
|
|
}
|