2020-04-12 16:37:58 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepeater(t *testing.T) {
|
|
|
|
r := NewRepeater()
|
|
|
|
|
|
|
|
buf1 := bytes.NewBufferString("buf1")
|
2020-04-12 17:30:00 -06:00
|
|
|
r.Join(buf1)
|
2020-04-12 20:46:51 -06:00
|
|
|
if r.Listeners() != 1 {
|
2020-04-12 16:37:58 -06:00
|
|
|
t.Error("Joining did nothing")
|
|
|
|
}
|
2020-04-12 17:30:00 -06:00
|
|
|
r.Send([]byte("moo"))
|
2020-04-12 16:37:58 -06:00
|
|
|
if buf1.String() != "buf1moo" {
|
|
|
|
t.Error("Client 1 not repeating", buf1)
|
|
|
|
}
|
2020-05-30 22:23:53 -06:00
|
|
|
|
2020-04-12 16:37:58 -06:00
|
|
|
buf2 := bytes.NewBufferString("buf2")
|
2020-04-12 17:30:00 -06:00
|
|
|
r.Join(buf2)
|
|
|
|
r.Send([]byte("bar"))
|
2020-04-12 16:37:58 -06:00
|
|
|
if buf1.String() != "buf1moobar" {
|
|
|
|
t.Error("Client 1 not repeating", buf1)
|
|
|
|
}
|
|
|
|
if buf2.String() != "buf2bar" {
|
|
|
|
t.Error("Client 2 not repeating", buf2)
|
|
|
|
}
|
2020-05-30 22:23:53 -06:00
|
|
|
|
2020-04-12 17:30:00 -06:00
|
|
|
r.Part(buf1)
|
|
|
|
r.Send([]byte("baz"))
|
2020-04-12 16:37:58 -06:00
|
|
|
if buf1.String() != "buf1moobar" {
|
|
|
|
t.Error("Client 1 still getting data after part", buf1)
|
|
|
|
}
|
|
|
|
if buf2.String() != "buf2barbaz" {
|
|
|
|
t.Error("Client 2 not getting data after part", buf2)
|
|
|
|
}
|
|
|
|
}
|