Commit 48a4b33a authored by Martin Sefcik's avatar Martin Sefcik

Url encoding fix

parent d5898459
...@@ -196,13 +196,11 @@ func (c *Client) SetBaseURL(urlStr string) error { ...@@ -196,13 +196,11 @@ func (c *Client) SetBaseURL(urlStr string) error {
// specified, the value pointed to by body is JSON encoded and included as the // specified, the value pointed to by body is JSON encoded and included as the
// request body. // request body.
func (c *Client) NewRequest(method, path string, opt interface{}) (*http.Request, error) { func (c *Client) NewRequest(method, path string, opt interface{}) (*http.Request, error) {
rel, err := url.Parse(path) u, err := url.Parse(c.baseURL.String() + path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
u := *c.baseURL.ResolveReference(rel)
q, err := query.Values(opt) q, err := query.Values(opt)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -211,7 +209,7 @@ func (c *Client) NewRequest(method, path string, opt interface{}) (*http.Request ...@@ -211,7 +209,7 @@ func (c *Client) NewRequest(method, path string, opt interface{}) (*http.Request
req := &http.Request{ req := &http.Request{
Method: method, Method: method,
URL: &u, URL: u,
Proto: "HTTP/1.1", Proto: "HTTP/1.1",
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 1, ProtoMinor: 1,
......
...@@ -32,6 +32,12 @@ func teardown(server *httptest.Server) { ...@@ -32,6 +32,12 @@ func teardown(server *httptest.Server) {
server.Close() server.Close()
} }
func testUrl(t *testing.T, r *http.Request, want string) {
if got := r.URL.String(); got != want {
t.Errorf("Request url: %s, want %s", got, want)
}
}
func testMethod(t *testing.T, r *http.Request, want string) { func testMethod(t *testing.T, r *http.Request, want string) {
if got := r.Method; got != want { if got := r.Method; got != want {
t.Errorf("Request method: %v, want %v", got, want) t.Errorf("Request method: %v, want %v", got, want)
......
...@@ -100,7 +100,7 @@ func TestListAllProjects(t *testing.T) { ...@@ -100,7 +100,7 @@ func TestListAllProjects(t *testing.T) {
} }
} }
func TestGetProject(t *testing.T) { func TestGetProject_byID(t *testing.T) {
mux, server, client := setup() mux, server, client := setup()
defer teardown(server) defer teardown(server)
...@@ -121,6 +121,28 @@ func TestGetProject(t *testing.T) { ...@@ -121,6 +121,28 @@ func TestGetProject(t *testing.T) {
} }
} }
func TestGetProject_byName(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/", func(w http.ResponseWriter, r *http.Request) {
testUrl(t, r, "/projects/namespace%2Fname")
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1}`)
})
want := &Project{ID: Int(1)}
project, _, err := client.Projects.GetProject("namespace/name")
if err != nil {
t.Fatalf("Projects.GetProject returns an error: %v", err)
}
if !reflect.DeepEqual(want, project) {
t.Errorf("Projects.GetProject returned %+v, want %+v", project, want)
}
}
func TestSearchProjects(t *testing.T) { func TestSearchProjects(t *testing.T) {
mux, server, client := setup() mux, server, client := setup()
defer teardown(server) defer teardown(server)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment