Skip to content

Commit

Permalink
Support opaque and query in archiver URI (uber#2630)
Browse files Browse the repository at this point in the history
  • Loading branch information
yycptt authored Oct 5, 2019
1 parent 9ac2bf1 commit ef14cb2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
14 changes: 10 additions & 4 deletions common/archiver/URI.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package archiver

import (
"errors"
"net/url"
)

Expand All @@ -35,6 +34,8 @@ type (
Username() string
Password() string
String() string
Opaque() string
Query() map[string][]string
}

uri struct {
Expand All @@ -48,9 +49,6 @@ func NewURI(s string) (URI, error) {
if err != nil {
return nil, err
}
if url.Opaque != "" {
return nil, errors.New("URI should begin with scheme://")
}
return &uri{url: url}, nil
}

Expand Down Expand Up @@ -88,6 +86,14 @@ func (u *uri) Password() string {
return password
}

func (u *uri) Opaque() string {
return u.url.Opaque
}

func (u *uri) Query() map[string][]string {
return u.url.Query()
}

func (u *uri) String() string {
return u.url.String()
}
26 changes: 24 additions & 2 deletions common/archiver/URI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func (s *URISuite) TestURI() {
port string
username string
password string
opaque string
query map[string][]string
}{
{
URIString: "",
Expand All @@ -63,7 +65,9 @@ func (s *URISuite) TestURI() {
},
{
URIString: "mailto:a@b.com",
valid: false,
valid: true,
scheme: "mailto",
opaque: "a@b.com",
},
{
URIString: "test://",
Expand All @@ -85,11 +89,15 @@ func (s *URISuite) TestURI() {
path: "/path with space",
},
{
URIString: "https://localhost:8080",
URIString: "https://localhost:8080?key1=value1&key1=value2&key2=value3",
valid: true,
scheme: "https",
hostname: "localhost",
port: "8080",
query: map[string][]string{
"key1": []string{"value1", "value2"},
"key2": []string{"value3"},
},
},
{
URIString: "file:///absolute/path/to/dir",
Expand All @@ -106,6 +114,16 @@ func (s *URISuite) TestURI() {
username: "person",
password: "password",
},
{
URIString: "test:opaque?key1=value1&key1=value2&key2=value3",
valid: true,
scheme: "test",
opaque: "opaque",
query: map[string][]string{
"key1": []string{"value1", "value2"},
"key2": []string{"value3"},
},
},
}

for _, tc := range testCases {
Expand All @@ -122,5 +140,9 @@ func (s *URISuite) TestURI() {
s.Equal(tc.port, URI.Port())
s.Equal(tc.username, URI.Username())
s.Equal(tc.password, URI.Password())
s.Equal(tc.opaque, URI.Opaque())
if tc.query != nil {
s.Equal(tc.query, URI.Query())
}
}
}

0 comments on commit ef14cb2

Please sign in to comment.