Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage List behaviour does not match real GS bucket. #5129

Closed
emcfarlane opened this issue Oct 15, 2022 · 1 comment
Closed

Storage List behaviour does not match real GS bucket. #5129

emcfarlane opened this issue Oct 15, 2022 · 1 comment

Comments

@emcfarlane
Copy link

[REQUIRED] Environment info

11.14.4

macOS

cloud.google.com/go/firestore v1.7.0
cloud.google.com/go/storage v1.27.0

[REQUIRED] Test case

package main

import (
	"context"
	"fmt"
	"os"

	"cloud.google.com/go/storage"
	firebase "firebase.google.com/go"
	"google.golang.org/api/iterator"
)

func init() {
	os.Setenv("FIRESTORE_EMULATOR_HOST", "localhost:8080")
	os.Setenv("FIREBASE_STORAGE_EMULATOR_HOST", "localhost:9199")
	os.Setenv("STORAGE_EMULATOR_HOST", "localhost:9199")
}

func check(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	ctx := context.Background()
	app, err := firebase.NewApp(ctx, nil)
	check(err)

	st, err := app.Storage(ctx)
	check(err)
	bkt, err := st.DefaultBucket()
	check(err)

	w := bkt.Object("some/object.txt").NewWriter(ctx)
	check(err)
	_, err = fmt.Fprintf(w, "This object contains text.\n")
	check(err)
	check(w.Close())

	it := bkt.Objects(ctx, &storage.Query{
		Delimiter: "/",
		Prefix:    "some/",
	})
	for {
		attrs, err := it.Next()
		if err != nil {
			if err == iterator.Done {
				break
			}
			check(err)
		}
		fmt.Println(attrs.Name)
	}
}

[REQUIRED] Steps to reproduce

Run the code above with accesse to a real cloud storage bucket, and then the storage emulator.

[REQUIRED] Expected behavior

Expect output to be:

some/object.txt

[REQUIRED] Actual behavior

panic: bucket name not specified

goroutine 1 [running]:
main.check(...)
        /Users/edward/src/github.com/emcfarlane/mems/main.go:21
main.main()
        /Users/edward/src/github.com/emcfarlane/mems/main.go:33 +0x31b
exit status 2

Also "FIREBASE_STORAGE_EMULATOR_HOST" should control the firebase bucket. But it looks like it is ignored.

@abhis3
Copy link
Contributor

abhis3 commented Nov 7, 2022

Hi there,

I believe this should have been fixed with the merge of #5209. Please try again once we cut a new version of the emulator, or download the latest version straight from Github if you need it sooner.

Be aware there is another small issue in our GO SDK, that I've documented and provided a workaround for here: https://stackoverflow.com/a/74322070/20420645

If both of the above don't fix your issue, please feel free to reopen.

@abhis3 abhis3 closed this as completed Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants