当前位置: 首页>>代码示例>>Golang>>正文


Golang testing.RunCommand函数代码示例

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


在下文中一共展示了RunCommand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestAddBadArgs

func (s *addSuite) TestAddBadArgs(c *gc.C) {
	addCmd := cloud.NewAddCloudCommand()
	_, err := testing.RunCommand(c, addCmd)
	c.Assert(err, gc.ErrorMatches, "Usage: juju add-cloud <cloud name> <cloud definition file>")
	_, err = testing.RunCommand(c, addCmd, "cloud", "cloud.yaml", "extra")
	c.Assert(err, gc.ErrorMatches, `unrecognized args: \["extra"\]`)
}
开发者ID:makyo,项目名称:juju,代码行数:7,代码来源:add_test.go

示例2: TestRemoveBadArgs

func (s *removeSuite) TestRemoveBadArgs(c *gc.C) {
	cmd := cloud.NewRemoveCloudCommand()
	_, err := testing.RunCommand(c, cmd)
	c.Assert(err, gc.ErrorMatches, "Usage: juju remove-cloud <cloud name>")
	_, err = testing.RunCommand(c, cmd, "cloud", "extra")
	c.Assert(err, gc.ErrorMatches, `unrecognized args: \["extra"\]`)
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:remove_test.go

示例3: TestBootstrapPropagatesEnvErrors

// In the case where we cannot examine an environment, we want the
// error to propagate back up to the user.
func (s *BootstrapSuite) TestBootstrapPropagatesEnvErrors(c *gc.C) {
	//TODO(bogdanteleaga): fix this for windows once permissions are fixed
	if runtime.GOOS == "windows" {
		c.Skip("bug 1403084: this is very platform specific. When/if we will support windows state machine, this will probably be rewritten.")
	}

	const envName = "devenv"
	env := resetJujuHome(c, envName)
	defaultSeriesVersion := version.Current
	defaultSeriesVersion.Series = config.PreferredSeries(env.Config())
	// Force a dev version by having a non zero build number.
	// This is because we have not uploaded any tools and auto
	// upload is only enabled for dev versions.
	defaultSeriesVersion.Build = 1234
	s.PatchValue(&version.Current, defaultSeriesVersion)
	s.PatchValue(&environType, func(string) (string, error) { return "", nil })

	_, err := coretesting.RunCommand(c, envcmd.Wrap(&BootstrapCommand{}), "-e", envName)
	c.Assert(err, jc.ErrorIsNil)

	// Change permissions on the jenv file to simulate some kind of
	// unexpected error when trying to read info from the environment
	jenvFile := gitjujutesting.HomePath(".juju", "environments", envName+".jenv")
	err = os.Chmod(jenvFile, os.FileMode(0200))
	c.Assert(err, jc.ErrorIsNil)

	// The second bootstrap should fail b/c of the propogated error
	_, err = coretesting.RunCommand(c, envcmd.Wrap(&BootstrapCommand{}), "-e", envName)
	c.Assert(err, gc.ErrorMatches, "there was an issue examining the environment: .*")
}
开发者ID:kakamessi99,项目名称:juju,代码行数:32,代码来源:bootstrap_test.go

示例4: TestBootstrapPropagatesEnvErrors

// In the case where we cannot examine an environment, we want the
// error to propagate back up to the user.
func (s *BootstrapSuite) TestBootstrapPropagatesEnvErrors(c *gc.C) {

	env := resetJujuHome(c)
	defaultSeriesVersion := version.Current
	defaultSeriesVersion.Series = config.PreferredSeries(env.Config())
	// Force a dev version by having a non zero build number.
	// This is because we have not uploaded any tools and auto
	// upload is only enabled for dev versions.
	defaultSeriesVersion.Build = 1234
	s.PatchValue(&version.Current, defaultSeriesVersion)

	const envName = "peckham"
	_, err := coretesting.RunCommand(c, envcmd.Wrap(&BootstrapCommand{}), "-e", envName)
	c.Assert(err, gc.IsNil)

	// Change permissions on the jenv file to simulate some kind of
	// unexpected error when trying to read info from the environment
	jenvFile := gitjujutesting.HomePath(".juju", "environments", envName+".jenv")
	err = os.Chmod(jenvFile, os.FileMode(0200))
	c.Assert(err, gc.IsNil)

	// The second bootstrap should fail b/c of the propogated error
	_, err = coretesting.RunCommand(c, envcmd.Wrap(&BootstrapCommand{}), "-e", envName)
	c.Assert(err, gc.ErrorMatches, "there was an issue examining the environment: .*")
}
开发者ID:zhouqt,项目名称:juju,代码行数:27,代码来源:bootstrap_test.go

示例5: testSSHCommandHostAddressRetry

func (s *SSHSuite) testSSHCommandHostAddressRetry(c *gc.C, proxy bool) {
	m := s.Factory.MakeMachine(c, nil)
	s.setKeys(c, m)

	called := 0
	attemptStarter := &callbackAttemptStarter{next: func() bool {
		called++
		return called < 2
	}}
	s.PatchValue(&sshHostFromTargetAttemptStrategy, attemptStarter)

	// Ensure that the ssh command waits for a public address, or the attempt
	// strategy's Done method returns false.
	args := []string{"--proxy=" + fmt.Sprint(proxy), "0"}
	_, err := coretesting.RunCommand(c, newSSHCommand(), args...)
	c.Assert(err, gc.ErrorMatches, "no .+ address")
	c.Assert(called, gc.Equals, 2)

	called = 0
	attemptStarter.next = func() bool {
		called++
		if called > 1 {
			s.setAddresses(c, m)
		}
		return true
	}

	_, err = coretesting.RunCommand(c, newSSHCommand(), args...)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, gc.Equals, 2)
}
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:ssh_unix_test.go

示例6: TestBadArgs

func (s *defaultCredentialSuite) TestBadArgs(c *gc.C) {
	cmd := cloud.NewSetDefaultCredentialCommand()
	_, err := testing.RunCommand(c, cmd)
	c.Assert(err, gc.ErrorMatches, "Usage: juju set-default-credential <cloud-name> <credential-name>")
	_, err = testing.RunCommand(c, cmd, "cloud", "credential", "extra")
	c.Assert(err, gc.ErrorMatches, `unrecognized args: \["extra"\]`)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:defaultcredential_test.go

示例7: TestBadArgs

func (s *defaultRegionSuite) TestBadArgs(c *gc.C) {
	cmd := cloud.NewSetDefaultRegionCommand()
	_, err := testing.RunCommand(c, cmd)
	c.Assert(err, gc.ErrorMatches, "Usage: juju set-default-region <cloud-name> <region>")
	_, err = testing.RunCommand(c, cmd, "cloud", "region", "extra")
	c.Assert(err, gc.ErrorMatches, `unrecognized args: \["extra"\]`)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:defaultregion_test.go

示例8: TestUnits

func (s *cmdMetricsCommandSuite) TestUnits(c *gc.C) {
	meteredCharm := s.Factory.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "local:quantal/metered"})
	meteredService := s.Factory.MakeApplication(c, &factory.ApplicationParams{Charm: meteredCharm})
	unit := s.Factory.MakeUnit(c, &factory.UnitParams{Application: meteredService, SetCharmURL: true})
	unit2 := s.Factory.MakeUnit(c, &factory.UnitParams{Application: meteredService, SetCharmURL: true})
	newTime1 := time.Now().Round(time.Second)
	newTime2 := newTime1.Add(time.Second)
	metricA := state.Metric{"pings", "5", newTime1}
	metricB := state.Metric{"pings", "10.5", newTime2}
	s.Factory.MakeMetric(c, &factory.MetricParams{Unit: unit, Metrics: []state.Metric{metricA}})
	s.Factory.MakeMetric(c, &factory.MetricParams{Unit: unit2, Metrics: []state.Metric{metricA, metricB}})
	ctx, err := coretesting.RunCommand(c, metricsdebug.New(), "metered/1")
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(cmdtesting.Stdout(ctx), gc.Equals,
		formatTabular(metric{
			Unit:      unit2.Name(),
			Timestamp: newTime2,
			Metric:    "pings",
			Value:     "10.5",
		}),
	)
	ctx, err = coretesting.RunCommand(c, metricsdebug.New(), "metered/0")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(cmdtesting.Stdout(ctx), gc.Equals,
		formatTabular(metric{
			Unit:      unit.Name(),
			Timestamp: newTime1,
			Metric:    "pings",
			Value:     "5",
		}),
	)
}
开发者ID:bac,项目名称:juju,代码行数:33,代码来源:cmd_juju_metrics.go

示例9: TestSuccess

func (*jenvSuite) TestSuccess(c *gc.C) {
	// Create a jenv file.
	contents := makeJenvContents("who", "Secret!", "env-UUID", testing.CACert, "1.2.3.4:17070")
	f := openJenvFile(c, contents)
	defer f.Close()

	// Import the newly created jenv file.
	jenvCmd := &environment.JenvCommand{}
	ctx, err := testing.RunCommand(c, jenvCmd, f.Name())
	c.Assert(err, jc.ErrorIsNil)

	// The jenv file has been properly imported.
	assertJenvContents(c, contents, "testing")

	// The default environment is now the newly imported one, and the output
	// reflects the change.
	c.Assert(envcmd.ReadCurrentEnvironment(), gc.Equals, "testing")
	c.Assert(testing.Stdout(ctx), gc.Equals, "erewhemos -> testing\n")

	// Trying to import the jenv with the same name a second time raises an
	// error.
	jenvCmd = &environment.JenvCommand{}
	ctx, err = testing.RunCommand(c, jenvCmd, f.Name())
	c.Assert(err, gc.ErrorMatches, `an environment named "testing" already exists: you can provide a second parameter to rename the environment`)

	// Overriding the environment name solves the problem.
	jenvCmd = &environment.JenvCommand{}
	ctx, err = testing.RunCommand(c, jenvCmd, f.Name(), "another")
	c.Assert(err, jc.ErrorIsNil)
	assertJenvContents(c, contents, "another")
	c.Assert(envcmd.ReadCurrentEnvironment(), gc.Equals, "another")
	c.Assert(testing.Stdout(ctx), gc.Equals, "testing -> another\n")
}
开发者ID:Pankov404,项目名称:juju,代码行数:33,代码来源:jenv_test.go

示例10: TestRemoveUser

func (s *RemoveUserSuite) TestRemoveUser(c *gc.C) {
	_, err := testing.RunCommand(c, envcmd.Wrap(&UserAddCommand{}), "foobar")
	c.Assert(err, gc.IsNil)

	_, err = testing.RunCommand(c, envcmd.Wrap(&RemoveUserCommand{}), "foobar")
	c.Assert(err, gc.IsNil)
}
开发者ID:jiasir,项目名称:juju,代码行数:7,代码来源:removeuser_test.go

示例11: TestBootstrapTwice

func (s *BootstrapSuite) TestBootstrapTwice(c *gc.C) {
	const envName = "devenv"
	s.patchVersionAndSeries(c, envName)

	_, err := coretesting.RunCommand(c, newBootstrapCommand(), "-e", envName, "--auto-upgrade")
	c.Assert(err, jc.ErrorIsNil)

	_, err = coretesting.RunCommand(c, newBootstrapCommand(), "-e", envName, "--auto-upgrade")
	c.Assert(err, gc.ErrorMatches, "environment is already bootstrapped")
}
开发者ID:imoapps,项目名称:juju,代码行数:10,代码来源:bootstrap_test.go

示例12: TestChangeAsCommandPair

func (s *SetEnvironmentSuite) TestChangeAsCommandPair(c *gc.C) {
	_, err := testing.RunCommand(c, envcmd.Wrap(&SetEnvironmentCommand{}), "default-series=raring")
	c.Assert(err, gc.IsNil)

	context, err := testing.RunCommand(c, envcmd.Wrap(&GetEnvironmentCommand{}), "default-series")
	c.Assert(err, gc.IsNil)
	output := strings.TrimSpace(testing.Stdout(context))

	c.Assert(output, gc.Equals, "raring")
}
开发者ID:kapilt,项目名称:juju,代码行数:10,代码来源:environment_test.go

示例13: TestRestoreArgs

func (s *restoreSuite) TestRestoreArgs(c *gc.C) {
	_, err := testing.RunCommand(c, s.command, "restore")
	c.Assert(err, gc.ErrorMatches, "you must specify either a file or a backup id.")

	_, err = testing.RunCommand(c, s.command, "restore", "--id", "anid", "--file", "afile")
	c.Assert(err, gc.ErrorMatches, "you must specify either a file or a backup id but not both.")

	_, err = testing.RunCommand(c, s.command, "restore", "--id", "anid", "-b")
	c.Assert(err, gc.ErrorMatches, "it is not possible to rebootstrap and restore from an id.")
}
开发者ID:Pankov404,项目名称:juju,代码行数:10,代码来源:restore_test.go

示例14: TestNoEndpoints

func (s *EndpointSuite) TestNoEndpoints(c *gc.C) {
	// Run command once to create store in test.
	_, err := coretesting.RunCommand(c, envcmd.Wrap(&EndpointCommand{}))
	c.Assert(err, gc.IsNil)
	info := s.APIInfo(c)
	s.setAPIAddresses(c)
	ctx, err := coretesting.RunCommand(c, envcmd.Wrap(&EndpointCommand{}))
	c.Assert(err, gc.IsNil)
	c.Assert(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")
	output := string(ctx.Stdout.(*bytes.Buffer).Bytes())
	c.Assert(output, gc.Equals, fmt.Sprintf("%s\n", info.Addrs[0]))
}
开发者ID:jiasir,项目名称:juju,代码行数:12,代码来源:endpoint_test.go

示例15: TestBadArgs

func (s *updateCredentialSuite) TestBadArgs(c *gc.C) {
	store := &jujuclienttesting.MemStore{
		Controllers: map[string]jujuclient.ControllerDetails{
			"controller": {},
		},
		CurrentControllerName: "controller",
	}
	cmd := cloud.NewUpdateCredentialCommandForTest(store, nil)
	_, err := testing.RunCommand(c, cmd)
	c.Assert(err, gc.ErrorMatches, "Usage: juju update-credential <cloud-name> <credential-name>")
	_, err = testing.RunCommand(c, cmd, "cloud", "credential", "extra")
	c.Assert(err, gc.ErrorMatches, `unrecognized args: \["extra"\]`)
}
开发者ID:bac,项目名称:juju,代码行数:13,代码来源:updatecredential_test.go


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