Skip to content

Commit e94a978

Browse files
committed
Merge pull request #237 from sykesm/hm-unknown-instances
Use '?' instead of '-1' when running instances is unknown [Finishes #76461268]
2 parents d4bdffc + f19bf65 commit e94a978

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

cf/commands/application/app_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,50 @@ var _ = Describe("app Command", func() {
152152
))
153153
})
154154
})
155+
156+
Describe("when running instances is unknown", func() {
157+
BeforeEach(func() {
158+
app := makeAppWithRoute("my-app")
159+
app.RunningInstances = -1
160+
appInstance := models.AppInstanceFields{
161+
State: models.InstanceRunning,
162+
Since: testtime.MustParse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2012"),
163+
CpuUsage: 5.0,
164+
DiskQuota: 4 * formatters.GIGABYTE,
165+
DiskUsage: 3 * formatters.GIGABYTE,
166+
MemQuota: 2 * formatters.GIGABYTE,
167+
MemUsage: 1 * formatters.GIGABYTE,
168+
}
169+
170+
appInstance2 := models.AppInstanceFields{
171+
State: models.InstanceRunning,
172+
Since: testtime.MustParse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Apr 1 15:04:05 -0700 MST 2012"),
173+
}
174+
175+
instances := []models.AppInstanceFields{appInstance, appInstance2}
176+
177+
appSummaryRepo.GetSummarySummary = app
178+
appInstancesRepo.GetInstancesResponses = [][]models.AppInstanceFields{instances}
179+
requirementsFactory.Application = app
180+
})
181+
182+
It("displays a '?' for running instances", func() {
183+
runCommand("my-app")
184+
185+
Expect(appSummaryRepo.GetSummaryAppGuid).To(Equal("app-guid"))
186+
Expect(appSummaryRepo.GetSummaryAppGuid).To(Equal("app-guid"))
187+
188+
Expect(ui.Outputs).To(ContainSubstrings(
189+
[]string{"Showing health and status", "my-app"},
190+
[]string{"state", "started"},
191+
[]string{"instances", "?/2"},
192+
[]string{"usage", "256M x 2 instances"},
193+
[]string{"urls", "my-app.example.com", "foo.example.com"},
194+
[]string{"#0", "running", "2012-01-02 03:04:05 PM", "500.0%", "1G of 2G", "3G of 4G"},
195+
[]string{"#1", "running", "2012-04-01 03:04:05 PM", "0%", "0 of 0", "0 of 0"},
196+
))
197+
})
198+
})
155199
})
156200

157201
func makeAppWithRoute(appName string) models.Application {

cf/commands/application/apps_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,34 @@ var _ = Describe("list-apps command", func() {
106106
))
107107
})
108108

109+
Context("when an app's running instances is unknown", func() {
110+
It("dipslays a '?' for running instances", func() {
111+
appRoutes := []models.RouteSummary{
112+
models.RouteSummary{
113+
Host: "app1",
114+
Domain: models.DomainFields{Name: "cfapps.io"},
115+
}}
116+
app := models.Application{}
117+
app.Name = "Application-1"
118+
app.State = "started"
119+
app.RunningInstances = -1
120+
app.InstanceCount = 2
121+
app.Memory = 512
122+
app.DiskQuota = 1024
123+
app.Routes = appRoutes
124+
125+
appSummaryRepo.GetSummariesInCurrentSpaceApps = []models.Application{app}
126+
127+
runCommand()
128+
129+
Expect(ui.Outputs).To(ContainSubstrings(
130+
[]string{"Getting apps in", "my-org", "my-space", "my-user"},
131+
[]string{"OK"},
132+
[]string{"Application-1", "started", "?/2", "512M", "1G", "app1.cfapps.io"},
133+
))
134+
})
135+
})
136+
109137
Context("when there are no apps", func() {
110138
It("tells the user that there are no apps", func() {
111139
runCommand()

cf/ui_helpers/ui.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package ui_helpers
22

33
import (
44
"fmt"
5-
. "github.com/cloudfoundry/cli/cf/i18n"
65
"strings"
76

7+
. "github.com/cloudfoundry/cli/cf/i18n"
8+
89
"github.com/cloudfoundry/cli/cf/models"
910
"github.com/cloudfoundry/cli/cf/terminal"
1011
)
@@ -30,6 +31,10 @@ func ColoredAppState(app models.ApplicationFields) string {
3031
func ColoredAppInstances(app models.ApplicationFields) string {
3132
healthString := fmt.Sprintf("%d/%d", app.RunningInstances, app.InstanceCount)
3233

34+
if app.RunningInstances < 0 {
35+
healthString = fmt.Sprintf("?/%d", app.InstanceCount)
36+
}
37+
3338
if app.RunningInstances == 0 {
3439
if strings.ToLower(app.State) == "stopped" {
3540
return healthString

0 commit comments

Comments
 (0)