mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Buffer writes to DataChannel, remove blocking on openChannel (#12)
This commit is contained in:
parent
760dee8a0f
commit
eb7eb04ac0
2 changed files with 93 additions and 40 deletions
44
client/client_test.go
Normal file
44
client/client_test.go
Normal 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"))
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue