本文整理匯總了Golang中github.com/wallyworld/core/testing.RunCommand函數的典型用法代碼示例。如果您正苦於以下問題:Golang RunCommand函數的具體用法?Golang RunCommand怎麽用?Golang RunCommand使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RunCommand函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRemoveUser
func (s *RemoveUserSuite) TestRemoveUser(c *gc.C) {
_, err := testing.RunCommand(c, &AddUserCommand{}, []string{"foobar", "password"})
c.Assert(err, gc.IsNil)
_, err = testing.RunCommand(c, &RemoveUserCommand{}, []string{"foobar"})
c.Assert(err, gc.IsNil)
}
示例2: TestAddUser
func (s *AddUserSuite) TestAddUser(c *gc.C) {
_, err := testing.RunCommand(c, &AddUserCommand{}, []string{"foobar", "password"})
c.Assert(err, gc.IsNil)
_, err = testing.RunCommand(c, &AddUserCommand{}, []string{"foobar", "newpassword"})
c.Assert(err, gc.ErrorMatches, "Failed to create user: user already exists")
}
示例3: TestChangeAsCommandPair
func (s *SetEnvironmentSuite) TestChangeAsCommandPair(c *gc.C) {
_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"default-series=raring"})
c.Assert(err, gc.IsNil)
context, err := testing.RunCommand(c, &GetEnvironmentCommand{}, []string{"default-series"})
c.Assert(err, gc.IsNil)
output := strings.TrimSpace(testing.Stdout(context))
c.Assert(output, gc.Equals, "raring")
}
示例4: TestSettingWritesFile
func (*SwitchSimpleSuite) TestSettingWritesFile(c *gc.C) {
defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"erewhemos-2"})
c.Assert(err, gc.IsNil)
c.Assert(testing.Stdout(context), gc.Equals, "erewhemos -> erewhemos-2\n")
c.Assert(envcmd.ReadCurrentEnvironment(), gc.Equals, "erewhemos-2")
}
示例5: TestListEnvironmentsOSJujuEnvSet
func (*SwitchSimpleSuite) TestListEnvironmentsOSJujuEnvSet(c *gc.C) {
defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
os.Setenv("JUJU_ENV", "using-env")
context, err := testing.RunCommand(c, &SwitchCommand{}, []string{"--list"})
c.Assert(err, gc.IsNil)
c.Assert(testing.Stdout(context), gc.Equals, expectedEnvironments)
}
示例6: TestAllMachines
func (s *RunSuite) TestAllMachines(c *gc.C) {
mock := s.setupMockAPI()
mock.setMachinesAlive("0", "1")
response0 := mockResponse{
stdout: "megatron\n",
machineId: "0",
}
response1 := mockResponse{
error: "command timed out",
machineId: "1",
}
mock.setResponse("0", response0)
unformatted := ConvertRunResults([]params.RunResult{
makeRunResult(response0),
makeRunResult(response1),
})
jsonFormatted, err := cmd.FormatJson(unformatted)
c.Assert(err, gc.IsNil)
context, err := testing.RunCommand(c, &RunCommand{}, []string{
"--format=json", "--all", "hostname",
})
c.Assert(err, gc.IsNil)
c.Check(testing.Stdout(context), gc.Equals, string(jsonFormatted)+"\n")
}
示例7: TestShowsJujuEnv
func (*SwitchSimpleSuite) TestShowsJujuEnv(c *gc.C) {
defer testing.MakeFakeHome(c, testing.MultipleEnvConfig).Restore()
os.Setenv("JUJU_ENV", "using-env")
context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
c.Assert(err, gc.IsNil)
c.Assert(testing.Stdout(context), gc.Equals, "using-env\n")
}
示例8: 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, gc.IsNil)
context, err := testing.RunCommand(c, &RunCommand{}, []string{
"--format=json", "--machine=0", "--unit=unit/0", "hostname",
})
c.Assert(err, gc.IsNil)
c.Check(testing.Stdout(context), gc.Equals, string(jsonFormatted)+"\n")
}
示例9: TestResolved
func (s *retryProvisioningSuite) TestResolved(c *gc.C) {
m, err := s.State.AddOneMachine(state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobManageEnviron},
})
c.Assert(err, gc.IsNil)
err = m.SetStatus(params.StatusError, "broken", nil)
c.Assert(err, gc.IsNil)
_, err = s.State.AddOneMachine(state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
})
c.Assert(err, gc.IsNil)
for i, t := range resolvedMachineTests {
c.Logf("test %d: %v", i, t.args)
context, err := testing.RunCommand(c, &RetryProvisioningCommand{}, t.args)
if t.err != "" {
c.Check(err, gc.ErrorMatches, t.err)
continue
} else {
c.Check(err, gc.IsNil)
}
output := testing.Stderr(context)
stripped := strings.Replace(output, "\n", "", -1)
c.Check(stripped, gc.Equals, t.stdErr)
if t.args[0] == "0" {
status, info, data, err := m.Status()
c.Check(err, gc.IsNil)
c.Check(status, gc.Equals, params.StatusError)
c.Check(info, gc.Equals, "broken")
c.Check(data["transient"], jc.IsTrue)
}
}
}
示例10: TestUnsetEnvironment
func (s *UnsetEnvironmentSuite) TestUnsetEnvironment(c *gc.C) {
for _, t := range unsetEnvTests {
c.Logf("testing unset-env %v", t.args)
s.initConfig(c)
_, err := testing.RunCommand(c, &UnsetEnvironmentCommand{}, t.args)
if t.err != "" {
c.Assert(err, gc.ErrorMatches, t.err)
} else {
c.Assert(err, gc.IsNil)
}
if len(t.expected)+len(t.unexpected) != 0 {
stateConfig, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
for k, v := range t.expected {
vstate, ok := stateConfig.AllAttrs()[k]
c.Assert(ok, jc.IsTrue)
c.Assert(vstate, gc.Equals, v)
}
for _, k := range t.unexpected {
_, ok := stateConfig.AllAttrs()[k]
c.Assert(ok, jc.IsFalse)
}
}
}
}
示例11: TestChangeBooleanAttribute
func (s *SetEnvironmentSuite) TestChangeBooleanAttribute(c *gc.C) {
_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{"ssl-hostname-verification=false"})
c.Assert(err, gc.IsNil)
stateConfig, err := s.State.EnvironConfig()
c.Assert(err, gc.IsNil)
c.Assert(stateConfig.SSLHostnameVerification(), gc.Equals, false)
}
示例12: TestLogOutput
func (s *DebugLogSuite) TestLogOutput(c *gc.C) {
s.PatchValue(&getDebugLogAPI, func(envName string) (DebugLogAPI, error) {
return &fakeDebugLogAPI{log: "this is the log output"}, nil
})
ctx, err := testing.RunCommand(c, &DebugLogCommand{}, nil)
c.Assert(err, gc.IsNil)
c.Assert(testing.Stdout(ctx), gc.Equals, "this is the log output")
}
示例13: TestCurrentEnvironmentHasPrecidence
func (*SwitchSimpleSuite) TestCurrentEnvironmentHasPrecidence(c *gc.C) {
home := testing.MakeFakeHome(c, testing.MultipleEnvConfig)
defer home.Restore()
home.AddFiles(c, []testing.TestFile{{".juju/current-environment", "fubar"}})
context, err := testing.RunCommand(c, &SwitchCommand{}, nil)
c.Assert(err, gc.IsNil)
c.Assert(testing.Stdout(context), gc.Equals, "fubar\n")
}
示例14: TestJenvJsonFileOutput
func (s *AddUserSuite) TestJenvJsonFileOutput(c *gc.C) {
expected := `{"User":"foobar","Password":"password","state-servers":null,"ca-cert":""}
`
ctx, err := testing.RunCommand(c, &AddUserCommand{}, []string{"foobar", "password", "--format", "json"})
c.Assert(err, gc.IsNil)
stdout := ctx.Stdout.(*bytes.Buffer).String()
c.Assert(stdout, gc.DeepEquals, expected)
}
示例15: TestImmutableConfigValues
func (s *SetEnvironmentSuite) TestImmutableConfigValues(c *gc.C) {
for name, value := range immutableConfigTests {
param := fmt.Sprintf("%s=%s", name, value)
_, err := testing.RunCommand(c, &SetEnvironmentCommand{}, []string{param})
errorPattern := fmt.Sprintf("cannot change %s from .* to [\"]?%v[\"]?", name, value)
c.Assert(err, gc.ErrorMatches, errorPattern)
}
}