Skip to content

Commit

Permalink
storage: don't drop port in endpoint
Browse files Browse the repository at this point in the history
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 <noreply+kokoro@google.com>
Reviewed-by: Tyler Bui-Palsulich <tbp@google.com>
  • Loading branch information
tritone committed Jan 27, 2020
1 parent e48feef commit c5fcd67
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit c5fcd67

Please sign in to comment.