Skip to content

Commit

Permalink
Modify fake bucket implementation to throw same error that is thrown …
Browse files Browse the repository at this point in the history
…by GCS Bucket. (#2707)
  • Loading branch information
vipnydav authored Nov 25, 2024
1 parent 17414f3 commit 833a760
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 2 additions & 5 deletions internal/storage/fake/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"time"
"unicode/utf8"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/gcs"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/storageutil"
"github.com/jacobsa/syncutil"
Expand Down Expand Up @@ -452,11 +453,7 @@ func (b *bucket) newReaderLocked(

// Does the generation match?
if req.Generation != 0 && req.Generation != o.metadata.Generation {
err = &gcs.NotFoundError{
Err: fmt.Errorf(
"object %s generation %v not found", req.Name, req.Generation),
}

err = storage.ErrObjectNotExist
return
}

Expand Down
11 changes: 6 additions & 5 deletions internal/storage/fake/testing/bucket_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"time"
"unicode"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/gcs"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/storageutil"
. "github.com/jacobsa/oglematchers"
Expand Down Expand Up @@ -2230,7 +2231,7 @@ func (t *composeTest) ExplicitGenerations_OneDoesntExist() {
},
})

ExpectThat(err, HasSameTypeAs(&gcs.NotFoundError{}))
ExpectThat(err, HasSameTypeAs(storage.ErrObjectNotExist))

// Make sure the destination object doesn't exist.
_, _, err = t.bucket.StatObject(
Expand Down Expand Up @@ -2753,8 +2754,8 @@ func (t *readTest) ParticularGeneration_NeverExisted() {
_, err = rc.Read(make([]byte, 1))
}

AssertThat(err, HasSameTypeAs(&gcs.NotFoundError{}))
ExpectThat(err, Error(MatchesRegexp("(?i)not found|404")))
AssertThat(err, HasSameTypeAs(storage.ErrObjectNotExist))
ExpectThat(err, Error(MatchesRegexp("(?i)object doesn't exist")))
}

func (t *readTest) ParticularGeneration_HasBeenDeleted() {
Expand Down Expand Up @@ -2855,8 +2856,8 @@ func (t *readTest) ParticularGeneration_ObjectHasBeenOverwritten() {
_, err = rc.Read(make([]byte, 1))
}

AssertThat(err, HasSameTypeAs(&gcs.NotFoundError{}))
ExpectThat(err, Error(MatchesRegexp("(?i)not found|404")))
AssertThat(err, HasSameTypeAs(storage.ErrObjectNotExist))
ExpectThat(err, Error(MatchesRegexp("(?i)object doesn't exist")))

// Reading by the new generation should work.
req.Generation = o2.Generation
Expand Down

0 comments on commit 833a760

Please sign in to comment.