本文整理汇总了Golang中github.com/wallyworld/core/testing.InitCommand函数的典型用法代码示例。如果您正苦于以下问题:Golang InitCommand函数的具体用法?Golang InitCommand怎么用?Golang InitCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InitCommand函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestDestroyEnvironmentCommandConfirmationFlag
func (*destroyEnvSuite) TestDestroyEnvironmentCommandConfirmationFlag(c *gc.C) {
com := new(DestroyEnvironmentCommand)
c.Check(coretesting.InitCommand(com, []string{"dummyenv"}), gc.IsNil)
c.Check(com.assumeYes, gc.Equals, false)
com = new(DestroyEnvironmentCommand)
c.Check(coretesting.InitCommand(com, []string{"dummyenv", "-y"}), gc.IsNil)
c.Check(com.assumeYes, gc.Equals, true)
com = new(DestroyEnvironmentCommand)
c.Check(coretesting.InitCommand(com, []string{"dummyenv", "--yes"}), gc.IsNil)
c.Check(com.assumeYes, gc.Equals, true)
}
开发者ID:jameinel,项目名称:core,代码行数:13,代码来源:destroyenvironment_test.go
示例2: CheckAgentCommand
// CheckAgentCommand is a utility function for verifying that common agent
// options are handled by a Command; it returns an instance of that
// command pre-parsed, with any mandatory flags added.
func CheckAgentCommand(c *gc.C, create acCreator, args []string) cmd.Command {
com, conf := create()
err := coretesting.InitCommand(com, args)
c.Assert(conf.dataDir, gc.Equals, "/var/lib/juju")
badArgs := append(args, "--data-dir", "")
com, conf = create()
err = coretesting.InitCommand(com, badArgs)
c.Assert(err, gc.ErrorMatches, "--data-dir option must be set")
args = append(args, "--data-dir", "jd")
com, conf = create()
c.Assert(coretesting.InitCommand(com, args), gc.IsNil)
c.Assert(conf.dataDir, gc.Equals, "jd")
return com
}
开发者ID:jameinel,项目名称:core,代码行数:18,代码来源:agent_test.go
示例3: TestInitErrors
func (s *DeploySuite) TestInitErrors(c *gc.C) {
for i, t := range initErrorTests {
c.Logf("test %d", i)
err := coretesting.InitCommand(&DeployCommand{}, t.args)
c.Assert(err, gc.ErrorMatches, t.err)
}
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:deploy_test.go
示例4: TestInit
func (s *DeleteCharmSuite) TestInit(c *gc.C) {
config := &DeleteCharmCommand{}
err := testing.InitCommand(config, []string{"--config", "/etc/charmd.conf", "--url", "cs:go"})
c.Assert(err, gc.IsNil)
c.Assert(config.ConfigPath, gc.Equals, "/etc/charmd.conf")
c.Assert(config.Url, gc.Equals, "cs:go")
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:deletecharm_test.go
示例5: TestInitErrors
func (s *ValidateToolsMetadataSuite) TestInitErrors(c *gc.C) {
for i, t := range validateInitToolsErrorTests {
c.Logf("test %d", i)
err := coretesting.InitCommand(&ValidateToolsMetadataCommand{}, t.args)
c.Check(err, gc.ErrorMatches, t.err)
}
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:validatetoolsmetadata_test.go
示例6: TestInitErrors
func (s *AddUnitSuite) TestInitErrors(c *gc.C) {
for i, t := range initAddUnitErrorTests {
c.Logf("test %d", i)
err := testing.InitCommand(&AddUnitCommand{}, t.args)
c.Check(err, gc.ErrorMatches, t.err)
}
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:addunit_test.go
示例7: testInit
// testInit checks that a command initialises correctly
// with the given set of arguments.
func testInit(c *gc.C, com cmd.Command, args []string, errPat string) {
err := coretesting.InitCommand(com, args)
if errPat != "" {
c.Assert(err, gc.ErrorMatches, errPat)
} else {
c.Assert(err, gc.IsNil)
}
}
开发者ID:jameinel,项目名称:core,代码行数:10,代码来源:cmd_test.go
示例8: TestBadArgs
func (s *PortsSuite) TestBadArgs(c *gc.C) {
for _, name := range []string{"open-port", "close-port"} {
for _, t := range badPortsTests {
hctx := s.GetHookContext(c, -1, "")
com, err := jujuc.NewCommand(hctx, name)
c.Assert(err, gc.IsNil)
err = testing.InitCommand(com, t.args)
c.Assert(err, gc.ErrorMatches, t.err)
}
}
}
开发者ID:jameinel,项目名称:core,代码行数:11,代码来源:ports_test.go
示例9: TestWrongArgs
func (*RunTestSuite) TestWrongArgs(c *gc.C) {
for i, test := range []struct {
title string
args []string
errMatch string
unit string
commands string
avoidContext bool
}{{
title: "no args",
errMatch: "missing unit-name",
}, {
title: "one arg",
args: []string{"foo"},
errMatch: "missing commands",
}, {
title: "more than two arg",
args: []string{"foo", "bar", "baz"},
errMatch: `unrecognized args: \["baz"\]`,
}, {
title: "unit and command assignment",
args: []string{"unit-name", "command"},
unit: "unit-name",
commands: "command",
}, {
title: "unit id converted to tag",
args: []string{"foo/1", "command"},
unit: "unit-foo-1",
commands: "command",
}, {
title: "execute not in a context",
args: []string{"--no-context", "command"},
commands: "command",
avoidContext: true,
},
} {
c.Logf("\n%d: %s", i, test.title)
runCommand := &RunCommand{}
err := testing.InitCommand(runCommand, test.args)
if test.errMatch == "" {
c.Assert(err, gc.IsNil)
c.Assert(runCommand.unit, gc.Equals, test.unit)
c.Assert(runCommand.commands, gc.Equals, test.commands)
c.Assert(runCommand.noContext, gc.Equals, test.avoidContext)
} else {
c.Assert(err, gc.ErrorMatches, test.errMatch)
}
}
}
开发者ID:jameinel,项目名称:core,代码行数:49,代码来源:run_test.go
示例10: TestReadConfig
func (s *ConfigSuite) TestReadConfig(c *gc.C) {
confDir := c.MkDir()
f, err := os.Create(path.Join(confDir, "charmd.conf"))
c.Assert(err, gc.IsNil)
cfgPath := f.Name()
{
defer f.Close()
fmt.Fprint(f, testConfig)
}
config := &SomeConfigCommand{}
args := []string{"--config", cfgPath}
err = testing.InitCommand(config, args)
c.Assert(err, gc.IsNil)
_, err = testing.RunCommand(c, config, args)
c.Assert(err, gc.IsNil)
c.Assert(config.Config, gc.NotNil)
c.Assert(config.Config.MongoURL, gc.Equals, "localhost:23456")
}
开发者ID:jameinel,项目名称:core,代码行数:20,代码来源:config_test.go
示例11: TestInit
func (s *RelationSetSuite) TestInit(c *gc.C) {
for i, t := range relationSetInitTests {
c.Logf("test %d", i)
hctx := s.GetHookContext(c, t.ctxrelid, "")
com, err := jujuc.NewCommand(hctx, "relation-set")
c.Assert(err, gc.IsNil)
err = testing.InitCommand(com, t.args)
if t.err == "" {
c.Assert(err, gc.IsNil)
rset := com.(*jujuc.RelationSetCommand)
c.Assert(rset.RelationId, gc.Equals, t.relid)
settings := t.settings
if settings == nil {
settings = map[string]string{}
}
c.Assert(rset.Settings, gc.DeepEquals, settings)
} else {
c.Assert(err, gc.ErrorMatches, t.err)
}
}
}
开发者ID:jameinel,项目名称:core,代码行数:21,代码来源:relation-set_test.go
示例12: initBootstrapCommand
func (s *BootstrapSuite) initBootstrapCommand(c *gc.C, jobs []params.MachineJob, args ...string) (machineConf agent.ConfigSetterWriter, cmd *BootstrapCommand, err error) {
if len(jobs) == 0 {
// Add default jobs.
jobs = []params.MachineJob{
params.JobManageEnviron, params.JobHostUnits,
}
}
// NOTE: the old test used an equivalent of the NewAgentConfig, but it
// really should be using NewStateMachineConfig.
agentParams := agent.AgentConfigParams{
LogDir: s.logDir,
DataDir: s.dataDir,
Jobs: jobs,
Tag: "machine-0",
UpgradedToVersion: version.Current.Number,
Password: testPasswordHash(),
Nonce: state.BootstrapNonce,
StateAddresses: []string{testing.MgoServer.Addr()},
APIAddresses: []string{"0.1.2.3:1234"},
CACert: testing.CACert,
Values: map[string]string{agent.Namespace: "foobar"},
}
servingInfo := params.StateServingInfo{
Cert: "some cert",
PrivateKey: "some key",
APIPort: 3737,
StatePort: testing.MgoServer.Port(),
}
machineConf, err = agent.NewStateMachineConfig(agentParams, servingInfo)
c.Assert(err, gc.IsNil)
err = machineConf.Write()
c.Assert(err, gc.IsNil)
cmd = &BootstrapCommand{}
err = testing.InitCommand(cmd, append([]string{"--data-dir", s.dataDir}, args...))
return machineConf, cmd, err
}
开发者ID:jameinel,项目名称:core,代码行数:39,代码来源:bootstrap_test.go
示例13: runCommand
func runCommand(ctx *cmd.Context, com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) {
if ctx == nil {
panic("ctx == nil")
}
errc = make(chan error, 1)
opc = make(chan dummy.Operation, 200)
dummy.Listen(opc)
go func() {
// signal that we're done with this ops channel.
defer dummy.Listen(nil)
err := coretesting.InitCommand(com, args)
if err != nil {
errc <- err
return
}
err = com.Run(ctx)
errc <- err
}()
return
}
开发者ID:jameinel,项目名称:core,代码行数:22,代码来源:cmd_test.go
示例14: TestUnknownArg
func (s *OwnerGetSuite) TestUnknownArg(c *gc.C) {
com := s.createCommand(c)
err := testing.InitCommand(com, []string{"tag", "blah"})
c.Assert(err, gc.ErrorMatches, `unrecognized args: \["blah"\]`)
}
开发者ID:jameinel,项目名称:core,代码行数:5,代码来源:owner-get_test.go
示例15: TestUnknownSetting
func (s *OwnerGetSuite) TestUnknownSetting(c *gc.C) {
com := s.createCommand(c)
err := testing.InitCommand(com, []string{"unknown-setting"})
c.Assert(err, gc.ErrorMatches, `unknown setting "unknown-setting"`)
}
开发者ID:jameinel,项目名称:core,代码行数:5,代码来源:owner-get_test.go
示例16: initDefenestrate
func initDefenestrate(args []string) (*cmd.SuperCommand, *TestCommand, error) {
jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest"})
tc := &TestCommand{Name: "defenestrate"}
jc.Register(tc)
return jc, tc, testing.InitCommand(jc, args)
}
开发者ID:jameinel,项目名称:core,代码行数:6,代码来源:supercommand_test.go
示例17: TestArgParsing
func (s *DebugLogSuite) TestArgParsing(c *gc.C) {
for i, test := range []struct {
args []string
expected api.DebugLogParams
errMatch string
}{
{
expected: api.DebugLogParams{
Backlog: 10,
},
}, {
args: []string{"-n0"},
}, {
args: []string{"--lines=50"},
expected: api.DebugLogParams{
Backlog: 50,
},
}, {
args: []string{"-l", "foo"},
errMatch: `level value "foo" is not one of "TRACE", "DEBUG", "INFO", "WARNING", "ERROR"`,
}, {
args: []string{"--level=INFO"},
expected: api.DebugLogParams{
Backlog: 10,
Level: loggo.INFO,
},
}, {
args: []string{"--include", "machine-1", "-i", "machine-2"},
expected: api.DebugLogParams{
IncludeEntity: []string{"machine-1", "machine-2"},
Backlog: 10,
},
}, {
args: []string{"--exclude", "machine-1", "-x", "machine-2"},
expected: api.DebugLogParams{
ExcludeEntity: []string{"machine-1", "machine-2"},
Backlog: 10,
},
}, {
args: []string{"--include-module", "juju.foo", "--include-module", "unit"},
expected: api.DebugLogParams{
IncludeModule: []string{"juju.foo", "unit"},
Backlog: 10,
},
}, {
args: []string{"--exclude-module", "juju.foo", "--exclude-module", "unit"},
expected: api.DebugLogParams{
ExcludeModule: []string{"juju.foo", "unit"},
Backlog: 10,
},
}, {
args: []string{"--replay"},
expected: api.DebugLogParams{
Backlog: 10,
Replay: true,
},
}, {
args: []string{"--limit", "100"},
expected: api.DebugLogParams{
Backlog: 10,
Limit: 100,
},
},
} {
c.Logf("test %v", i)
command := &DebugLogCommand{}
err := testing.InitCommand(command, test.args)
if test.errMatch == "" {
c.Check(err, gc.IsNil)
c.Check(command.params, jc.DeepEquals, test.expected)
} else {
c.Check(err, gc.ErrorMatches, test.errMatch)
}
}
}
开发者ID:jameinel,项目名称:core,代码行数:75,代码来源:debuglog_test.go
示例18: initExposeCommand
func initExposeCommand(args ...string) (*ExposeCommand, error) {
com := &ExposeCommand{}
return com, coretesting.InitCommand(com, args)
}
开发者ID:jameinel,项目名称:core,代码行数:4,代码来源:cmd_test.go
示例19: ParseAgentCommand
// ParseAgentCommand is a utility function that inserts the always-required args
// before parsing an agent command and returning the result.
func ParseAgentCommand(ac cmd.Command, args []string) error {
common := []string{
"--data-dir", "jd",
}
return coretesting.InitCommand(ac, append(common, args...))
}
开发者ID:jameinel,项目名称:core,代码行数:8,代码来源:agent_test.go
示例20: TestUpgradeJuju
func (s *UpgradeJujuSuite) TestUpgradeJuju(c *gc.C) {
s.PatchValue(&sync.BuildToolsTarball, s.getMockBuildTools(c))
oldVersion := version.Current
defer func() {
version.Current = oldVersion
}()
for i, test := range upgradeJujuTests {
c.Logf("\ntest %d: %s", i, test.about)
s.Reset(c)
// Set up apparent CLI version and initialize the command.
version.Current = version.MustParseBinary(test.currentVersion)
com := &UpgradeJujuCommand{}
if err := coretesting.InitCommand(com, test.args); err != nil {
if test.expectInitErr != "" {
c.Check(err, gc.ErrorMatches, test.expectInitErr)
} else {
c.Check(err, gc.IsNil)
}
continue
}
// Set up state and environ, and run the command.
toolsDir := c.MkDir()
updateAttrs := map[string]interface{}{
"agent-version": test.agentVersion,
"tools-metadata-url": "file://" + toolsDir,
}
err := s.State.UpdateEnvironConfig(updateAttrs, nil, nil)
c.Assert(err, gc.IsNil)
versions := make([]version.Binary, len(test.tools))
for i, v := range test.tools {
versions[i] = version.MustParseBinary(v)
}
if len(versions) > 0 {
envtesting.MustUploadFakeToolsVersions(s.Conn.Environ.Storage(), versions...)
stor, err := filestorage.NewFileStorageWriter(toolsDir)
c.Assert(err, gc.IsNil)
envtesting.MustUploadFakeToolsVersions(stor, versions...)
}
err = com.Run(coretesting.Context(c))
if test.expectErr != "" {
c.Check(err, gc.ErrorMatches, test.expectErr)
continue
} else if !c.Check(err, gc.IsNil) {
continue
}
// Check expected changes to environ/state.
cfg, err := s.State.EnvironConfig()
c.Check(err, gc.IsNil)
agentVersion, ok := cfg.AgentVersion()
c.Check(ok, gc.Equals, true)
c.Check(agentVersion, gc.Equals, version.MustParse(test.expectVersion))
for _, uploaded := range test.expectUploaded {
// Substitute latest LTS for placeholder in expected series for uploaded tools
uploaded = strings.Replace(uploaded, "%LTS%", config.LatestLtsSeries(), 1)
vers := version.MustParseBinary(uploaded)
r, err := storage.Get(s.Conn.Environ.Storage(), envtools.StorageName(vers))
if !c.Check(err, gc.IsNil) {
continue
}
data, err := ioutil.ReadAll(r)
r.Close()
c.Check(err, gc.IsNil)
expectContent := version.Current
expectContent.Number = agentVersion
checkToolsContent(c, data, "jujud contents "+expectContent.String())
}
}
}
开发者ID:jameinel,项目名称:core,代码行数:75,代码来源:upgradejuju_test.go
注:本文中的github.com/wallyworld/core/testing.InitCommand函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论