Skip to content

Commit

Permalink
increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fogfish committed May 12, 2024
1 parent 1fc58c5 commit 5c85345
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ var (
},
}

s3HeadObjectNotFound = mocks.HeadObject{
Mock: mocks.Mock[s3.HeadObjectOutput]{
ExpectKey: file[1:],
},
}

s3HeadObjectError = mocks.HeadObject{
Mock: mocks.Mock[s3.HeadObjectOutput]{
ExpectKey: file[1:],
ReturnErr: errors.New("critical failure"),
},
}

s3GetObject = mocks.GetObject{
Mock: mocks.Mock[s3.GetObjectOutput]{
ExpectKey: file[1:],
Expand Down Expand Up @@ -505,6 +518,17 @@ func TestStat(t *testing.T) {
)
})

t.Run("Stat/Error", func(t *testing.T) {
s3fs, err := stream.NewFS("test",
stream.WithS3(s3HeadObjectError),
)
it.Then(t).Should(it.Nil(err))

it.Then(t).Should(
it.Error(s3fs.Stat(file)),
)
})

t.Run("Stat/Error/InvalidPath", func(t *testing.T) {
s3fs, err := stream.NewFS("test",
stream.WithS3(s3GetObject),
Expand All @@ -516,6 +540,18 @@ func TestStat(t *testing.T) {
)
})

t.Run("Stat/Error/NotFound", func(t *testing.T) {
s3fs, err := stream.NewFS("test",
stream.WithS3(s3HeadObjectNotFound),
)
it.Then(t).Should(it.Nil(err))

_, err = s3fs.Stat(file)
it.Then(t).Should(
it.True(errors.Is(err, fs.ErrNotExist)),
)
})

t.Run("File/Stat", func(t *testing.T) {
s3fs, err := stream.NewFS("test",
stream.WithS3(s3GetObject),
Expand Down
2 changes: 1 addition & 1 deletion internal/mocks/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (mock HeadObject) HeadObject(ctx context.Context, input *s3.HeadObjectInput
}

if mock.ReturnVal == nil {
return nil, &types.NoSuchKey{}
return nil, &types.NotFound{}
}

return mock.ReturnVal, nil
Expand Down

0 comments on commit 5c85345

Please sign in to comment.