Skip to content

Commit

Permalink
fix(remove): added more tests for remove operation
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfeidau committed Jan 17, 2024
1 parent cdb8524 commit 317baea
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
54 changes: 45 additions & 9 deletions integration/s3fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func TestSeek(t *testing.T) {
s3fs := s3iofs.NewWithClient(testBucketName, client)

t.Run("seek to start", func(t *testing.T) {
assert := require.New(t)

f, err := s3fs.Open("test_seek.txt")
assert.NoError(err)

Expand All @@ -112,6 +114,8 @@ func TestSeek(t *testing.T) {
})

t.Run("seek to end", func(t *testing.T) {
assert := require.New(t)

f, err := s3fs.Open("test_seek.txt")
assert.NoError(err)
defer f.Close()
Expand All @@ -124,6 +128,8 @@ func TestSeek(t *testing.T) {
})

t.Run("seek to current", func(t *testing.T) {
assert := require.New(t)

f, err := s3fs.Open("test_seek.txt")
assert.NoError(err)
defer f.Close()
Expand Down Expand Up @@ -239,17 +245,47 @@ func TestReadBigEOF(t *testing.T) {
}

func TestRemove(t *testing.T) {
assert := require.New(t)

_, err := client.PutObject(context.Background(), &s3.PutObjectInput{
Bucket: aws.String(testBucketName),
Key: aws.String("test_remove.txt"),
Body: bytes.NewReader(generateData(oneMegabyte)),
t.Run("create and remove", func(t *testing.T) {
assert := require.New(t)

_, err := client.PutObject(context.Background(), &s3.PutObjectInput{
Bucket: aws.String(testBucketName),
Key: aws.String("test_remove.txt"),
Body: bytes.NewReader(generateData(oneMegabyte)),
})
assert.NoError(err)

s3fs := s3iofs.NewWithClient(testBucketName, client)

err = s3fs.Remove("test_remove.txt")
assert.NoError(err)
})
assert.NoError(err)

s3fs := s3iofs.NewWithClient(testBucketName, client)
t.Run("removing non existent file should not error", func(t *testing.T) {
assert := require.New(t)

err = s3fs.Remove("test_remove.txt")
assert.NoError(err)
s3fs := s3iofs.NewWithClient(testBucketName, client)

err := s3fs.Remove("test_remove_not_exists.txt")
assert.NoError(err)
})

t.Run("bad bucket name should error", func(t *testing.T) {
assert := require.New(t)

s3fs := s3iofs.NewWithClient("badbucket", client)

err := s3fs.Remove("test_remove_not_exists.txt")
assert.Error(err)
})

t.Run("invalid name should error", func(t *testing.T) {
assert := require.New(t)

s3fs := s3iofs.NewWithClient(testBucketName, client)

err := s3fs.Remove("")
assert.Error(err)
})
}
6 changes: 0 additions & 6 deletions s3iofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ func (s3fs *S3FS) Remove(name string) error {
Key: aws.String(name),
})
if err != nil {
var nfe *types.NotFound
if errors.As(err, &nfe) {
// deleting a file which doesn't exist is not an error
return nil
}

return &fs.PathError{Op: "remove", Path: name, Err: err}
}

Expand Down

0 comments on commit 317baea

Please sign in to comment.