本文整理汇总了Golang中github.com/juju/juju/testing.Stderr函数的典型用法代码示例。如果您正苦于以下问题:Golang Stderr函数的具体用法?Golang Stderr怎么用?Golang Stderr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Stderr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestBootstrapGUISuccessLocal
func (s *bootstrapSuite) TestBootstrapGUISuccessLocal(c *gc.C) {
path := makeGUIArchive(c, "jujugui-2.2.0")
s.PatchEnvironment("JUJU_GUI", path)
env := newEnviron("foo", useDefaultKeys, nil)
ctx := coretesting.Context(c)
err := bootstrap.Bootstrap(modelcmd.BootstrapContext(ctx), env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(coretesting.Stderr(ctx), jc.Contains, "Preparing for Juju GUI 2.2.0 installation from local archive\n")
// Check GUI URL and version.
c.Assert(env.instanceConfig.GUI.URL, gc.Equals, "file://"+path)
c.Assert(env.instanceConfig.GUI.Version.String(), gc.Equals, "2.2.0")
// Check GUI size.
f, err := os.Open(path)
c.Assert(err, jc.ErrorIsNil)
defer f.Close()
info, err := f.Stat()
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.instanceConfig.GUI.Size, gc.Equals, info.Size())
// Check GUI hash.
h := sha256.New()
_, err = io.Copy(h, f)
c.Assert(err, jc.ErrorIsNil)
c.Assert(env.instanceConfig.GUI.SHA256, gc.Equals, fmt.Sprintf("%x", h.Sum(nil)))
}
开发者ID:makyo,项目名称:juju,代码行数:27,代码来源:bootstrap_test.go
示例17: TestBootstrapGUISuccessRemote
func (s *bootstrapSuite) TestBootstrapGUISuccessRemote(c *gc.C) {
s.PatchValue(bootstrap.GUIFetchMetadata, func(stream string, sources ...simplestreams.DataSource) ([]*gui.Metadata, error) {
c.Assert(stream, gc.Equals, gui.ReleasedStream)
c.Assert(sources[0].Description(), gc.Equals, "gui simplestreams")
c.Assert(sources[0].RequireSigned(), jc.IsTrue)
return []*gui.Metadata{{
Version: version.MustParse("2.0.42"),
FullPath: "https://1.2.3.4/juju-gui-2.0.42.tar.bz2",
SHA256: "hash-2.0.42",
Size: 42,
}, {
Version: version.MustParse("2.0.47"),
FullPath: "https://1.2.3.4/juju-gui-2.0.47.tar.bz2",
SHA256: "hash-2.0.47",
Size: 47,
}}, nil
})
env := newEnviron("foo", useDefaultKeys, nil)
ctx := coretesting.Context(c)
err := bootstrap.Bootstrap(modelcmd.BootstrapContext(ctx), env, bootstrap.BootstrapParams{
GUIDataSourceBaseURL: "https://1.2.3.4/gui/sources",
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(coretesting.Stderr(ctx), jc.Contains, "Preparing for Juju GUI 2.0.42 release installation\n")
// The most recent GUI release info has been stored.
c.Assert(env.instanceConfig.GUI.URL, gc.Equals, "https://1.2.3.4/juju-gui-2.0.42.tar.bz2")
c.Assert(env.instanceConfig.GUI.Version.String(), gc.Equals, "2.0.42")
c.Assert(env.instanceConfig.GUI.Size, gc.Equals, int64(42))
c.Assert(env.instanceConfig.GUI.SHA256, gc.Equals, "hash-2.0.42")
}
开发者ID:makyo,项目名称:juju,代码行数:31,代码来源:bootstrap_test.go
示例18: TestStorageAddToUnitInvalidUnitName
func (s *cmdStorageSuite) TestStorageAddToUnitInvalidUnitName(c *gc.C) {
cmdArgs := append([]string{"add-storage"}, "fluffyunit-0", "allecto=1")
context, err := runJujuCommand(c, cmdArgs...)
c.Assert(err, gc.ErrorMatches, `unit name "fluffyunit-0" not valid`)
c.Assert(testing.Stdout(context), gc.Equals, "")
c.Assert(testing.Stderr(context), gc.Equals, "error: unit name \"fluffyunit-0\" not valid\n")
}
开发者ID:kat-co,项目名称:juju,代码行数:7,代码来源:storage_test.go
示例19: TestDestroyReturnsBlocks
func (s *DestroySuite) TestDestroyReturnsBlocks(c *gc.C) {
s.api.SetErrors(¶ms.Error{Code: params.CodeOperationBlocked})
s.api.blocks = []params.ModelBlockInfo{
params.ModelBlockInfo{
Name: "test1",
UUID: test1UUID,
OwnerTag: "[email protected]",
Blocks: []string{
"BlockDestroy",
},
},
params.ModelBlockInfo{
Name: "test2",
UUID: test2UUID,
OwnerTag: "[email protected]",
Blocks: []string{
"BlockDestroy",
"BlockChange",
},
},
}
ctx, _ := s.runDestroyCommand(c, "local.test1", "-y", "--destroy-all-models")
c.Assert(testing.Stderr(ctx), gc.Equals, "Destroying controller\n"+
"NAME MODEL UUID OWNER BLOCKS\n"+
"test1 1871299e-1370-4f3e-83ab-1849ed7b1076 [email protected] destroy-model\n"+
"test2 c59d0e3b-2bd7-4867-b1b9-f1ef8a0bb004 [email protected] destroy-model,all-changes\n")
}
开发者ID:makyo,项目名称:juju,代码行数:27,代码来源:destroy_test.go
示例20: TestProposedControllerNameExists
func (s *RegisterSuite) TestProposedControllerNameExists(c *gc.C) {
// Controller does not have the UUID from s.testRegister, thereby
// mimicing a user with an already registered 'foreign' controller.
err := s.store.AddController("controller-name", jujuclient.ControllerDetails{
ControllerUUID: "0d75314a-5266-4f4f-8523-415be76f92dc",
CACert: testing.CACert,
})
s.listModels = func(_ jujuclient.ClientStore, controllerName, userName string) ([]base.UserModel, error) {
return []base.UserModel{{
Name: "model-name",
Owner: "[email protected]",
UUID: "df136476-12e9-11e4-8a70-b2227cce2b54",
}}, nil
}
ctx := s.testRegister(c, "you must specify a non-empty controller name")
secretKey := []byte(strings.Repeat("X", 32))
registrationData := s.encodeRegistrationDataWithControllerName(c, "bob", secretKey, "controller-name")
stdin := strings.NewReader("another-controller-name\nhunter2\nhunter2\n")
_, err = s.run(c, stdin, registrationData)
c.Assert(err, jc.ErrorIsNil)
stderr := testing.Stderr(ctx)
c.Assert(stderr, gc.Equals, `
WARNING: You already have a controller registered with the name "controller-name". Please choose a different name for the new controller.
Enter a name for this controller:
`[1:])
}
开发者ID:kat-co,项目名称:juju,代码行数:32,代码来源:register_test.go
注:本文中的github.com/juju/juju/testing.Stderr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论