• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cmdtesting.RunCommand函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/juju/cmd/cmdtesting.RunCommand函数的典型用法代码示例。如果您正苦于以下问题:Golang RunCommand函数的具体用法?Golang RunCommand怎么用?Golang RunCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了RunCommand函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:alesstimec,项目名称:romulus-1,代码行数:33,代码来源:listagreements_test.go


示例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`)
}
开发者ID:juju,项目名称:cmd,代码行数:15,代码来源:help_test.go


示例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)
	}
}
开发者ID:tasdomas,项目名称:romulus-1,代码行数:26,代码来源:allocate_test.go


示例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"})
}
开发者ID:tasdomas,项目名称:romulus-1,代码行数:7,代码来源:allocate_test.go


示例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)
	}
}
开发者ID:tasdomas,项目名称:romulus-1,代码行数:31,代码来源:updateallocation_test.go


示例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")
}
开发者ID:tasdomas,项目名称:romulus-1,代码行数:7,代码来源:updateallocation_test.go


示例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")
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:setbudget_test.go


示例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)
	}
}
开发者ID:bac,项目名称:juju,代码行数:32,代码来源:setbudget_test.go


示例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")
}
开发者ID:tasdomas,项目名称:romulus-1,代码行数:7,代码来源:createbudget_test.go


示例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")
}
开发者ID:alesstimec,项目名称:romulus-1,代码行数:25,代码来源:list-budgets_test.go


示例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)
	}
}
开发者ID:tasdomas,项目名称:romulus-1,代码行数:33,代码来源:createbudget_test.go


示例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"})
}
开发者ID:tasdomas,项目名称:romulus-1,代码行数:8,代码来源:allocate_test.go


示例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")
}
开发者ID:tasdomas,项目名称:romulus-1,代码行数:8,代码来源:updateallocation_test.go


示例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")
}
开发者ID:alesstimec,项目名称:romulus-1,代码行数:8,代码来源:list-budgets_test.go


示例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)
}
开发者ID:rogpeppe,项目名称:charmstore,代码行数:8,代码来源:deletecharm_test.go


示例16: TestCreateBudget

func (s *createBudgetSuite) TestCreateBudget(c *gc.C) {
	s.mockAPI.resp = "name budget set to 5"
	createCmd := createbudget.NewCreateBudgetCommand()
	ctx, err := cmdtesting.RunCommand(c, createCmd, "name", "5")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), jc.DeepEquals, "name budget set to 5")
	s.mockAPI.CheckCall(c, 0, "CreateBudget", "name", "5")
}
开发者ID:tasdomas,项目名称:romulus-1,代码行数:8,代码来源:createbudget_test.go


示例17: TestSetBudget

func (s *setBudgetSuite) TestSetBudget(c *gc.C) {
	s.mockAPI.resp = "name budget set to 5"
	set := setbudget.NewSetBudgetCommand()
	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\n")
	s.mockAPI.CheckCall(c, 0, "SetBudget", "name", "5")
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:setbudget_test.go


示例18: TestHelpBasics

func (s *HelpCommandSuite) TestHelpBasics(c *gc.C) {
	super := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest"})
	super.Register(&TestCommand{Name: "blah"})
	super.AddHelpTopic("basics", "short", "long help basics")

	ctx, err := cmdtesting.RunCommand(c, super)
	c.Assert(err, jc.ErrorIsNil)
	s.assertStdOutMatches(c, ctx, "long help basics")
}
开发者ID:juju,项目名称:cmd,代码行数:9,代码来源:help_test.go


示例19: TestListBudgetsOutput

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")
}
开发者ID:alesstimec,项目名称:romulus-1,代码行数:57,代码来源:list-budgets_test.go


示例20: TestHelpOutput

func (s *HelpCommandSuite) TestHelpOutput(c *gc.C) {
	for i, test := range []struct {
		message     string
		args        []string
		usagePrefix string
		helpMatch   string
		errMatch    string
	}{
		{
			message:   "no args shows help",
			helpMatch: "Usage: jujutest .*",
		}, {
			message:     "usage prefix with help command",
			args:        []string{"help"},
			usagePrefix: "juju",
			helpMatch:   "Usage: juju jujutest .*",
		}, {
			message:     "usage prefix with help flag",
			args:        []string{"--help"},
			usagePrefix: "juju",
			helpMatch:   "Usage: juju jujutest .*",
		}, {
			message:   "help arg usage",
			args:      []string{"blah", "--help"},
			helpMatch: "Usage: jujutest blah.*blah-doc.*",
		}, {
			message:     "usage prefix with help command",
			args:        []string{"help", "blah"},
			usagePrefix: "juju",
			helpMatch:   "Usage: juju jujutest blah .*",
		}, {
			message:     "usage prefix with help flag",
			args:        []string{"blah", "--help"},
			usagePrefix: "juju",
			helpMatch:   "Usage: juju jujutest blah .*",
		}, {
			message:  "too many args",
			args:     []string{"help", "blah", "blah"},
			errMatch: `extra arguments to command help: \["blah"\]`,
		},
	} {
		supername := "jujutest"
		super := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: supername, UsagePrefix: test.usagePrefix})
		super.Register(&TestCommand{Name: "blah"})
		c.Logf("%d: %s, %q", i, test.message, strings.Join(append([]string{supername}, test.args...), " "))

		ctx, err := cmdtesting.RunCommand(c, super, test.args...)
		if test.errMatch == "" {
			c.Assert(err, jc.ErrorIsNil)
			s.assertStdOutMatches(c, ctx, test.helpMatch)

		} else {
			c.Assert(err, gc.ErrorMatches, test.errMatch)
		}
	}
}
开发者ID:juju,项目名称:cmd,代码行数:56,代码来源:help_test.go



注:本文中的github.com/juju/cmd/cmdtesting.RunCommand函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cmdtesting.Stderr函数代码示例发布时间:2022-05-23
下一篇:
Golang cmdtesting.InitCommand函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap