Skip to content

Commit 297440b

Browse files
committed
ftp: Replace fakeDataConn with mockery
1 parent 745af85 commit 297440b

File tree

9 files changed

+265
-406
lines changed

9 files changed

+265
-406
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
- Replace ftp `fakeDataConn` type with mockery.
89

910
## [v7.13.0] - 2025-01-26
1011
### Added

backend/ftp/dataconn.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func getDataConn(ctx context.Context, a authority.Authority, fs *FileSystem, f *
147147
fs.dataconn = nil
148148
}
149149

150-
if fs.dataconn == nil || fs.resetConn {
150+
if fs.dataconn == nil {
151151
client, err := fs.Client(ctx, a)
152152
if err != nil {
153153
return nil, err
@@ -176,10 +176,6 @@ func getDataConn(ctx context.Context, a authority.Authority, fs *FileSystem, f *
176176
c: client,
177177
}
178178
}
179-
// ensure resetConn is false since we've opened/reopened the file
180-
if f != nil {
181-
fs.resetConn = false
182-
}
183179
}
184180

185181
return fs.dataconn, nil

backend/ftp/dataconn_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ func (s *dataConnSuite) TestGetDataConn_writeSuccess() {
230230

231231
func (s *dataConnSuite) TestGetDataConn_readAfterWriteError() {
232232
// open dataconn for read after dataconn for write exists - error on dataconn.Close
233-
fakedconn := NewFakeDataConn(types.OpenWrite)
233+
fakedconn := mocks.NewDataConn(s.T())
234+
fakedconn.EXPECT().Mode().Return(types.OpenWrite)
234235
closeErr := errors.New("some close err")
235-
fakedconn.AssertCloseErr(closeErr)
236+
fakedconn.EXPECT().Close().Return(closeErr).Once()
236237
s.ftpFile.location.fileSystem.dataconn = fakedconn
237238
dc, err := getDataConn(
238239
s.T().Context(),

backend/ftp/file.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (f *File) Close() error {
310310
if err != nil {
311311
return utils.WrapCloseError(err)
312312
}
313-
f.location.fileSystem.resetConn = true
313+
f.location.fileSystem.dataconn = nil
314314
}
315315
// no op for unopened file
316316
f.offset = 0
@@ -372,7 +372,7 @@ func (f *File) Seek(offset int64, whence int) (int64, error) {
372372
if err != nil {
373373
return 0, utils.WrapSeekError(err)
374374
}
375-
f.location.fileSystem.resetConn = true
375+
f.location.fileSystem.dataconn = nil
376376
case 2: // offset from end of the file
377377
sz, err := f.Size()
378378
if err != nil {
@@ -393,7 +393,7 @@ func (f *File) Seek(offset int64, whence int) (int64, error) {
393393
if err != nil {
394394
return 0, utils.WrapSeekError(err)
395395
}
396-
f.location.fileSystem.resetConn = true
396+
f.location.fileSystem.dataconn = nil
397397
}
398398
}
399399

backend/ftp/fileSystem.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type FileSystem struct {
3030
options Options
3131
ftpclient types.Client
3232
dataconn types.DataConn
33-
resetConn bool
3433
}
3534

3635
// NewFileSystem initializer for fileSystem struct.

0 commit comments

Comments
 (0)