refactor: move quicdialing base functionality to netxlite (#406)
Part of https://github.com/ooni/probe/issues/1505
This commit is contained in:
parent
c00cad1382
commit
925ca22b88
10 changed files with 254 additions and 84 deletions
13
internal/netxmocks/quic.go
Normal file
13
internal/netxmocks/quic.go
Normal 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)
|
||||
}
|
||||
23
internal/netxmocks/quic_test.go
Normal file
23
internal/netxmocks/quic_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue