本文整理汇总了Golang中github.com/juju/juju/testing.Stdout函数的典型用法代码示例。如果您正苦于以下问题:Golang Stdout函数的具体用法?Golang Stdout怎么用?Golang Stdout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Stdout函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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")
}
示例2: assertHelp
func (s *HelpStorageSuite) assertHelp(c *gc.C, expectedNames []string) {
ctx, err := testing.RunCommand(c, s.command, "--help")
c.Assert(err, jc.ErrorIsNil)
expected := "(?sm).*^purpose: " + s.command.Purpose + "$.*"
c.Check(testing.Stdout(ctx), gc.Matches, expected)
expected = "(?sm).*^" + s.command.Doc + "$.*"
c.Check(testing.Stdout(ctx), gc.Matches, expected)
s.checkHelpCommands(c, ctx, expectedNames)
}
示例3: TestHelp
func (s *downloadSuite) TestHelp(c *gc.C) {
ctx, err := testing.RunCommand(c, s.command, "download", "--help")
c.Assert(err, jc.ErrorIsNil)
info := s.subcommand.Info()
expected := `(?sm)usage: juju backups download \[options] ` + info.Args + `$.*`
c.Check(testing.Stdout(ctx), gc.Matches, expected)
expected = "(?sm).*^purpose: " + info.Purpose + "$.*"
c.Check(testing.Stdout(ctx), gc.Matches, expected)
expected = "(?sm).*^" + info.Doc + "$.*"
c.Check(testing.Stdout(ctx), gc.Matches, expected)
}
示例4: TestHelp
func (s *uploadSuite) TestHelp(c *gc.C) {
ctx, err := testing.RunCommand(c, s.command, "upload", "--help")
c.Assert(err, jc.ErrorIsNil)
info := s.subcommand.Info()
expected := "(?sm)usage: juju backups upload [options] " + info.Args + "$.*"
expected = strings.Replace(expected, "[", `\[`, -1)
c.Check(testing.Stdout(ctx), gc.Matches, expected)
expected = "(?sm).*^purpose: " + info.Purpose + "$.*"
c.Check(testing.Stdout(ctx), gc.Matches, expected)
expected = "(?sm).*^" + info.Doc + "$.*"
c.Check(testing.Stdout(ctx), gc.Matches, expected)
}
示例5: TestHelp
func (s *backupsSuite) TestHelp(c *gc.C) {
ctx, err := testing.RunCommand(c, s.command, "--help")
c.Assert(err, jc.ErrorIsNil)
expected := "(?s)usage: juju backups \\[options\\] <command> .+"
c.Check(testing.Stdout(ctx), gc.Matches, expected)
expected = "(?sm).*^purpose: " + s.command.Purpose + "$.*"
c.Check(testing.Stdout(ctx), gc.Matches, expected)
expected = "(?sm).*^" + s.command.Doc + "$.*"
c.Check(testing.Stdout(ctx), gc.Matches, expected)
s.checkHelpCommands(c)
}
示例6: 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)
}
示例7: TestDestroyCommandConfirmation
func (s *DestroySuite) TestDestroyCommandConfirmation(c *gc.C) {
var stdin, stdout bytes.Buffer
ctx, err := cmd.DefaultContext()
c.Assert(err, jc.ErrorIsNil)
ctx.Stdout = &stdout
ctx.Stdin = &stdin
// Ensure confirmation is requested if "-y" is not specified.
stdin.WriteString("n")
_, errc := cmdtesting.RunCommand(ctx, s.NewDestroyCommand(), "test2")
select {
case err := <-errc:
c.Check(err, gc.ErrorMatches, "environment destruction: aborted")
case <-time.After(testing.LongWait):
c.Fatalf("command took too long")
}
c.Check(testing.Stdout(ctx), gc.Matches, "WARNING!.*test2(.|\n)*")
checkEnvironmentExistsInStore(c, "test1", s.store)
// EOF on stdin: equivalent to answering no.
stdin.Reset()
stdout.Reset()
_, errc = cmdtesting.RunCommand(ctx, s.NewDestroyCommand(), "test2")
select {
case err := <-errc:
c.Check(err, gc.ErrorMatches, "environment destruction: aborted")
case <-time.After(testing.LongWait):
c.Fatalf("command took too long")
}
c.Check(testing.Stdout(ctx), gc.Matches, "WARNING!.*test2(.|\n)*")
checkEnvironmentExistsInStore(c, "test1", s.store)
for _, answer := range []string{"y", "Y", "yes", "YES"} {
stdin.Reset()
stdout.Reset()
stdin.WriteString(answer)
_, errc = cmdtesting.RunCommand(ctx, s.NewDestroyCommand(), "test2")
select {
case err := <-errc:
c.Check(err, jc.ErrorIsNil)
case <-time.After(testing.LongWait):
c.Fatalf("command took too long")
}
checkEnvironmentRemovedFromStore(c, "test2", s.store)
// Add the test2 environment back into the store for the next test
s.resetEnvironment(c)
}
}
示例8: checkHelp
func (s *BaseActionSuite) checkHelp(c *gc.C, subcmd cmd.Command) {
ctx, err := coretesting.RunCommand(c, s.command, subcmd.Info().Name, "--help")
c.Assert(err, gc.IsNil)
expected := "(?sm).*^usage: juju action " +
regexp.QuoteMeta(subcmd.Info().Name) +
` \[options\] ` + regexp.QuoteMeta(subcmd.Info().Args) + ".+"
c.Check(coretesting.Stdout(ctx), gc.Matches, expected)
expected = "(?sm).*^purpose: " + regexp.QuoteMeta(subcmd.Info().Purpose) + "$.*"
c.Check(coretesting.Stdout(ctx), gc.Matches, expected)
expected = "(?sm).*^" + regexp.QuoteMeta(subcmd.Info().Doc) + "$.*"
c.Check(coretesting.Stdout(ctx), gc.Matches, expected)
}
示例9: TestUserInfoFormatJson
func (*UserInfoCommandSuite) TestUserInfoFormatJson(c *gc.C) {
context, err := testing.RunCommand(c, newUserInfoCommand(), "--format", "json")
c.Assert(err, gc.IsNil)
c.Assert(testing.Stdout(context), gc.Equals, `
{"user-name":"admin","display-name":"","date-created":"1981-02-27 16:10:05 +0000 UTC","last-connection":"2014-01-01 00:00:00 +0000 UTC"}
`[1:])
}
示例10: TestLoginCommand
func (s *cmdLoginSuite) TestLoginCommand(c *gc.C) {
s.createTestUser(c)
// logout "admin" first; we'll need to give it
// a non-random password before we can do so.
s.changeUserPassword(c, "admin", "hunter2")
s.run(c, nil, "logout")
// TODO(axw) 2016-09-08 #1621375
// "juju logout" should clear the cookies for the controller.
os.Remove(filepath.Join(utils.Home(), ".go-cookies"))
context := s.run(c, strings.NewReader("hunter2\nhunter2\n"), "login", "test")
c.Assert(testing.Stdout(context), gc.Equals, "")
c.Assert(testing.Stderr(context), gc.Equals, `
please enter password for [email protected] on kontroll:
You are now logged in to "kontroll" as "[email protected]".
`[1:])
// We should have a macaroon, but no password, in the client store.
store := jujuclient.NewFileClientStore()
accountDetails, err := store.AccountDetails("kontroll")
c.Assert(err, jc.ErrorIsNil)
c.Assert(accountDetails.Password, gc.Equals, "")
// We should be able to login with the macaroon.
s.run(c, nil, "status")
}
示例11: TestUserInfoFormatJsonWithUsername
func (s *UserInfoCommandSuite) TestUserInfoFormatJsonWithUsername(c *gc.C) {
context, err := testing.RunCommand(c, s.NewShowUserCommand(), "foobar", "--format", "json")
c.Assert(err, jc.ErrorIsNil)
c.Assert(testing.Stdout(context), gc.Equals, `
{"user-name":"foobar","display-name":"Foo Bar","access":"login","date-created":"1981-02-27","last-connection":"2014-01-01"}
`[1:])
}
示例12: TestRunForMachineAndUnit
func (s *RunSuite) TestRunForMachineAndUnit(c *gc.C) {
mock := s.setupMockAPI()
machineResponse := mockResponse{
stdout: "megatron\n",
machineId: "0",
}
unitResponse := mockResponse{
stdout: "bumblebee",
machineId: "1",
unitId: "unit/0",
}
mock.setResponse("0", machineResponse)
mock.setResponse("unit/0", unitResponse)
unformatted := ConvertRunResults([]params.RunResult{
makeRunResult(machineResponse),
makeRunResult(unitResponse),
})
jsonFormatted, err := cmd.FormatJson(unformatted)
c.Assert(err, jc.ErrorIsNil)
context, err := testing.RunCommand(c, newRunCommand(),
"--format=json", "--machine=0", "--unit=unit/0", "hostname",
)
c.Assert(err, jc.ErrorIsNil)
c.Check(testing.Stdout(context), gc.Equals, string(jsonFormatted)+"\n")
}
示例13: TestServiceGet
func (s *cmdJujuSuite) TestServiceGet(c *gc.C) {
expected := `charm: dummy
service: dummy-service
settings:
outlook:
default: true
description: No default outlook.
type: string
skill-level:
default: true
description: A number indicating skill.
type: int
title:
default: true
description: A descriptive title used for the service.
type: string
value: My Title
username:
default: true
description: The name of the initial account (given admin permissions).
type: string
value: admin001
`
ch := s.AddTestingCharm(c, "dummy")
s.AddTestingService(c, "dummy-service", ch)
context, err := testing.RunCommand(c, service.NewGetCommand(), "dummy-service")
c.Assert(err, jc.ErrorIsNil)
c.Assert(testing.Stdout(context), gc.Equals, expected)
}
示例14: assertValidShow
func (s *ShowSuite) assertValidShow(c *gc.C, args []string, expected string) {
context, err := runShow(c, args)
c.Assert(err, jc.ErrorIsNil)
obtained := testing.Stdout(context)
c.Assert(obtained, gc.Matches, expected)
}
示例15: 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)
}