1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-02-11 10:51:16 +00:00
ghostream/stream/messaging_test.go

31 lines
561 B
Go
Raw Normal View History

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