diff --git a/storage/storage.go b/storage/storage.go index 763626747650..c0bf509dae05 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -128,7 +128,7 @@ func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error if err != nil { return nil, fmt.Errorf("supplied endpoint %v is not valid: %v", ep, err) } - readHost = u.Hostname() + readHost = u.Host } return &Client{ diff --git a/storage/storage_test.go b/storage/storage_test.go index fdfda9e1577d..38abb130c94e 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -1148,7 +1148,7 @@ func TestAttrToFieldMapCoverage(t *testing.T) { // for writes) and readHost (used for reads) are both set correctly. func TestWithEndpoint(t *testing.T) { ctx := context.Background() - endpoint := "https://fake.gcs.com/storage/v1" + endpoint := "https://fake.gcs.com:8080/storage/v1" c, err := NewClient(ctx, option.WithEndpoint(endpoint)) if err != nil { t.Fatalf("error creating client: %v", err) @@ -1158,7 +1158,7 @@ func TestWithEndpoint(t *testing.T) { t.Errorf("raw.BasePath not set correctly: got %v, want %v", c.raw.BasePath, endpoint) } - want := "fake.gcs.com" + want := "fake.gcs.com:8080" if c.readHost != want { t.Errorf("readHost not set correctly: got %v, want %v", c.readHost, want) }