Skip to content

Commit

Permalink
meta: linter fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jan 22, 2025
1 parent 3a9c727 commit 9887a74
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
48 changes: 29 additions & 19 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"testing"
"time"

go_ftp "github.com/moov-io/go-ftp"
mhttptest "github.com/moov-io/go-ftp/internal/httptest"

"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
)

func TestClient(t *testing.T) {
Expand Down Expand Up @@ -49,24 +49,34 @@ func TestClient(t *testing.T) {
largerFileSize := size(t, filepath.Join("testdata", "ftp-server", "bigdata", "large.txt"))

const iterations = 10
var wg sync.WaitGroup
wg.Add(iterations)
for i := 0; i < iterations; i++ {
go func(wg *sync.WaitGroup) {
defer wg.Done()

var g errgroup.Group
for i := 0; i < iterations; i++ {
g.Go(func() error {
file, err := client.Open("/bigdata/large.txt")
require.NoError(t, err)
if err != nil {
return err
}

var buf bytes.Buffer
_, err = io.Copy(&buf, file)
require.NoError(t, err)

require.NoError(t, file.Close())
require.Equal(t, largerFileSize, len(buf.Bytes()))
}(&wg)
if err != nil {
return err
}

err = file.Close()
if err != nil {
return err
}

read := len(buf.Bytes())
if read != largerFileSize {
return fmt.Errorf("read %d bytes, expected %d", read, largerFileSize)
}
return nil
})
}
wg.Wait()
require.NoError(t, g.Wait())
})

t.Run("reader", func(t *testing.T) {
Expand All @@ -92,7 +102,7 @@ func TestClient(t *testing.T) {
require.NoError(t, err)

require.NoError(t, file.Close())
require.Equal(t, largerFileSize, len(buf.Bytes()))
require.Len(t, buf.Bytes(), largerFileSize)
}
})

Expand Down Expand Up @@ -171,9 +181,9 @@ func TestClient(t *testing.T) {
} else {
file, err = client.Reader(filenames[i])
}
require.NoError(t, err, fmt.Sprintf("filenames[%d]", i))
require.NotNil(t, file, fmt.Sprintf("filenames[%d]", i))
require.NotNil(t, file.Contents, fmt.Sprintf("filenames[%d]", i))
require.NoError(t, err, "filenames[%d]", i)
require.NotNil(t, file, "filenames[%d]", i)
require.NotNil(t, file.Contents, "filenames[%d]", i)

bs, err := io.ReadAll(file.Contents)
require.NoError(t, err)
Expand Down Expand Up @@ -258,7 +268,7 @@ func TestClientErrors(t *testing.T) {
t.Run("list", func(t *testing.T) {
filenames, err := client.ListFiles("does/not/exist")
require.NoError(t, err)
require.Len(t, filenames, 0)
require.Empty(t, filenames)
})

t.Run("walk", func(t *testing.T) {
Expand All @@ -268,7 +278,7 @@ func TestClientErrors(t *testing.T) {
return nil
})
require.ErrorContains(t, err, "550 Directory change to /does/not/exist failed: lstat /data/does/not/exist: no such file or directory")
require.Len(t, found, 0)
require.Empty(t, found)
})

require.NoError(t, client.Close())
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/jlaffaye/ftp v0.2.0
github.com/stretchr/testify v1.10.0
golang.org/x/sync v0.10.0
)

require (
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ github.com/jlaffaye/ftp v0.2.0 h1:lXNvW7cBu7R/68bknOX3MrRIIqZ61zELs1P2RAiA3lg=
github.com/jlaffaye/ftp v0.2.0/go.mod h1:is2Ds5qkhceAPy2xD6RLI6hmp/qysSoymZ+Z2uTnspI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
4 changes: 2 additions & 2 deletions network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ func TestNetwork(t *testing.T) {

files, err := client.ListFiles("/")
require.NoError(t, err)
require.Greater(t, len(files), 0)
require.NotEmpty(t, files)

// close it again for fun
require.NoError(t, client.Close())

// try again
files, err = client.ListFiles("/")
require.NoError(t, err)
require.Greater(t, len(files), 0)
require.NotEmpty(t, files)
})
}

0 comments on commit 9887a74

Please sign in to comment.