Skip to content

Commit

Permalink
services: send data as x-www-form-urlencoded in service instance bind.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnsaoki2 committed Jun 3, 2016
1 parent d01e83f commit 34721db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 6 additions & 3 deletions tsuru/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
"net/url"
"sort"
"strconv"
"strings"

"github.com/tsuru/gnuflag"
Expand Down Expand Up @@ -188,15 +189,17 @@ func (sb *serviceInstanceBind) Run(ctx *cmd.Context, client *cmd.Client) error {
}
serviceName := ctx.Args[0]
instanceName := ctx.Args[1]
url, err := cmd.GetURL("/services/" + serviceName + "/instances/" + instanceName + "/" + appName)
u, err := cmd.GetURL("/services/" + serviceName + "/instances/" + instanceName + "/" + appName)
if err != nil {
return err
}
url += fmt.Sprintf("?noRestart=%t", sb.noRestart)
request, err := http.NewRequest("PUT", url, nil)
v := url.Values{}
v.Set("noRestart", strconv.FormatBool(sb.noRestart))
request, err := http.NewRequest("PUT", u, strings.NewReader(v.Encode()))
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(request)
if err != nil {
return err
Expand Down
18 changes: 12 additions & 6 deletions tsuru/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ func (s *S) TestServiceBind(c *check.C) {
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
called = true
return req.Method == "PUT" && strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/g1") &&
req.URL.RawQuery == "noRestart=true"
method := req.Method == "PUT"
path := strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/g1")
noRestart := req.FormValue("noRestart") == "true"
return method && path && noRestart
},
}
client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
Expand Down Expand Up @@ -189,8 +191,10 @@ func (s *S) TestServiceBindWithoutFlag(c *check.C) {
},
CondFunc: func(req *http.Request) bool {
called = true
return req.Method == "PUT" && strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/ge") &&
req.URL.RawQuery == "noRestart=false"
method := req.Method == "PUT"
path := strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/ge")
noRestart := req.FormValue("noRestart") == "false"
return method && path && noRestart
},
}
client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
Expand All @@ -215,8 +219,10 @@ func (s *S) TestServiceBindWithoutEnvironmentVariables(c *check.C) {
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
return req.Method == "PUT" && strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/g1") &&
req.URL.RawQuery == "noRestart=false"
method := req.Method == "PUT"
path := strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/g1")
noRestart := req.FormValue("noRestart") == "false"
return method && path && noRestart
},
}
client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
Expand Down

0 comments on commit 34721db

Please sign in to comment.