From c5fcd67e3d904b723a2ec52f0054f03186a19674 Mon Sep 17 00:00:00 2001 From: Chris Cotter Date: Sat, 25 Jan 2020 16:38:43 -0500 Subject: [PATCH] storage: don't drop port in endpoint If the user creates a client with a custom endpoint, we should retain the port for readhost. Fixes #1737 Change-Id: Ic0cf928ae99fe115e1eebce46c3965044d682db4 Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/50891 Reviewed-by: kokoro Reviewed-by: Tyler Bui-Palsulich --- storage/storage.go | 2 +- storage/storage_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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) }