本文整理汇总了Golang中github.com/juju/cmd/cmdtesting.RunCommand函数的典型用法代码示例。如果您正苦于以下问题:Golang RunCommand函数的具体用法?Golang RunCommand怎么用?Golang RunCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RunCommand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestGetUsersAgreementsWithTermOwner
func (s *listAgreementsSuite) TestGetUsersAgreementsWithTermOwner(c *gc.C) {
ctx, err := cmdtesting.RunCommand(c, listagreements.NewListAgreementsCommand())
c.Assert(err, jc.ErrorIsNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Equals, `[]
`)
c.Assert(s.client.called, jc.IsTrue)
s.client.setError("well, this is embarassing")
ctx, err = cmdtesting.RunCommand(c, listagreements.NewListAgreementsCommand())
c.Assert(err, gc.ErrorMatches, "failed to list user agreements: well, this is embarassing")
c.Assert(s.client.called, jc.IsTrue)
agreements := []terms.AgreementResponse{{
User: "test-user",
Owner: "owner",
Term: "test-term",
Revision: 1,
CreatedOn: time.Date(2015, 12, 25, 0, 0, 0, 0, time.UTC),
}}
s.client.setAgreements(agreements)
ctx, err = cmdtesting.RunCommand(c, listagreements.NewListAgreementsCommand())
c.Assert(err, jc.ErrorIsNil)
c.Assert(ctx, gc.NotNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Equals, expectedListAgreementsJSONOutputWithOwner)
c.Assert(s.client.called, jc.IsTrue)
ctx, err = cmdtesting.RunCommand(c, listagreements.NewListAgreementsCommand(), "--format", "yaml")
c.Assert(err, jc.ErrorIsNil)
c.Assert(ctx, gc.NotNil)
c.Assert(cmdtesting.Stdout(ctx), gc.Equals, "- user: test-user\n owner: owner\n term: test-term\n revision: 1\n createdon: 2015-12-25T00:00:00Z\n")
c.Assert(s.client.called, jc.IsTrue)
}
示例2: TestMultipleSuperCommands
func (s *HelpCommandSuite) TestMultipleSuperCommands(c *gc.C) {
level1 := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "level1"})
level2 := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "level2", UsagePrefix: "level1"})
level1.Register(level2)
level3 := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "level3", UsagePrefix: "level1 level2"})
level2.Register(level3)
level3.Register(&TestCommand{Name: "blah"})
ctx, err := cmdtesting.RunCommand(c, level1, "help", "level2", "level3", "blah")
c.Assert(err, jc.ErrorIsNil)
s.assertStdOutMatches(c, ctx, "Usage: level1 level2 level3 blah.*blah-doc.*")
_, err = cmdtesting.RunCommand(c, level1, "help", "level2", "missing", "blah")
c.Assert(err, gc.ErrorMatches, `subcommand "missing" not found`)
}
示例3: TestAllocateErrors
func (s *allocateSuite) TestAllocateErrors(c *gc.C) {
tests := []struct {
about string
args []string
expectedError string
}{{
about: "no args",
args: []string{},
expectedError: "budget and service name required",
}, {
about: "budget without allocation limit",
args: []string{"name", "db"},
expectedError: "invalid budget specification, expecting <budget>:<limit>",
}, {
about: "service not specified",
args: []string{"name:100"},
expectedError: "budget and service name required",
}}
for i, test := range tests {
c.Logf("test %d: %s", i, test.about)
set := allocate.NewAllocateCommand()
_, err := cmdtesting.RunCommand(c, set, test.args...)
c.Check(err, gc.ErrorMatches, test.expectedError)
s.mockAPI.CheckNoCalls(c)
}
}
示例4: TestallocateAPIError
func (s *allocateSuite) TestallocateAPIError(c *gc.C) {
s.stub.SetErrors(errors.New("something failed"))
set := allocate.NewAllocateCommand()
_, err := cmdtesting.RunCommand(c, set, "name:100", "db")
c.Assert(err, gc.ErrorMatches, "failed to create allocation: something failed")
s.mockAPI.CheckCall(c, 0, "CreateAllocation", "name", "100", "env-uuid", []string{"db"})
}
示例5: TestUpdateAllocationErrors
func (s *updateAllocationSuite) TestUpdateAllocationErrors(c *gc.C) {
tests := []struct {
about string
args []string
expectedError string
}{
{
about: "value needs to be a number",
args: []string{"name", "badvalue"},
expectedError: "value needs to be a whole number",
},
{
about: "value is missing",
args: []string{"name"},
expectedError: "service and value required",
},
{
about: "no args",
args: []string{},
expectedError: "service and value required",
},
}
for i, test := range tests {
s.mockAPI.ResetCalls()
c.Logf("test %d: %s", i, test.about)
set := updateallocation.NewUpdateAllocationCommand()
_, err := cmdtesting.RunCommand(c, set, test.args...)
c.Check(err, gc.ErrorMatches, test.expectedError)
s.mockAPI.CheckNoCalls(c)
}
}
示例6: TestUpdateAllocationAPIError
func (s *updateAllocationSuite) TestUpdateAllocationAPIError(c *gc.C) {
s.stub.SetErrors(errors.New("something failed"))
set := updateallocation.NewUpdateAllocationCommand()
_, err := cmdtesting.RunCommand(c, set, "name", "5")
c.Assert(err, gc.ErrorMatches, "failed to update the allocation: something failed")
s.mockAPI.CheckCall(c, 0, "UpdateAllocation", "env-uuid", "name", "5")
}
示例7: TestSetBudgetAPIError
func (s *setBudgetSuite) TestSetBudgetAPIError(c *gc.C) {
s.stub.SetErrors(errors.New("something failed"))
set := setbudget.NewSetBudgetCommand()
_, err := cmdtesting.RunCommand(c, set, "name", "5")
c.Assert(err, gc.ErrorMatches, "failed to set the budget: something failed")
s.mockAPI.CheckCall(c, 0, "SetBudget", "name", "5")
}
示例8: TestSetBudgetErrors
func (s *setBudgetSuite) TestSetBudgetErrors(c *gc.C) {
tests := []struct {
about string
args []string
expectedError string
}{
{
about: "value needs to be a number",
args: []string{"name", "badvalue"},
expectedError: "budget value needs to be a whole number",
},
{
about: "value is missing",
args: []string{"name"},
expectedError: "name and value required",
},
{
about: "no args",
args: []string{},
expectedError: "name and value required",
},
}
for i, test := range tests {
c.Logf("test %d: %s", i, test.about)
s.stub.SetErrors(errors.New(test.expectedError))
defer s.mockAPI.ResetCalls()
set := setbudget.NewSetBudgetCommand()
_, err := cmdtesting.RunCommand(c, set, test.args...)
c.Assert(err, gc.ErrorMatches, test.expectedError)
s.mockAPI.CheckNoCalls(c)
}
}
示例9: TestCreateBudgetAPIError
func (s *createBudgetSuite) TestCreateBudgetAPIError(c *gc.C) {
s.mockAPI.SetErrors(errors.New("something failed"))
createCmd := createbudget.NewCreateBudgetCommand()
_, err := cmdtesting.RunCommand(c, createCmd, "name", "5")
c.Assert(err, gc.ErrorMatches, "failed to create the budget: something failed")
s.mockAPI.CheckCall(c, 0, "CreateBudget", "name", "5")
}
示例10: TestListBudgetsOutputNoBudgets
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")
}
示例11: TestCreateBudgetErrors
func (s *createBudgetSuite) TestCreateBudgetErrors(c *gc.C) {
tests := []struct {
about string
args []string
expectedError string
}{
{
about: "test value needs to be a number",
args: []string{"name", "badvalue"},
expectedError: "budget value needs to be a whole number",
},
{
about: "value is missing",
args: []string{"name"},
expectedError: "name and value required",
},
{
about: "no args",
args: []string{},
expectedError: "name and value required",
},
}
for i, test := range tests {
c.Logf("test %d: %s", i, test.about)
if test.expectedError != "" {
s.mockAPI.SetErrors(errors.New(test.expectedError))
}
createCmd := createbudget.NewCreateBudgetCommand()
_, err := cmdtesting.RunCommand(c, createCmd, test.args...)
c.Assert(err, gc.ErrorMatches, test.expectedError)
s.mockAPI.CheckNoCalls(c)
}
}
示例12: TestAllocate
func (s *allocateSuite) TestAllocate(c *gc.C) {
s.mockAPI.resp = "allocation updated"
alloc := allocate.NewAllocateCommand()
ctx, err := cmdtesting.RunCommand(c, alloc, "name:100", "db")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, "allocation updated")
s.mockAPI.CheckCall(c, 0, "CreateAllocation", "name", "100", "env-uuid", []string{"db"})
}
示例13: TestUpdateAllocation
func (s *updateAllocationSuite) TestUpdateAllocation(c *gc.C) {
s.mockAPI.resp = "name budget set to 5"
set := updateallocation.NewUpdateAllocationCommand()
ctx, err := cmdtesting.RunCommand(c, set, "name", "5")
c.Assert(err, jc.ErrorIsNil)
c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, "name budget set to 5")
s.mockAPI.CheckCall(c, 0, "UpdateAllocation", "env-uuid", "name", "5")
}
示例14: TestListBudgetsNoOutput
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")
}
示例15: TestRunNotFound
func (s *deleteCharmSuite) TestRunNotFound(c *gc.C) {
configPath := s.createConfigFile(c)
// Deleting charm that does not exist returns a not found error.
config := &DeleteCharmCommand{}
_, err := cmdtesting.RunCommand(c, config, "--config", configPath, "--url", "cs:unreleased/foo")
c.Assert(err, gc.Equals, charmstore.ErrNotFound)
}