-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tld
committed
Jul 31, 2024
1 parent
a916ba4
commit ecdaf37
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package eventcenter | ||
|
||
import ( | ||
"testing" | ||
|
||
"net/http" | ||
"net/http/httptest" | ||
|
||
"github.com/agiledragon/gomonkey/v2" | ||
. "github.com/smartystreets/goconvey/convey" | ||
"github.com/tianluoding/eventcenter/eventbus" | ||
) | ||
|
||
func TestEventCenter(t *testing.T) { | ||
Convey("Given an EventCenter instance", t, func() { | ||
eb := &eventbus.EventBus{} | ||
center := NewEventCenter(eb) | ||
|
||
Convey("When publishing an event", func() { | ||
patches := gomonkey.ApplyFunc(eb.Publish, func(event eventbus.Event) {}) | ||
defer patches.Reset() | ||
|
||
center.Publish(eventbus.Event{}) | ||
}) | ||
|
||
Convey("When handling WebSocket connections", func() { | ||
w := httptest.NewRecorder() | ||
r, _ := http.NewRequest("GET", "/", nil) | ||
|
||
patches := gomonkey.ApplyFunc(eb.Subscribe, func(id string, name string, ch chan eventbus.Event) {}) | ||
patches.ApplyFunc(eb.Unsubscribe, func(id string, name string) {}) | ||
defer patches.Reset() | ||
|
||
center.HandleWebSocket(w, r) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters