Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fogfish committed May 12, 2024
1 parent 5c85345 commit 375ddc8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ func (fd *writer[T]) Close() error {
if fd.w != nil && fd.r != nil {
err := fd.w.Close()
fd.wg.Wait()

if fd.err != nil {
return fd.err
}

return err
}

Expand Down
28 changes: 28 additions & 0 deletions filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ var (
},
}

s3PutObjectError = mocks.PutObject{
Mock: mocks.Mock[manager.UploadOutput]{
ExpectKey: file[1:],
ReturnErr: errors.New("critical failure"),
},
}

s3ListObject = mocks.ListObject{
Mock: mocks.Mock[s3.ListObjectsV2Output]{
ExpectKey: dir[1:],
Expand Down Expand Up @@ -239,6 +246,7 @@ func TestReadWrite(t *testing.T) {

t.Run("File/Write", func(t *testing.T) {
s3fs, err := stream.NewFS("test",
stream.WithS3(s3PutObject),
stream.WithS3Upload(s3PutObject),
)
it.Then(t).Should(it.Nil(err))
Expand Down Expand Up @@ -296,6 +304,26 @@ func TestReadWrite(t *testing.T) {
)
})

t.Run("File/Write/Error", func(t *testing.T) {
s3fs, err := stream.NewFS("test",
stream.WithS3Upload(s3PutObjectError),
)
it.Then(t).Should(it.Nil(err))

fd, err := s3fs.Create(file, nil)
it.Then(t).Must(it.Nil(err))

n, err := io.WriteString(fd, content)
it.Then(t).Should(
it.Nil(err),
it.Equal(n, len(content)),
)

it.Then(t).Should(
it.Fail(fd.Close),
)
})

t.Run("File/Write/Error/InvalidPath", func(t *testing.T) {
s3fs, err := stream.NewFS("test",
stream.WithS3(s3GetObject),
Expand Down

0 comments on commit 375ddc8

Please sign in to comment.