Files
EdgeNode/internal/events/utils_test.go

35 lines
556 B
Go
Raw Normal View History

2022-01-12 20:31:04 +08:00
package events_test
2020-10-28 11:19:06 +08:00
2022-01-12 20:31:04 +08:00
import (
"testing"
2024-07-27 15:42:50 +08:00
"github.com/TeaOSLab/EdgeNode/internal/events"
2022-01-12 20:31:04 +08:00
)
2020-10-28 11:19:06 +08:00
func TestOn(t *testing.T) {
2022-01-12 20:31:04 +08:00
type User struct {
name string
}
2023-08-08 18:14:48 +08:00
var u = &User{name: "lily"}
var u2 = &User{name: "lucy"}
2022-01-12 20:31:04 +08:00
events.On("hello", func() {
2020-10-28 11:19:06 +08:00
t.Log("world")
})
2022-01-12 20:31:04 +08:00
events.On("hello", func() {
2020-10-28 11:19:06 +08:00
t.Log("world2")
})
2022-01-12 20:31:04 +08:00
events.OnKey("hello", u, func() {
t.Log("world3")
})
events.OnKey("hello", u, func() {
t.Log("world4")
})
events.Remove(u)
events.Remove(u2)
events.OnKey("hello2", nil, func() {
2020-10-28 11:19:06 +08:00
t.Log("world2")
})
2022-01-12 20:31:04 +08:00
events.Notify("hello")
2020-10-28 11:19:06 +08:00
}