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


Golang testing.InitCommand函数代码示例

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


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


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