Beispiel #1
0
// 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())
}
Beispiel #2
0
func (s setPlanCommandSuite) TestSetPlanCommand(c *gc.C) {
	tests := []struct {
		about       string
		plan        string
		application string
		err         string
		apiErr      error
		apiCalls    []testing.StubCall
	}{{
		about:       "all is well",
		plan:        "bob/default",
		application: "mysql",
		apiCalls: []testing.StubCall{{
			FuncName: "Authorize",
			Args: []interface{}{
				s.State.ModelUUID(),
				s.charmURL,
				"mysql",
			},
		}},
	}, {
		about:       "invalid application name",
		plan:        "bob/default",
		application: "mysql-0",
		err:         "invalid application name \"mysql-0\"",
	}, {
		about:       "unknown application",
		plan:        "bob/default",
		application: "wordpress",
		err:         "application \"wordpress\" not found.*",
	}, {
		about:       "unknown application",
		plan:        "bob/default",
		application: "mysql",
		apiErr:      errors.New("some strange error"),
		err:         "some strange error",
	},
	}
	for i, test := range tests {
		c.Logf("running test %d: %v", i, test.about)
		s.mockAPI.ResetCalls()
		if test.apiErr != nil {
			s.mockAPI.SetErrors(test.apiErr)
		}
		_, err := cmdtesting.RunCommand(c, setplan.NewSetPlanCommand(), test.application, test.plan)
		if test.err == "" {
			c.Assert(err, jc.ErrorIsNil)
			c.Assert(s.mockAPI.Calls(), gc.HasLen, 1)
			s.mockAPI.CheckCalls(c, test.apiCalls)

			app, err := s.State.Application("mysql")
			c.Assert(err, jc.ErrorIsNil)
			svcMacaroon := app.MetricCredentials()
			data, err := json.Marshal(macaroon.Slice{s.mockAPI.macaroon})
			c.Assert(err, jc.ErrorIsNil)
			c.Assert(svcMacaroon, gc.DeepEquals, data)
		} else {
			c.Assert(err, gc.ErrorMatches, test.err)
			c.Assert(s.mockAPI.Calls(), gc.HasLen, 0)
		}
	}
}
Beispiel #3
0
func (s *setPlanCommandSuite) TestNoArgs(c *gc.C) {
	_, err := cmdtesting.RunCommand(c, setplan.NewSetPlanCommand())
	c.Assert(err, gc.ErrorMatches, "need to specify application name and plan url")
}