Skip to content

Commit

Permalink
Fix displaying of empty quotas tables
Browse files Browse the repository at this point in the history
* When the API returns a list of empty quotas, the CLI user should
see the message `No [space/org] quotas found` instead of table headers
with empty rows.

[finishes #165135189]

Co-authored-by: Reid Mitchell <[email protected]>
Co-authored-by: Mona Mohebbi <[email protected]>
  • Loading branch information
reidmit and monamohebbi committed Feb 6, 2020
1 parent 3756751 commit 0d06556
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion command/v7/org_quotas_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (cmd OrgQuotasCommand) Execute(args []string) error {
}

quotaDisplayer := shared.NewQuotaDisplayer(cmd.UI)
quotaDisplayer.DisplayQuotasTable(quotas)
quotaDisplayer.DisplayQuotasTable(quotas, "No organization quotas found.")

return nil
}
16 changes: 16 additions & 0 deletions command/v7/org_quotas_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,20 @@ var _ = Describe("org-quotas command", func() {
Expect(testUI.Err).To(Say("some-warning-2"))
})
})

When("the quota list is empty", func() {
BeforeEach(func() {
fakeConfig.CurrentUserReturns(configv3.User{Name: "apple"}, nil)
fakeActor.GetOrganizationQuotasReturns([]v7action.OrganizationQuota{}, v7action.Warnings{"some-warning-1", "some-warning-2"}, nil)
})

It("prints warnings and returns error", func() {
Expect(executeErr).NotTo(HaveOccurred())

Expect(testUI.Err).To(Say("some-warning-1"))
Expect(testUI.Err).To(Say("some-warning-2"))
Expect(testUI.Out).To(Say(`Getting org quotas as apple\.\.\.`))
Expect(testUI.Out).To(Say("No organization quotas found."))
})
})
})
7 changes: 6 additions & 1 deletion command/v7/shared/quota_displayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ func NewQuotaDisplayer(ui command.UI) QuotaDisplayer {
return QuotaDisplayer{ui: ui}
}

func (displayer QuotaDisplayer) DisplayQuotasTable(quotas []v7action.Quota) {
func (displayer QuotaDisplayer) DisplayQuotasTable(quotas []v7action.Quota, emptyMessage string) {
if len(quotas) == 0 {
displayer.ui.DisplayText(emptyMessage)
return
}

var keyValueTable = [][]string{
{"name", "total memory", "instance memory", "routes", "service instances", "paid service plans", "app instances", "route ports"},
}
Expand Down
2 changes: 1 addition & 1 deletion command/v7/space_quotas_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (cmd SpaceQuotasCommand) Execute(args []string) error {
}

quotaDisplayer := shared.NewQuotaDisplayer(cmd.UI)
quotaDisplayer.DisplayQuotasTable(quotas)
quotaDisplayer.DisplayQuotasTable(quotas, "No space quotas found.")

return nil
}
16 changes: 16 additions & 0 deletions command/v7/space_quotas_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,20 @@ var _ = Describe("space-quotas command", func() {
Expect(testUI.Err).To(Say("some-warning-2"))
})
})

When("the quota list is empty", func() {
BeforeEach(func() {
fakeConfig.CurrentUserReturns(configv3.User{Name: "apple"}, nil)
fakeActor.GetSpaceQuotasByOrgGUIDReturns([]v7action.SpaceQuota{}, v7action.Warnings{"some-warning-1", "some-warning-2"}, nil)
})

It("prints warnings and returns error", func() {
Expect(executeErr).NotTo(HaveOccurred())

Expect(testUI.Err).To(Say("some-warning-1"))
Expect(testUI.Err).To(Say("some-warning-2"))
Expect(testUI.Out).To(Say(`Getting space quotas as apple\.\.\.`))
Expect(testUI.Out).To(Say("No space quotas found."))
})
})
})

0 comments on commit 0d06556

Please sign in to comment.