Buffer writes to DataChannel, remove blocking on openChannel (#12)

This commit is contained in:
Serene Han 2016-02-17 18:38:40 -08:00
parent 760dee8a0f
commit eb7eb04ac0
2 changed files with 93 additions and 40 deletions

44
client/client_test.go Normal file
View file

@ -0,0 +1,44 @@
package main
import (
"bytes"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
type MockDataChannel struct {
destination bytes.Buffer
}
func (m *MockDataChannel) Send(data []byte) {
m.destination.Write(data)
}
func (*MockDataChannel) Close() error {
return nil
}
func TestConnect(t *testing.T) {
Convey("Snowflake", t, func() {
Convey("WebRTC Connection", func() {
c := new(webRTCConn)
So(c.buffer.Bytes(), ShouldEqual, nil)
Convey("SendData buffers when datachannel is nil", func() {
c.sendData([]byte("test"))
c.snowflake = nil
So(c.buffer.Bytes(), ShouldResemble, []byte("test"))
})
Convey("SendData sends to datachannel when not nil", func() {
mock := new(MockDataChannel)
c.snowflake = mock
c.sendData([]byte("test"))
So(c.buffer.Bytes(), ShouldEqual, nil)
So(mock.destination.Bytes(), ShouldResemble, []byte("test"))
})
})
})
}