3265bc670a
This diff required us to move some code around, but no major change actually happened, except better tests. While there, I also slightly refactored ndt7's implementation and removed the ProxyURL setting, which was actually unused. See https://github.com/ooni/probe/issues/2121
40 lines
856 B
Go
40 lines
856 B
Go
package ndt7
|
|
|
|
import (
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
type mockableWSConn struct {
|
|
NextReaderMsgType int
|
|
NextReaderErr error
|
|
NextReaderReader func() io.Reader
|
|
ReadDeadlineErr error
|
|
WriteDeadlineErr error
|
|
WritePreparedMessageErr error
|
|
}
|
|
|
|
func (c *mockableWSConn) NextReader() (int, io.Reader, error) {
|
|
var reader io.Reader
|
|
if c.NextReaderReader != nil {
|
|
reader = c.NextReaderReader()
|
|
}
|
|
return c.NextReaderMsgType, reader, c.NextReaderErr
|
|
}
|
|
|
|
func (c *mockableWSConn) SetReadDeadline(time.Time) error {
|
|
return c.ReadDeadlineErr
|
|
}
|
|
|
|
func (c *mockableWSConn) SetReadLimit(int64) {}
|
|
|
|
func (c *mockableWSConn) SetWriteDeadline(time.Time) error {
|
|
return c.WriteDeadlineErr
|
|
}
|
|
|
|
func (c *mockableWSConn) WritePreparedMessage(*websocket.PreparedMessage) error {
|
|
return c.WritePreparedMessageErr
|
|
}
|