ooni-probe-cli/internal/engine/experiment/ndt7/wsconn_test.go
Simone Basso 3265bc670a
refactor(ndt7): use netxlite rather than netx (#768)
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
2022-05-30 23:14:07 +02:00

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
}