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


Golang testing.Stderr函数代码示例

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


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

示例1: TestAddUnsupportedContainerToMachine

func (s *AddMachineSuite) TestAddUnsupportedContainerToMachine(c *gc.C) {
	context, err := runAddMachine(c)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stderr(context), gc.Equals, "created machine 0\n")
	m, err := s.State.Machine("0")
	c.Assert(err, gc.IsNil)
	m.SetSupportedContainers([]instance.ContainerType{instance.KVM})
	context, err = runAddMachine(c, "lxc:0")
	c.Assert(err, gc.ErrorMatches, "cannot add a new machine: machine 0 cannot host lxc containers")
	c.Assert(testing.Stderr(context), gc.Equals, "failed to create 1 machine\n")
}
开发者ID:klyachin,项目名称:juju,代码行数:11,代码来源:addmachine_test.go

示例2: TestAddUserAndRegister

func (s *cmdRegistrationSuite) TestAddUserAndRegister(c *gc.C) {
	// First, add user "bob", and record the "juju register" command
	// that is printed out.
	context := s.run(c, nil, "add-user", "bob", "Bob Dobbs")
	c.Check(testing.Stderr(context), gc.Equals, "")
	stdout := testing.Stdout(context)
	c.Check(stdout, gc.Matches, `
User "Bob Dobbs \(bob\)" added
Please send this command to bob:
    juju register .*

"Bob Dobbs \(bob\)" has not been granted access to any models(.|\n)*
`[1:])
	jujuRegisterCommand := strings.Fields(strings.TrimSpace(
		strings.SplitN(stdout[strings.Index(stdout, "juju register"):], "\n", 2)[0],
	))
	c.Logf("%q", jujuRegisterCommand)

	// Now run the "juju register" command. We need to pass the
	// controller name and password to set.
	stdin := strings.NewReader("bob-controller\nhunter2\nhunter2\n")
	args := jujuRegisterCommand[1:] // drop the "juju"
	context = s.run(c, stdin, args...)
	c.Check(testing.Stdout(context), gc.Equals, "")
	c.Check(testing.Stderr(context), gc.Equals, `
Please set a name for this controller: 
Enter password: 
Confirm password: 

Welcome, bob. You are now logged into "bob-controller".

There are no models available. You can create models with
"juju create-model", or you can ask an administrator or owner
of a model to grant access to that model with "juju grant".

`[1:])

	// Make sure that the saved server details are sufficient to connect
	// to the api server.
	accountDetails, err := s.ControllerStore.AccountByName("bob-controller", "[email protected]")
	c.Assert(err, jc.ErrorIsNil)
	api, err := juju.NewAPIConnection(juju.NewAPIConnectionParams{
		Store:           s.ControllerStore,
		ControllerName:  "bob-controller",
		AccountDetails:  accountDetails,
		BootstrapConfig: noBootstrapConfig,
		DialOpts:        api.DefaultDialOpts(),
	})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(api.Close(), jc.ErrorIsNil)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:51,代码来源:cmd_juju_register_test.go

示例3: TestRegisterMultipleModels

func (s *RegisterSuite) TestRegisterMultipleModels(c *gc.C) {
	s.listModels = func(_ jujuclient.ClientStore, controllerName, userName string) ([]base.UserModel, error) {
		return []base.UserModel{{
			Name:  "model1",
			Owner: "[email protected]",
			UUID:  "df136476-12e9-11e4-8a70-b2227cce2b54",
		}, {
			Name:  "model2",
			Owner: "[email protected]",
			UUID:  "df136476-12e9-11e4-8a70-b2227cce2b55",
		}}, nil
	}
	ctx := s.testRegister(c, "")

	// When there are multiple models, no current model will be set.
	// Instead, the command will output the list of models and inform
	// the user how to set the current model.
	_, err := s.store.CurrentModel("controller-name")
	c.Assert(err, jc.Satisfies, errors.IsNotFound)

	stderr := testing.Stderr(ctx)
	c.Assert(stderr, gc.Equals, `
Enter a name for this controller [controller-name]: 
Enter a new password: 
Confirm password: 

Welcome, bob. You are now logged into "controller-name".

There are 2 models available. Use "juju switch" to select
one of them:
  - juju switch model1
  - juju switch model2

`[1:])
}
开发者ID:kat-co,项目名称:juju,代码行数:35,代码来源:register_test.go

示例4: TestSetCurrentModel

func (s *filesSuite) TestSetCurrentModel(c *gc.C) {
	ctx := testing.Context(c)
	err := modelcmd.SetCurrentModel(ctx, "new-model")
	c.Assert(err, jc.ErrorIsNil)
	s.assertCurrentModel(c, "new-model")
	c.Assert(testing.Stderr(ctx), gc.Equals, "-> new-model\n")
}
开发者ID:exekias,项目名称:juju,代码行数:7,代码来源:files_test.go

示例5: TestAddContainerToExistingMachine

func (s *AddMachineSuite) TestAddContainerToExistingMachine(c *gc.C) {
	context, err := runAddMachine(c)
	c.Assert(err, gc.IsNil)
	c.Assert(testing.Stderr(context), gc.Equals, "created machine 0\n")
	for i, container := range instance.ContainerTypes {
		machineNum := strconv.Itoa(i + 1)
		context, err = runAddMachine(c)
		c.Assert(err, gc.IsNil)
		c.Assert(testing.Stderr(context), gc.Equals, "created machine "+machineNum+"\n")
		context, err := runAddMachine(c, fmt.Sprintf("%s:%s", container, machineNum))
		c.Assert(err, gc.IsNil)
		machine := fmt.Sprintf("%s/%s/0", machineNum, container)
		c.Assert(testing.Stderr(context), gc.Equals, "created container "+machine+"\n")
		s._assertAddContainer(c, machineNum, machine, container)
	}
}
开发者ID:klyachin,项目名称:juju,代码行数:16,代码来源:addmachine_test.go

示例6: TestKillEarlyAPIConnectionTimeout

func (s *KillSuite) TestKillEarlyAPIConnectionTimeout(c *gc.C) {
	stop := make(chan struct{})
	defer close(stop)
	testDialer := func(sysName string) (*api.State, error) {
		<-stop
		return nil, errors.New("kill command waited too long")
	}

	done := make(chan struct{})
	go func() {
		defer close(done)
		cmd := system.NewKillCommand(nil, nil, nil, testDialer)
		ctx, err := testing.RunCommand(c, cmd, "test1", "-y")
		c.Check(err, jc.ErrorIsNil)
		c.Check(testing.Stderr(ctx), jc.Contains, "Unable to open API: connection to state server timed out")
		c.Check(s.api.ignoreBlocks, jc.IsFalse)
		c.Check(s.api.destroyAll, jc.IsFalse)
		checkSystemRemovedFromStore(c, "test1", s.store)
	}()
	select {
	case <-done:
	case <-time.After(1 * time.Minute):
		c.Fatalf("Kill command waited too long to open the API")
	}
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:25,代码来源:kill_test.go

示例7: TestKillCannotConnectToAPISucceeds

func (s *KillSuite) TestKillCannotConnectToAPISucceeds(c *gc.C) {
	s.apierror = errors.New("connection refused")
	ctx, err := s.runKillCommand(c, "local.test1", "-y")
	c.Assert(err, jc.ErrorIsNil)
	c.Check(testing.Stderr(ctx), jc.Contains, "Unable to open API: connection refused")
	checkControllerRemovedFromStore(c, "local.test1", s.store)
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:kill_test.go

示例8: TestFinalizeCredentialUserPass

func (s *credentialsSuite) TestFinalizeCredentialUserPass(c *gc.C) {
	in := cloud.NewCredential("userpass", map[string]string{
		"application-id":       "application",
		"application-password": "password",
		"subscription-id":      "subscription",
		"tenant-id":            "tenant",
	})
	ctx := coretesting.Context(c)
	out, err := s.provider.FinalizeCredential(ctx, environs.FinalizeCredentialParams{Credential: in})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(out, gc.NotNil)
	c.Assert(out.AuthType(), gc.Equals, cloud.AuthType("service-principal-secret"))
	c.Assert(out.Attributes(), jc.DeepEquals, map[string]string{
		"application-id":       "application",
		"application-password": "password",
		"subscription-id":      "subscription",
	})
	stderr := coretesting.Stderr(ctx)
	c.Assert(stderr, gc.Equals, `
WARNING: The "userpass" auth-type is deprecated, and will be removed soon.

Please update the credential in ~/.local/share/juju/credentials.yaml,
changing auth-type to "service-principal-secret", and dropping the tenant-id field.

`[1:])
}
开发者ID:kat-co,项目名称:juju,代码行数:26,代码来源:credentials_test.go

示例9: TestLogoutCount

func (s *LogoutCommandSuite) TestLogoutCount(c *gc.C) {
	// Create multiple controllers. We'll log out of each one
	// to observe the messages printed out by "logout".
	s.setPassword(c, "testing", "")
	controllers := []string{"testing", "testing2", "testing3"}
	details := s.store.Accounts["testing"]
	for _, controller := range controllers {
		s.store.Controllers[controller] = s.store.Controllers["testing"]
		err := s.store.UpdateAccount(controller, details)
		c.Assert(err, jc.ErrorIsNil)
	}

	expected := []string{
		"Logged out. You are still logged into 2 controllers.\n",
		"Logged out. You are still logged into 1 controller.\n",
		"Logged out. You are no longer logged into any controllers.\n",
	}

	for i, controller := range controllers {
		ctx, err := s.run(c, "-c", controller)
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(coretesting.Stdout(ctx), gc.Equals, "")
		c.Assert(coretesting.Stderr(ctx), gc.Equals, expected[i])
	}
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:logout_test.go

示例10: assertUserFacingOutput

func (s *filesystemListSuite) assertUserFacingOutput(c *gc.C, context *cmd.Context, expectedOut, expectedErr string) {
	obtainedOut := testing.Stdout(context)
	c.Assert(obtainedOut, gc.Equals, expectedOut)

	obtainedErr := testing.Stderr(context)
	c.Assert(obtainedErr, gc.Equals, expectedErr)
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:filesystemlist_test.go

示例11: TestSwitchLocalControllerWithCurrent

func (s *SwitchSimpleSuite) TestSwitchLocalControllerWithCurrent(c *gc.C) {
	s.currentController = "old"
	s.addController(c, "local.new")
	context, err := s.run(c, "new")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(coretesting.Stderr(context), gc.Equals, "old (controller) -> local.new (controller)\n")
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:7,代码来源:switch_test.go

示例12: assertDetectCredential

func (s *detectCredentialsSuite) assertDetectCredential(c *gc.C, cloudName, expectedRegion, errText string) {
	s.aCredential = jujucloud.CloudCredential{
		DefaultRegion: "default region",
		AuthCredentials: map[string]jujucloud.Credential{
			"test": s.credentialWithLabel(jujucloud.AccessKeyAuthType, "credential")},
	}
	clouds := map[string]jujucloud.Cloud{
		"test-cloud": {
			Type: "mock-provider",
		},
		"another-cloud": {
			Type: "another-provider",
		},
	}

	stdin := strings.NewReader(fmt.Sprintf("1\n%s\nQ\n", cloudName))
	ctx, err := s.run(c, stdin, clouds)
	c.Assert(err, jc.ErrorIsNil)
	if errText == "" {
		if expectedRegion != "" {
			s.aCredential.DefaultRegion = expectedRegion
		}
		c.Assert(s.store.Credentials["test-cloud"], jc.DeepEquals, s.aCredential)
	} else {
		output := strings.Replace(testing.Stderr(ctx), "\n", "", -1)
		c.Assert(output, gc.Matches, ".*"+regexp.QuoteMeta(errText)+".*")
	}
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:28,代码来源:detectcredentials_test.go

示例13: assertExpectedOutput

func (s *addSuite) assertExpectedOutput(c *gc.C, context *cmd.Context, expectedOut, expectedErr string) {
	obtainedErr := testing.Stderr(context)
	c.Assert(obtainedErr, gc.Equals, expectedErr)

	obtainedValid := testing.Stdout(context)
	c.Assert(obtainedValid, gc.Equals, expectedOut)
}
开发者ID:kat-co,项目名称:juju,代码行数:7,代码来源:add_test.go

示例14: TestSetCurrentController

func (s *filesSuite) TestSetCurrentController(c *gc.C) {
	ctx := testing.Context(c)
	err := envcmd.SetCurrentController(ctx, "new-sys")
	c.Assert(err, jc.ErrorIsNil)
	s.assertCurrentController(c, "new-sys")
	c.Assert(testing.Stderr(ctx), gc.Equals, "-> new-sys (controller)\n")
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:files_test.go

示例15: TestSetCurrentEnvironment

func (s *filesSuite) TestSetCurrentEnvironment(c *gc.C) {
	ctx := testing.Context(c)
	err := envcmd.SetCurrentEnvironment(ctx, "new-env")
	c.Assert(err, jc.ErrorIsNil)
	s.assertCurrentEnvironment(c, "new-env")
	c.Assert(testing.Stderr(ctx), gc.Equals, "-> new-env\n")
}
开发者ID:imoapps,项目名称:juju,代码行数:7,代码来源:files_test.go


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