diff --git a/tsuru/client/plan.go b/tsuru/client/plan.go index 6bcfd0d4..f6d6b167 100644 --- a/tsuru/client/plan.go +++ b/tsuru/client/plan.go @@ -84,7 +84,9 @@ func renderPlans(plans []apptypes.Plan, opts renderPlansOpts) string { memory = resource.NewQuantity(p.Memory, resource.BinarySI).String() } + cpuMilli := p.CPUMilli if p.Override.CPUMilli != nil { + cpuMilli = *p.Override.CPUMilli cpu = fmt.Sprintf("%g", float64(*p.Override.CPUMilli)/10) + "% (override)" } else if p.CPUMilli > 0 { cpu = fmt.Sprintf("%g", float64(p.CPUMilli)/10) + "%" @@ -108,11 +110,11 @@ func renderPlans(plans []apptypes.Plan, opts renderPlansOpts) string { cpuBurstObservation = " (override)" } - row = append(row, displayCPUBurst(p.CPUMilli, cpuBurst)+cpuBurstObservation) + row = append(row, displayCPUBurst(cpuMilli, cpuBurst)+cpuBurstObservation) } if showBurstColumn && opts.showMaxBurstAllowed { - row = append(row, displayCPUBurst(p.CPUMilli, p.CPUBurst.MaxAllowed)) + row = append(row, displayCPUBurst(cpuMilli, p.CPUBurst.MaxAllowed)) } if opts.showDefaultColumn { diff --git a/tsuru/client/plan_test.go b/tsuru/client/plan_test.go index 456bd257..7a785f9a 100644 --- a/tsuru/client/plan_test.go +++ b/tsuru/client/plan_test.go @@ -168,6 +168,35 @@ func (s *S) TestPlanListWithBurst(c *check.C) { c.Assert(stdout.String(), check.Equals, expected) } +func (s *S) TestPlanListWithBurstAndCPUOverrided(c *check.C) { + var stdout, stderr bytes.Buffer + result := `[ + {"name": "test", "cpumilli": 300, "memory": 536870912, "default": false, "cpuBurst": {"default": 1.1}, "override": {"cpumilli": 1000}} +]` + expected := `+------+-----------------+--------+---------------------+---------+ +| Name | CPU | Memory | CPU Burst (default) | Default | ++------+-----------------+--------+---------------------+---------+ +| test | 100% (override) | 512Mi | up to 110% | false | ++------+-----------------+--------+---------------------+---------+ +` + context := cmd.Context{ + Args: []string{}, + Stdout: &stdout, + Stderr: &stderr, + } + trans := &cmdtest.ConditionalTransport{ + Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK}, + CondFunc: func(req *http.Request) bool { + return strings.HasSuffix(req.URL.Path, "/plans") && req.Method == "GET" + }, + } + client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager) + command := PlanList{} + err := command.Run(&context, client) + c.Assert(err, check.IsNil) + c.Assert(stdout.String(), check.Equals, expected) +} + func (s *S) TestPlanListWithBurstKubernetesFriendly(c *check.C) { var stdout, stderr bytes.Buffer result := `[