Add test for DialWithDialer

This commit is contained in:
Julien Laffaye 2022-03-08 20:25:35 -05:00
parent a8377c07ac
commit 813c8a8384

View File

@ -7,6 +7,7 @@ import (
"net"
"net/textproto"
"strings"
"syscall"
"testing"
"time"
@ -27,7 +28,6 @@ func TestConnEPSV(t *testing.T) {
}
func testConn(t *testing.T, disableEPSV bool) {
mock, c := openConn(t, "127.0.0.1", DialWithTimeout(5*time.Second), DialWithDisabledEPSV(disableEPSV))
err := c.Login("anonymous", "anonymous")
@ -417,3 +417,22 @@ func TestDialWithDialFunc(t *testing.T) {
_, err := Dial("bogus-address", DialWithDialFunc(f))
assert.Equal(t, dialErr, err)
}
func TestDialWithDialer(t *testing.T) {
dialerCalled := false
dialer := net.Dialer{
Control: func(network, address string, c syscall.RawConn) error {
dialerCalled = true
return nil
},
}
mock, err := newFtpMock(t, "127.0.0.1")
assert.NoError(t, err)
c, err := Dial(mock.Addr(), DialWithDialer(dialer))
assert.NoError(t, err)
assert.NoError(t, c.Quit())
assert.Equal(t, true, dialerCalled)
}