mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-29 12:10:54 +02:00
Add Stream messaging struct
This commit is contained in:
30
stream/messaging_test.go
Normal file
30
stream/messaging_test.go
Normal file
@ -0,0 +1,30 @@
|
||||
package stream
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWithoutOutputs(t *testing.T) {
|
||||
stream := New()
|
||||
defer stream.Close()
|
||||
stream.Broadcast <- "hello world"
|
||||
}
|
||||
|
||||
func TestWithOneOutput(t *testing.T) {
|
||||
stream := New()
|
||||
defer stream.Close()
|
||||
|
||||
// Register one output
|
||||
output := make(chan interface{}, 64)
|
||||
stream.Register(output)
|
||||
|
||||
// Try to pass one message
|
||||
stream.Broadcast <- "hello world"
|
||||
msg := <-output
|
||||
if m, ok := msg.(string); !ok || m != "hello world" {
|
||||
t.Error("Message has wrong type or content")
|
||||
}
|
||||
|
||||
// Unregister
|
||||
stream.Unregister(output)
|
||||
}
|
Reference in New Issue
Block a user