From 375ddc85bda7665dd93b134fb77fb5922307c4c6 Mon Sep 17 00:00:00 2001 From: Dmitry Kolesnikov Date: Sun, 12 May 2024 23:40:38 +0300 Subject: [PATCH] improve coverage --- file.go | 5 +++++ filesystem_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/file.go b/file.go index 3f4bf5d..6fa5d0d 100644 --- a/file.go +++ b/file.go @@ -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 } diff --git a/filesystem_test.go b/filesystem_test.go index dc4cb80..7d895fa 100644 --- a/filesystem_test.go +++ b/filesystem_test.go @@ -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:], @@ -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)) @@ -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),