ghostream/stream/messaging_test.go

31 lines
561 B
Go
Raw Normal View History

2020-10-17 08:02:38 +00:00
package stream
import (
"testing"
)
func TestWithoutOutputs(t *testing.T) {
stream := New()
defer stream.Close()
2020-10-17 08:21:40 +00:00
stream.Broadcast <- []byte("hello world")
2020-10-17 08:02:38 +00:00
}
func TestWithOneOutput(t *testing.T) {
stream := New()
defer stream.Close()
// Register one output
2020-10-17 08:21:40 +00:00
output := make(chan []byte, 64)
2020-10-17 08:02:38 +00:00
stream.Register(output)
// Try to pass one message
2020-10-17 08:21:40 +00:00
stream.Broadcast <- []byte("hello world")
2020-10-17 08:02:38 +00:00
msg := <-output
2020-10-17 08:21:40 +00:00
if string(msg) != "hello world" {
t.Errorf("Message has wrong content: %s != hello world", msg)
2020-10-17 08:02:38 +00:00
}
// Unregister
stream.Unregister(output)
}