refactor: only use shaping dialer for ndt7 and dash (#754)
See https://github.com/ooni/probe/issues/2112 for context. While there, run `go fix -fix buildtag ./...`
This commit is contained in:
parent
b68b8e1e8f
commit
6924d1ad81
17 changed files with 126 additions and 65 deletions
66
internal/netxlite/shaping_shaping_test.go
Normal file
66
internal/netxlite/shaping_shaping_test.go
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//go:build shaping
|
||||
|
||||
package netxlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
||||
)
|
||||
|
||||
func TestNewShapingDialerx(t *testing.T) {
|
||||
t.Run("failure", func(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
d := &mocks.Dialer{
|
||||
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return nil, expected
|
||||
},
|
||||
}
|
||||
shd := NewMaybeShapingDialer(d)
|
||||
conn, err := shd.DialContext(context.Background(), "tcp", "8.8.8.8:443")
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("unexpected err", err)
|
||||
}
|
||||
if conn != nil {
|
||||
t.Fatal("expected nil conn")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("success", func(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
uc := &mocks.Conn{
|
||||
MockRead: func(b []byte) (int, error) {
|
||||
return 0, expected
|
||||
},
|
||||
MockWrite: func(b []byte) (int, error) {
|
||||
return 0, expected
|
||||
},
|
||||
}
|
||||
d := &mocks.Dialer{
|
||||
MockDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return uc, nil
|
||||
},
|
||||
}
|
||||
shd := NewMaybeShapingDialer(d)
|
||||
conn, err := shd.DialContext(context.Background(), "tcp", "8.8.8.8:443")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := conn.(*shapingConn); !ok {
|
||||
t.Fatal("not shapingConn")
|
||||
}
|
||||
validateCountAndErr := func(count int, err error) {
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("unexpected err", err)
|
||||
}
|
||||
if count != 0 {
|
||||
t.Fatal("expected zero")
|
||||
}
|
||||
}
|
||||
validateCountAndErr(conn.Read(make([]byte, 16)))
|
||||
validateCountAndErr(conn.Write(make([]byte, 16)))
|
||||
})
|
||||
}
|
||||
Loading…
Reference in a new issue