Skip to content

Commit 60c43da

Browse files
committed
ftp: Replace fakeDataConn with mockery
1 parent 97c7a37 commit 60c43da

9 files changed

Lines changed: 264 additions & 368 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Use context from `testing.T` introduced in Go 1.24.
1515
- Define more sentinel errors for more ergonomic error checking.
1616
- Use typed expectations consistently for added type safety.
17+
- Remove `fakeDataConn` mock and switch to mockery.
1718
### Fixed
1819
- Use walrus assignment where possible.
1920
- Use the `any` keyword where possible.

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,11 @@ 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-
s.ftpFile.Location().FileSystem().(*FileSystem).dataconn = fakedconn
236+
fakedconn.EXPECT().Close().Return(closeErr).Once()
237+
s.ftpFile.location.fileSystem.dataconn = fakedconn
237238
dc, err := getDataConn(
238239
s.T().Context(),
239240
authority.Authority{},

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().(*FileSystem).resetConn = true
313+
f.Location().FileSystem().(*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().(*FileSystem).resetConn = true
375+
f.Location().FileSystem().(*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().(*FileSystem).resetConn = true
396+
f.Location().FileSystem().(*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)