Skip to content

Commit

Permalink
Add adjusts to command helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Oct 17, 2023
1 parent 031f9fd commit 2e710c7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tsuru/client/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ type AppUpdate struct {
func (c *AppUpdate) Info() *cmd.Info {
return &cmd.Info{
Name: "app-update",
Usage: "app update [-a/--app appname] [--description/-d description] [--plan/-p plan name] [--pool/-o pool] [--team-owner/-t team owner] [--platform/-l platform] [-i/--image-reset] [--cpu cpu] [--memory memory] [--tag/-g tag]...",
Usage: "app update [-a/--app appname] [--description/-d description] [--plan/-p plan name] [--pool/-o pool] [--team-owner/-t team owner] [--platform/-l platform] [-i/--image-reset] [--cpu cpu] [--memory memory] [--cpu-burst-factor cpu-burst-factor] [--tag/-g tag]...",
Desc: `Updates an app, changing its description, tags, plan or pool information.`,
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ func (c *AppUpdate) Flags() *gnuflag.FlagSet {
flagSet.Var((*cmd.StringSliceFlag)(&c.args.Tags), "g", tagMessage)
flagSet.Var((*cmd.StringSliceFlag)(&c.args.Tags), "tag", tagMessage)
flagSet.StringVar(&c.cpu, "cpu", "", "CPU limit for app, this will override the plan cpu value. One cpu is equivalent to 1 vCPU/Core, fractional requests are allowed and the expression 0.1 is equivalent to the expression 100m")
flagSet.StringVar(&c.cpuBurst, "cpu-burst-factor", "", "The multiplier to determine the limits of CPU burst, when the value is 1 not set burst")
flagSet.StringVar(&c.cpuBurst, "cpu-burst-factor", "", "The multiplier to determine the limits of the CPU burst. Setting 1 disables burst")

flagSet.StringVar(&c.memory, "memory", "", "Memory limit for app, this will override the plan memory value. You can express memory as a bytes integer or using one of these suffixes: E, P, T, G, M, K, Ei, Pi, Ti, Gi, Mi, Ki")
c.fs = cmd.MergeFlagSet(
Expand Down
33 changes: 33 additions & 0 deletions tsuru/client/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,39 @@ func (s *S) TestAppUpdateWithCPUBurst(c *check.C) {
c.Assert(stdout.String(), check.Equals, expected)
}

func (s *S) TestAppUpdateWithInvalidCPUBurst(c *check.C) {
var stdout, stderr bytes.Buffer
context := cmd.Context{
Stdout: &stdout,
Stderr: &stderr,
}
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
url := strings.HasSuffix(req.URL.Path, "/apps/ble")
method := req.Method == "PUT"
data, err := io.ReadAll(req.Body)
c.Assert(err, check.IsNil)
var result map[string]interface{}
err = json.Unmarshal(data, &result)
c.Assert(err, check.IsNil)
c.Assert(result, check.DeepEquals, map[string]interface{}{
"planoverride": map[string]interface{}{
"cpuBurst": float64(1.3),
},
"metadata": map[string]interface{}{},
})
return url && method
},
}
client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
command := AppUpdate{}
command.Flags().Parse(true, []string{"-a", "ble", "--cpu-burst-factor", "0.5"})
err := command.Run(&context, client)
c.Assert(err, check.NotNil)
c.Assert(err.Error(), check.Equals, "Invalid factor, please use a value greater equal 1")
}

func (s *S) TestAppUpdateWithoutArgs(c *check.C) {
var stdout, stderr bytes.Buffer
expected := "Please use the -a/--app flag to specify which app you want to update."
Expand Down
2 changes: 1 addition & 1 deletion tsuru/client/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *PlanList) Flags() *gnuflag.FlagSet {
func (c *PlanList) Info() *cmd.Info {
return &cmd.Info{
Name: "plan-list",
Usage: "plan list [--bytes][--kubernetes-friendly]",
Usage: "plan list [--bytes][--kubernetes-friendly][--show-max-cpu-burst-allowed]",
Desc: "List available plans that can be used when creating an app.",
MinArgs: 0,
}
Expand Down

0 comments on commit 2e710c7

Please sign in to comment.