func (s *listBudgetsSuite) TestListBudgetsOutputNoBudgets(c *gc.C) { s.mockAPI.result = &budget.ListBudgetsResponse{ Budgets: budget.BudgetSummaries{}, Total: budget.BudgetTotals{ Limit: "0", Allocated: "0", Available: "0", Unallocated: "0", Consumed: "0", }, Credit: "0", } expected := "" + "BUDGET \tMONTHLY\tALLOCATED\tAVAILABLE\tSPENT\n" + "TOTAL \t 0\t 0\t 0\t 0\n" + " \t \t \t \t \n" + "Credit limit:\t 0\t \t \t \n" listBudgets := listbudgets.NewListBudgetsCommand() ctx, err := cmdtesting.RunCommand(c, listBudgets) c.Assert(err, jc.ErrorIsNil) c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, expected) s.mockAPI.CheckCallNames(c, "ListBudgets") }
func (s *listBudgetsSuite) TestListBudgetsNoOutput(c *gc.C) { listBudgets := listbudgets.NewListBudgetsCommand() ctx, err := cmdtesting.RunCommand(c, listBudgets) c.Assert(err, gc.ErrorMatches, `no budget information available`) c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, ``) s.mockAPI.CheckCallNames(c, "ListBudgets") }
func (s *listBudgetsSuite) TestListBudgetsOutput(c *gc.C) { s.mockAPI.result = &budget.ListBudgetsResponse{ Budgets: budget.BudgetSummaries{ budget.BudgetSummary{ Owner: "bob", Budget: "personal", Limit: "50", Allocated: "30", Unallocated: "20", Available: "45", Consumed: "5", }, budget.BudgetSummary{ Owner: "bob", Budget: "work", Limit: "200", Allocated: "100", Unallocated: "100", Available: "150", Consumed: "50", }, budget.BudgetSummary{ Owner: "bob", Budget: "team", Limit: "50", Allocated: "10", Unallocated: "40", Available: "40", Consumed: "10", }, }, Total: budget.BudgetTotals{ Limit: "300", Allocated: "140", Available: "235", Unallocated: "160", Consumed: "65", }, Credit: "400", } // Expected command output. Make sure budgets are sorted alphabetically. expected := "" + "BUDGET \tMONTHLY\tALLOCATED\tAVAILABLE\tSPENT\n" + "personal \t 50\t 30\t 45\t 5\n" + "team \t 50\t 10\t 40\t 10\n" + "work \t 200\t 100\t 150\t 50\n" + "TOTAL \t 300\t 140\t 235\t 65\n" + " \t \t \t \t \n" + "Credit limit:\t 400\t \t \t \n" listBudgets := listbudgets.NewListBudgetsCommand() ctx, err := cmdtesting.RunCommand(c, listBudgets) c.Assert(err, jc.ErrorIsNil) c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, expected) s.mockAPI.CheckCallNames(c, "ListBudgets") }
// RegisterAll registers all romulus commands with the // provided command registry. func RegisterAll(r commandRegister) { r.Register(agree.NewAgreeCommand()) r.Register(allocate.NewAllocateCommand()) r.Register(createbudget.NewCreateBudgetCommand()) r.Register(listbudgets.NewListBudgetsCommand()) r.Register(listplans.NewListPlansCommand()) r.Register(setbudget.NewSetBudgetCommand()) r.Register(setplan.NewSetPlanCommand()) r.Register(showbudget.NewShowBudgetCommand()) r.Register(updateallocation.NewUpdateAllocationCommand()) }
// RegisterAll registers all romulus commands with the // provided command registry. func RegisterAll(r commandRegister) { register := func(c cmd.Command) { switch c := c.(type) { case modelcmd.ModelCommand: r.Register(modelcmd.Wrap(c)) case modelcmd.CommandBase: r.Register(modelcmd.WrapBase(c)) default: r.Register(c) } } register(agree.NewAgreeCommand()) register(listagreements.NewListAgreementsCommand()) register(allocate.NewAllocateCommand()) register(listbudgets.NewListBudgetsCommand()) register(createbudget.NewCreateBudgetCommand()) register(listplans.NewListPlansCommand()) register(setbudget.NewSetBudgetCommand()) register(setplan.NewSetPlanCommand()) register(showbudget.NewShowBudgetCommand()) register(updateallocation.NewUpdateAllocationCommand()) }
func (s *listBudgetsSuite) TestAPIError(c *gc.C) { s.mockAPI.SetErrors(errors.New("well, this is embarrassing")) listBudgets := listbudgets.NewListBudgetsCommand() _, err := cmdtesting.RunCommand(c, listBudgets) c.Assert(err, gc.ErrorMatches, "failed to retrieve budgets: well, this is embarrassing") }
func (s *listBudgetsSuite) TestUnexpectedParameters(c *gc.C) { listBudgets := listbudgets.NewListBudgetsCommand() _, err := cmdtesting.RunCommand(c, listBudgets, "unexpected") c.Assert(err, gc.ErrorMatches, `unrecognized args: \["unexpected"\]`) }