refactor: move quicdialing base functionality to netxlite (#406)

Part of https://github.com/ooni/probe/issues/1505
This commit is contained in:
Simone Basso 2021-06-25 17:04:24 +02:00 committed by GitHub
commit 925ca22b88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 254 additions and 84 deletions

View file

@ -0,0 +1,13 @@
package netxmocks
import "net"
// QUICListener is a mockable netxlite.QUICListener.
type QUICListener struct {
MockListen func(addr *net.UDPAddr) (net.PacketConn, error)
}
// Listen calls MockListen.
func (ql *QUICListener) Listen(addr *net.UDPAddr) (net.PacketConn, error) {
return ql.MockListen(addr)
}

View file

@ -0,0 +1,23 @@
package netxmocks
import (
"errors"
"net"
"testing"
)
func TestQUICListenerListen(t *testing.T) {
expected := errors.New("mocked error")
ql := &QUICListener{
MockListen: func(addr *net.UDPAddr) (net.PacketConn, error) {
return nil, expected
},
}
pconn, err := ql.Listen(&net.UDPAddr{})
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", expected)
}
if pconn != nil {
t.Fatal("expected nil conn here")
}
}