Listing a Google Cloud Storage bucket does not return things in the root of the bucket.
aucampia opened this issue · comments
If I use Location.List()
(this) on a google cloud storage location which is just a bucket with files directly in the bucket and not in any "folder" it does not find anything.
pseudocode:
gsLocation, _ := vfssimple.NewLocation("gs://bucket/")
list, _ := gsLocation.List()
# list will be empty if all objects in the bucket is directly in the root without any folders.
The problem is, as far as I can tell, that the query prefix in this case is /
, while files directly in a bucket has no prefix.
Making this change fixes it:
$ git diff vendor/
diff --git a/suggestions-go/vendor/github.com/c2fo/vfs/v5/backend/gs/location.go b/suggestions-go/vendor/github.com/c2fo/vfs/v5/backend/gs/location.go
index 7a0abca..5354ab0 100644
--- a/suggestions-go/vendor/github.com/c2fo/vfs/v5/backend/gs/location.go
+++ b/suggestions-go/vendor/github.com/c2fo/vfs/v5/backend/gs/location.go
@@ -38,6 +38,9 @@ func (l *Location) ListByPrefix(filenamePrefix string) ([]string, error) {
if filenamePrefix == "" {
prefix = utils.EnsureTrailingSlash(prefix)
}
+ if prefix == "/" {
+ prefix = ""
+ }
d := path.Dir(prefix)
q := &storage.Query{
Delimiter: "/",
There are two options to test this:
- use stiface and mocks: https://pkg.go.dev/github.com/googleapis/google-cloud-go-testing/storage/stiface
- use a mock server, e.g: fake-gcs-server https://github.com/fsouza/fake-gcs-server
Not sure which you would favour, I think both has it's merits and best would be to test with both of these options.