mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
44 lines
913 B
Go
44 lines
913 B
Go
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"))
|
|
})
|
|
})
|
|
|
|
})
|
|
}
|