2011-09-05 23:36:14 +02:00
|
|
|
package ftp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-03-09 01:06:48 +01:00
|
|
|
"fmt"
|
2022-08-18 17:18:54 +02:00
|
|
|
"io"
|
2022-03-09 01:06:48 +01:00
|
|
|
"net"
|
2022-03-09 02:25:35 +01:00
|
|
|
"syscall"
|
2011-09-05 23:36:14 +02:00
|
|
|
"testing"
|
2015-03-16 23:45:56 +01:00
|
|
|
"time"
|
2021-02-13 18:42:15 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2011-09-05 23:36:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
testData = "Just some text"
|
2013-02-17 10:31:56 +01:00
|
|
|
testDir = "mydir"
|
2011-09-05 23:36:14 +02:00
|
|
|
)
|
|
|
|
|
2015-08-20 01:46:22 +02:00
|
|
|
func TestConnPASV(t *testing.T) {
|
|
|
|
testConn(t, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConnEPSV(t *testing.T) {
|
|
|
|
testConn(t, false)
|
|
|
|
}
|
|
|
|
|
2016-11-24 14:49:16 +01:00
|
|
|
func testConn(t *testing.T, disableEPSV bool) {
|
2022-08-18 01:24:40 +02:00
|
|
|
assert := assert.New(t)
|
2019-04-10 20:25:16 +02:00
|
|
|
mock, c := openConn(t, "127.0.0.1", DialWithTimeout(5*time.Second), DialWithDisabledEPSV(disableEPSV))
|
2015-08-20 01:46:22 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
err := c.Login("anonymous", "anonymous")
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-05 23:36:14 +02:00
|
|
|
|
|
|
|
err = c.NoOp()
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-05 23:36:14 +02:00
|
|
|
|
2015-08-18 19:34:22 +02:00
|
|
|
err = c.ChangeDir("incoming")
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2015-08-18 19:34:22 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
dir, err := c.CurrentDir()
|
2022-08-18 01:24:40 +02:00
|
|
|
if assert.NoError(err) {
|
|
|
|
assert.Equal("/incoming", dir)
|
2019-04-10 20:20:50 +02:00
|
|
|
}
|
|
|
|
|
2011-09-05 23:36:14 +02:00
|
|
|
data := bytes.NewBufferString(testData)
|
|
|
|
err = c.Stor("test", data)
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-05 23:36:14 +02:00
|
|
|
|
|
|
|
_, err = c.List(".")
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-05 23:36:14 +02:00
|
|
|
|
|
|
|
err = c.Rename("test", "tset")
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-05 23:36:14 +02:00
|
|
|
|
2017-04-15 11:53:19 +02:00
|
|
|
// Read without deadline
|
2011-09-05 23:36:14 +02:00
|
|
|
r, err := c.Retr("tset")
|
2022-08-18 01:24:40 +02:00
|
|
|
if assert.NoError(err) {
|
2022-08-18 17:18:54 +02:00
|
|
|
buf, err := io.ReadAll(r)
|
2022-08-18 01:24:40 +02:00
|
|
|
if assert.NoError(err) {
|
|
|
|
assert.Equal(testData, string(buf))
|
2011-09-05 23:36:14 +02:00
|
|
|
}
|
2022-08-18 01:24:40 +02:00
|
|
|
|
2011-09-05 23:36:14 +02:00
|
|
|
r.Close()
|
2017-05-05 02:46:29 +02:00
|
|
|
r.Close() // test we can close two times
|
2011-09-05 23:36:14 +02:00
|
|
|
}
|
|
|
|
|
2017-04-15 11:53:19 +02:00
|
|
|
// Read with deadline
|
|
|
|
r, err = c.Retr("tset")
|
2022-08-18 01:24:40 +02:00
|
|
|
if assert.NoError(err) {
|
2022-03-09 00:35:30 +01:00
|
|
|
if err := r.SetDeadline(time.Now()); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-08-18 17:18:54 +02:00
|
|
|
_, err = io.ReadAll(r)
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.ErrorContains(err, "i/o timeout")
|
2017-04-15 11:53:19 +02:00
|
|
|
r.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read with offset
|
2015-08-20 22:47:09 +02:00
|
|
|
r, err = c.RetrFrom("tset", 5)
|
2022-08-18 01:24:40 +02:00
|
|
|
if assert.NoError(err) {
|
2022-08-18 17:18:54 +02:00
|
|
|
buf, err := io.ReadAll(r)
|
2022-08-18 01:24:40 +02:00
|
|
|
if assert.NoError(err) {
|
|
|
|
expected := testData[5:]
|
|
|
|
assert.Equal(expected, string(buf))
|
2015-08-20 22:47:09 +02:00
|
|
|
}
|
2022-08-18 01:24:40 +02:00
|
|
|
|
2013-07-10 12:18:32 +02:00
|
|
|
r.Close()
|
|
|
|
}
|
|
|
|
|
2020-03-10 11:43:17 +01:00
|
|
|
data2 := bytes.NewBufferString(testData)
|
|
|
|
err = c.Append("tset", data2)
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2020-03-10 11:43:17 +01:00
|
|
|
|
|
|
|
// Read without deadline, after append
|
|
|
|
r, err = c.Retr("tset")
|
2022-08-18 01:24:40 +02:00
|
|
|
if assert.NoError(err) {
|
2022-08-18 17:18:54 +02:00
|
|
|
buf, err := io.ReadAll(r)
|
2022-08-18 01:24:40 +02:00
|
|
|
if assert.NoError(err) {
|
|
|
|
assert.Equal(testData+testData, string(buf))
|
2020-03-10 11:43:17 +01:00
|
|
|
}
|
2022-08-18 01:24:40 +02:00
|
|
|
|
2020-03-10 11:43:17 +01:00
|
|
|
r.Close()
|
|
|
|
}
|
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
fileSize, err := c.FileSize("magic-file")
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(int64(42), fileSize)
|
2017-02-20 06:34:20 +01:00
|
|
|
|
2017-03-04 12:58:20 +01:00
|
|
|
_, err = c.FileSize("not-found")
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.Error(err)
|
2017-02-19 21:43:08 +01:00
|
|
|
|
2022-08-21 23:25:29 +02:00
|
|
|
entry, err := c.GetEntry("magic-file")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if entry == nil {
|
|
|
|
t.Fatal("expected entry, got nil")
|
|
|
|
}
|
|
|
|
if entry.Size != 42 {
|
|
|
|
t.Errorf("entry size %q, expected %q", entry.Size, 42)
|
|
|
|
}
|
|
|
|
if entry.Type != EntryTypeFile {
|
|
|
|
t.Errorf("entry type %q, expected %q", entry.Type, EntryTypeFile)
|
|
|
|
}
|
|
|
|
if entry.Name != "magic-file" {
|
|
|
|
t.Errorf("entry name %q, expected %q", entry.Name, "magic-file")
|
|
|
|
}
|
|
|
|
|
|
|
|
entry, err = c.GetEntry("multiline-dir")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if entry == nil {
|
|
|
|
t.Fatal("expected entry, got nil")
|
|
|
|
}
|
|
|
|
if entry.Size != 0 {
|
|
|
|
t.Errorf("entry size %q, expected %q", entry.Size, 0)
|
|
|
|
}
|
|
|
|
if entry.Type != EntryTypeFolder {
|
|
|
|
t.Errorf("entry type %q, expected %q", entry.Type, EntryTypeFolder)
|
|
|
|
}
|
|
|
|
if entry.Name != "multiline-dir" {
|
|
|
|
t.Errorf("entry name %q, expected %q", entry.Name, "multiline-dir")
|
|
|
|
}
|
|
|
|
|
2011-09-06 00:02:01 +02:00
|
|
|
err = c.Delete("tset")
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-06 00:02:01 +02:00
|
|
|
|
2011-09-07 16:52:52 +02:00
|
|
|
err = c.MakeDir(testDir)
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-06 00:02:01 +02:00
|
|
|
|
2011-09-07 16:52:52 +02:00
|
|
|
err = c.ChangeDir(testDir)
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-07 16:52:52 +02:00
|
|
|
|
|
|
|
err = c.ChangeDirToParent()
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-07 16:52:52 +02:00
|
|
|
|
2015-08-20 10:32:28 +02:00
|
|
|
entries, err := c.NameList("/")
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal([]string{"/incoming"}, entries)
|
2015-08-20 10:32:28 +02:00
|
|
|
|
2011-09-07 16:52:52 +02:00
|
|
|
err = c.RemoveDir(testDir)
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2011-09-06 00:02:01 +02:00
|
|
|
|
2013-05-19 21:15:23 +02:00
|
|
|
err = c.Logout()
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.NoError(err)
|
2013-05-19 21:15:23 +02:00
|
|
|
|
2021-03-07 01:43:28 +01:00
|
|
|
if err = c.Quit(); err != nil {
|
2019-04-10 20:20:50 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for the connection to close
|
|
|
|
mock.Wait()
|
2011-09-07 16:52:52 +02:00
|
|
|
|
|
|
|
err = c.NoOp()
|
2022-08-18 01:24:40 +02:00
|
|
|
assert.Error(err, "should error on closed conn")
|
2011-09-05 23:36:14 +02:00
|
|
|
}
|
2013-07-08 07:48:11 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
// TestConnect tests the legacy Connect function
|
|
|
|
func TestConnect(t *testing.T) {
|
|
|
|
mock, err := newFtpMock(t, "127.0.0.1")
|
2013-12-04 19:12:09 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-04-10 20:20:50 +02:00
|
|
|
defer mock.Close()
|
2013-12-04 19:12:09 +01:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
c, err := Connect(mock.Addr())
|
2013-12-04 19:12:09 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
if err := c.Quit(); err != nil {
|
2015-08-21 18:47:44 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-04-10 20:20:50 +02:00
|
|
|
mock.Wait()
|
2015-08-21 18:47:44 +02:00
|
|
|
}
|
|
|
|
|
2015-08-21 18:36:56 +02:00
|
|
|
func TestTimeout(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping test in short mode.")
|
|
|
|
}
|
|
|
|
|
2020-10-21 22:10:46 +02:00
|
|
|
if c, err := DialTimeout("localhost:2121", 1*time.Second); err == nil {
|
2022-03-09 00:35:30 +01:00
|
|
|
_ = c.Quit()
|
2020-10-21 22:10:46 +02:00
|
|
|
t.Fatal("expected timeout, got nil error")
|
2015-08-21 18:36:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWrongLogin(t *testing.T) {
|
2019-04-10 20:20:50 +02:00
|
|
|
mock, err := newFtpMock(t, "127.0.0.1")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2015-08-21 18:36:56 +02:00
|
|
|
}
|
2019-04-10 20:20:50 +02:00
|
|
|
defer mock.Close()
|
2015-08-21 18:36:56 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
c, err := DialTimeout(mock.Addr(), 5*time.Second)
|
2015-08-21 18:36:56 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-03-09 00:35:30 +01:00
|
|
|
defer func() {
|
|
|
|
if err := c.Quit(); err != nil {
|
|
|
|
t.Errorf("can not quit: %s", err)
|
|
|
|
}
|
|
|
|
}()
|
2015-08-21 18:36:56 +02:00
|
|
|
|
|
|
|
err = c.Login("zoo2Shia", "fei5Yix9")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error, got nil")
|
|
|
|
}
|
|
|
|
}
|
2017-06-06 00:52:51 +02:00
|
|
|
|
|
|
|
func TestDeleteDirRecur(t *testing.T) {
|
2019-04-10 20:20:50 +02:00
|
|
|
mock, c := openConn(t, "127.0.0.1")
|
2017-06-06 00:52:51 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
err := c.RemoveDirRecur("testDir")
|
2017-06-06 00:52:51 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
if err := c.Quit(); err != nil {
|
2017-06-06 00:52:51 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
// Wait for the connection to close
|
|
|
|
mock.Wait()
|
|
|
|
}
|
2017-06-06 00:52:51 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
// func TestFileDeleteDirRecur(t *testing.T) {
|
|
|
|
// mock, c := openConn(t, "127.0.0.1")
|
2017-06-06 00:52:51 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
// err := c.RemoveDirRecur("testFile")
|
|
|
|
// if err == nil {
|
|
|
|
// t.Fatal("expected error got nil")
|
|
|
|
// }
|
2017-06-06 00:52:51 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
// if err := c.Quit(); err != nil {
|
|
|
|
// t.Fatal(err)
|
|
|
|
// }
|
2017-06-06 00:52:51 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
// // Wait for the connection to close
|
|
|
|
// mock.Wait()
|
|
|
|
// }
|
2017-06-06 00:52:51 +02:00
|
|
|
|
|
|
|
func TestMissingFolderDeleteDirRecur(t *testing.T) {
|
2019-04-10 20:20:50 +02:00
|
|
|
mock, c := openConn(t, "127.0.0.1")
|
2017-06-06 00:52:51 +02:00
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
err := c.RemoveDirRecur("missing-dir")
|
2017-06-06 00:52:51 +02:00
|
|
|
if err == nil {
|
2019-04-10 20:20:50 +02:00
|
|
|
t.Fatal("expected error got nil")
|
2017-06-06 00:52:51 +02:00
|
|
|
}
|
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
if err := c.Quit(); err != nil {
|
|
|
|
t.Fatal(err)
|
2017-06-06 00:52:51 +02:00
|
|
|
}
|
|
|
|
|
2019-04-10 20:20:50 +02:00
|
|
|
// Wait for the connection to close
|
|
|
|
mock.Wait()
|
2017-06-06 00:52:51 +02:00
|
|
|
}
|
2021-02-13 18:42:15 +01:00
|
|
|
|
|
|
|
func TestListCurrentDir(t *testing.T) {
|
2022-08-21 23:25:29 +02:00
|
|
|
mock, c := openConnExt(t, "127.0.0.1", "no-time", DialWithDisabledMLSD(true))
|
2021-02-13 18:42:15 +01:00
|
|
|
|
|
|
|
_, err := c.List("")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "LIST", mock.lastFull, "LIST must not have a trailing whitespace")
|
|
|
|
|
|
|
|
_, err = c.NameList("")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "NLST", mock.lastFull, "NLST must not have a trailing whitespace")
|
2022-09-04 20:43:06 +02:00
|
|
|
|
|
|
|
err = c.Quit()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
mock.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListCurrentDirWithForceListHidden(t *testing.T) {
|
|
|
|
mock, c := openConnExt(t, "127.0.0.1", "no-time", DialWithDisabledMLSD(true), DialWithForceListHidden(true))
|
|
|
|
|
|
|
|
assert.True(t, c.options.forceListHidden)
|
|
|
|
_, err := c.List("")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "LIST -a", mock.lastFull, "LIST -a must not have a trailing whitespace")
|
2021-02-13 18:42:15 +01:00
|
|
|
|
|
|
|
err = c.Quit()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
mock.Wait()
|
|
|
|
}
|
2021-05-08 15:20:49 +02:00
|
|
|
|
|
|
|
func TestTimeUnsupported(t *testing.T) {
|
|
|
|
mock, c := openConnExt(t, "127.0.0.1", "no-time")
|
|
|
|
|
|
|
|
assert.False(t, c.mdtmSupported, "MDTM must NOT be supported")
|
|
|
|
assert.False(t, c.mfmtSupported, "MFMT must NOT be supported")
|
|
|
|
|
|
|
|
assert.False(t, c.IsGetTimeSupported(), "GetTime must NOT be supported")
|
|
|
|
assert.False(t, c.IsSetTimeSupported(), "SetTime must NOT be supported")
|
|
|
|
|
|
|
|
_, err := c.GetTime("file1")
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
err = c.SetTime("file1", time.Now())
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
assert.NoError(t, c.Quit())
|
|
|
|
mock.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeStandard(t *testing.T) {
|
|
|
|
mock, c := openConnExt(t, "127.0.0.1", "std-time")
|
|
|
|
|
|
|
|
assert.True(t, c.mdtmSupported, "MDTM must be supported")
|
|
|
|
assert.True(t, c.mfmtSupported, "MFMT must be supported")
|
|
|
|
|
|
|
|
assert.True(t, c.IsGetTimeSupported(), "GetTime must be supported")
|
|
|
|
assert.True(t, c.IsSetTimeSupported(), "SetTime must be supported")
|
|
|
|
|
|
|
|
tm, err := c.GetTime("file1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, tm.IsZero(), "GetTime must return valid time")
|
|
|
|
|
|
|
|
err = c.SetTime("file1", time.Now())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.NoError(t, c.Quit())
|
|
|
|
mock.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeVsftpdPartial(t *testing.T) {
|
|
|
|
mock, c := openConnExt(t, "127.0.0.1", "vsftpd")
|
|
|
|
|
|
|
|
assert.True(t, c.mdtmSupported, "MDTM must be supported")
|
|
|
|
assert.False(t, c.mfmtSupported, "MFMT must NOT be supported")
|
|
|
|
|
|
|
|
assert.True(t, c.IsGetTimeSupported(), "GetTime must be supported")
|
|
|
|
assert.False(t, c.IsSetTimeSupported(), "SetTime must NOT be supported")
|
|
|
|
|
|
|
|
tm, err := c.GetTime("file1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, tm.IsZero(), "GetTime must return valid time")
|
|
|
|
|
|
|
|
err = c.SetTime("file1", time.Now())
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
assert.NoError(t, c.Quit())
|
|
|
|
mock.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimeVsftpdFull(t *testing.T) {
|
|
|
|
mock, c := openConnExt(t, "127.0.0.1", "vsftpd", DialWithWritingMDTM(true))
|
|
|
|
|
|
|
|
assert.True(t, c.mdtmSupported, "MDTM must be supported")
|
|
|
|
assert.False(t, c.mfmtSupported, "MFMT must NOT be supported")
|
|
|
|
|
|
|
|
assert.True(t, c.IsGetTimeSupported(), "GetTime must be supported")
|
|
|
|
assert.True(t, c.IsSetTimeSupported(), "SetTime must be supported")
|
|
|
|
|
|
|
|
tm, err := c.GetTime("file1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, tm.IsZero(), "GetTime must return valid time")
|
|
|
|
|
|
|
|
err = c.SetTime("file1", time.Now())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.NoError(t, c.Quit())
|
|
|
|
mock.Wait()
|
|
|
|
}
|
2022-03-09 01:06:48 +01:00
|
|
|
|
|
|
|
func TestDialWithDialFunc(t *testing.T) {
|
|
|
|
dialErr := fmt.Errorf("this is proof that dial function was called")
|
|
|
|
|
|
|
|
f := func(network, address string) (net.Conn, error) {
|
|
|
|
return nil, dialErr
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := Dial("bogus-address", DialWithDialFunc(f))
|
|
|
|
assert.Equal(t, dialErr, err)
|
|
|
|
}
|
2022-03-09 02:25:35 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|