Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package storage
import (
"context"
"errors"
"os"

"cloud.google.com/go/storage"
"firebase.google.com/go/v4/internal"
Expand All @@ -34,6 +35,9 @@ type Client struct {
// This function can only be invoked from within the SDK. Client applications should access the
// the Storage service through firebase.App.
func NewClient(ctx context.Context, c *internal.StorageConfig) (*Client, error) {
if os.Getenv("STORAGE_EMULATOR_HOST") == "" && os.Getenv("FIREBASE_STORAGE_EMULATOR_HOST") != "" {
os.Setenv("STORAGE_EMULATOR_HOST", os.Getenv("FIREBASE_STORAGE_EMULATOR_HOST"))
}
client, err := storage.NewClient(ctx, c.Opts...)
if err != nil {
return nil, err
Expand Down
20 changes: 20 additions & 0 deletions storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package storage

import (
"context"
"os"
"testing"

"firebase.google.com/go/v4/internal"
Expand All @@ -38,6 +39,25 @@ func TestNewClientError(t *testing.T) {
}
}

func TestNewClientEmulatorHostEnvVar(t *testing.T) {
emulatorHost := "localhost:9099"
os.Setenv("FIREBASE_STORAGE_EMULATOR_HOST", emulatorHost)
defer os.Unsetenv("FIREBASE_STORAGE_EMULATOR_HOST")
os.Unsetenv("STORAGE_EMULATOR_HOST")
defer os.Unsetenv("STORAGE_EMULATOR_HOST")

_, err := NewClient(context.Background(), &internal.StorageConfig{
Opts: opts,
})
if err != nil {
t.Fatal(err)
}

if host := os.Getenv("STORAGE_EMULATOR_HOST"); host != emulatorHost {
t.Errorf("emulator host: %q; want: %q", host, emulatorHost)
}
}

func TestNoBucketName(t *testing.T) {
client, err := NewClient(context.Background(), &internal.StorageConfig{
Opts: opts,
Expand Down