Skip to content

Commit

Permalink
client: adds test case and exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur authored and andrestc committed Jun 29, 2017
1 parent 2681de3 commit 91b0afa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tsuru/client/apps.go
Expand Up @@ -150,8 +150,13 @@ func (c *AppCreate) Flags() *gnuflag.FlagSet {
}

func (c *AppCreate) Run(context *cmd.Context, client *cmd.Client) error {
var platform string
appName := context.Args[0]
platform := context.Args[1]
if len(context.Args) > 1 {
platform = context.Args[1]
} else {
platform = ""
}
v, err := form.EncodeToValues(map[string]interface{}{"routeropts": c.routerOpts})
if err != nil {
return err
Expand Down
36 changes: 36 additions & 0 deletions tsuru/client/apps_test.go
Expand Up @@ -68,6 +68,42 @@ Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` +
c.Assert(stdout.String(), check.Equals, expected)
}

func (s *S) TestAppCreateEmptyPlatform(c *check.C) {
var stdout, stderr bytes.Buffer
result := `{"status":"success", "repository_url":"git@tsuru.plataformas.glb.com:ble.git"}`
expected := `App "ble" has been created!
Use app-info to check the status of the app and its units.
Your repository for "ble" project is "git@tsuru.plataformas.glb.com:ble.git"` + "\n"
context := cmd.Context{
Args: []string{"ble"},
Stdout: &stdout,
Stderr: &stderr,
}
trans := cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: result, Status: http.StatusOK},
CondFunc: func(r *http.Request) bool {
name := r.FormValue("name") == "ble"
platform := r.FormValue("platform") == ""
teamOwner := r.FormValue("teamOwner") == ""
plan := r.FormValue("plan") == ""
pool := r.FormValue("pool") == ""
description := r.FormValue("description") == ""
r.ParseForm()
tags := r.Form["tag"] == nil
router := r.FormValue("router") == ""
method := r.Method == "POST"
contentType := r.Header.Get("Content-Type") == "application/x-www-form-urlencoded"
url := strings.HasSuffix(r.URL.Path, "/apps")
return method && url && name && platform && teamOwner && plan && pool && description && tags && contentType && router
},
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := AppCreate{}
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
}

func (s *S) TestAppCreateTeamOwner(c *check.C) {
var stdout, stderr bytes.Buffer
result := `{"status":"success", "repository_url":"git@tsuru.plataformas.glb.com:ble.git"}`
Expand Down

0 comments on commit 91b0afa

Please sign in to comment.