Esempio n. 1
0
func TestWrite(t *testing.T) {
	ch := make(chan []byte)
	broadcaster := writer.NewBroadcaster(ch)
	testWriter := TestWriter{}
	broadcaster.Add(&testWriter)

	str := randomString()
	bin := []byte(str)
	go broadcaster.Run()
	broadcaster.Write(bin)
	defer func() {
		broadcaster.Close()
	}()
	time.Sleep(20 * time.Millisecond) // wait for writing data

	if str != string(testWriter.Writed[:]) {
		t.Errorf("dont same string, %v, %v", str, string(testWriter.Writed[:]))
	}
}
Esempio n. 2
0
func prepareWriter(readCh chan []byte) *writer.Broadcaster {
	bc := writer.NewBroadcaster(readCh)
	go bc.Run()
	return bc
}