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


Golang commandmocker.Ran函数代码示例

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


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

示例1: TestHandleMessageWithUnits

func (s *ELBSuite) TestHandleMessageWithUnits(c *gocheck.C) {
	id1 := s.server.NewInstance()
	id2 := s.server.NewInstance()
	defer s.server.RemoveInstance(id1)
	defer s.server.RemoveInstance(id2)
	app := testing.NewFakeApp("symfonia", "python", 1)
	router, err := Router()
	c.Assert(err, gocheck.IsNil)
	router.AddBackend(app.GetName())
	c.Assert(err, gocheck.IsNil)
	defer router.RemoveBackend(app.GetName())
	output := strings.Replace(simpleCollectOutput, "i-00004444", id1, -1)
	output = strings.Replace(output, "i-00004445", id2, -1)
	tmpdir, err := commandmocker.Add("juju", output)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	msg := queue.Message{
		Action: addUnitToLoadBalancer,
		Args:   []string{"symfonia", "symfonia/0", "symfonia/1"},
	}
	handle(&msg)
	resp, err := s.client.DescribeLoadBalancers(app.GetName())
	c.Assert(err, gocheck.IsNil)
	c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1)
	instances := resp.LoadBalancerDescriptions[0].Instances
	c.Assert(instances, gocheck.HasLen, 2)
	ids := []string{instances[0].InstanceId, instances[1].InstanceId}
	sort.Strings(ids)
	want := []string{id1, id2}
	sort.Strings(want)
	c.Assert(ids, gocheck.DeepEquals, want)
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:33,代码来源:queue_test.go

示例2: TestReadMessageWithLaunchJSON

func (s *S) TestReadMessageWithLaunchJSON(c *check.C) {
	cmd, err := commandmocker.Add("sudo", "service nginx reload")
	c.Assert(err, check.IsNil)
	defer commandmocker.Remove(cmd)

	payload := `{"TopicArn":"arn:test","Message":` +
		`"{\"AutoScalingGroupARN\":\"arn:asg-test\",\"Event\":\"autoscaling:EC2_INSTANCE_LAUNCH\",` +
		`\"EC2InstanceId\":\"%s\"}"}`
	b := strings.NewReader(fmt.Sprintf(payload, s.instance_ids[0]))
	recorder, request := newRequest("POST", "/", b, c)
	readMessage(recorder, request)
	body := readBody(recorder.Body, c)
	c.Assert(body, check.Equals, fmt.Sprintf(`Added instance "%s".`, s.instance_ids[0]))
	c.Assert(recorder.Code, check.Equals, 200)

	// Check upstreams file
	upstream := Config.Upstreams[0]
	content, err := ioutil.ReadFile(upstream.File)
	c.Assert(err, check.IsNil)
	serverLine := fmt.Sprintf("server %s.internal.invalid:80 max_fails=3 fail_timeout=60s; # %s\n", s.instance_ids[0], s.instance_ids[0])
	c.Assert(string(content), check.Equals, fmt.Sprintf("upstream %s {\n  %s}\n", upstream.Name, serverLine))

	// Check run NGINX reload
	c.Assert(commandmocker.Ran(cmd), check.Equals, true)
}
开发者ID:rochacon,项目名称:elastic-nginx,代码行数:25,代码来源:elnginx_test.go

示例3: TestReadMessageWithTerminateJSON

func (s *S) TestReadMessageWithTerminateJSON(c *check.C) {
	cmd, err := commandmocker.Add("sudo", "service nginx reload")
	c.Assert(err, check.IsNil)
	defer commandmocker.Remove(cmd)

	// Setup instance file
	u := Config.Upstreams[0]
	instance := &ec2.Instance{InstanceId: s.instance_ids[0], PrivateDNSName: "test.internal"}
	if err := addInstance(u, instance); err != nil {
		c.Error(err)
	}

	payload := `{"TopicArn":"arn:test","Message":
	"{\"AutoScalingGroupARN\":\"arn:asg-test\",\"Event\":\"autoscaling:EC2_INSTANCE_TERMINATE\",\"EC2InstanceId\":\"%s\"}"}`
	b := strings.NewReader(fmt.Sprintf(payload, s.instance_ids[0]))
	recorder, request := newRequest("POST", "/", b, c)
	readMessage(recorder, request)
	body := readBody(recorder.Body, c)
	c.Assert(body, check.Equals, fmt.Sprintf(`Removed instance "%s".`, s.instance_ids[0]))
	c.Assert(recorder.Code, check.Equals, 200)

	// Check upstreams file
	content, err := ioutil.ReadFile(u.File)
	c.Assert(err, check.IsNil)
	c.Assert(string(content), check.Equals, fmt.Sprintf("upstream %s {\n}\n", u.Name))

	// Check run NGINX reload
	c.Assert(commandmocker.Ran(cmd), check.Equals, true)
}
开发者ID:rochacon,项目名称:elastic-nginx,代码行数:29,代码来源:elnginx_test.go

示例4: TestNewBareShouldCreateADir

func (s *S) TestNewBareShouldCreateADir(c *gocheck.C) {
	dir, err := commandmocker.Add("git", "$*")
	c.Check(err, gocheck.IsNil)
	defer commandmocker.Remove(dir)
	err = newBare("myBare")
	c.Assert(err, gocheck.IsNil)
	c.Assert(commandmocker.Ran(dir), gocheck.Equals, true)
}
开发者ID:rfloriano,项目名称:gandalf,代码行数:8,代码来源:git_test.go

示例5: TestCollectStatusDirtyOutput

func (s *S) TestCollectStatusDirtyOutput(c *gocheck.C) {
	server, url := badGatewayServer()
	defer server.Close()
	tmpdir, err := commandmocker.Add("juju", generateDirtyOutput(url))
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	expected := []provision.Unit{
		{
			Name:       "as_i_rise/0",
			AppName:    "as_i_rise",
			Type:       "django",
			Machine:    105,
			InstanceId: "i-00000439",
			Ip:         url,
			Status:     provision.StatusUnreachable,
		},
		{
			Name:       "the_infanta/1",
			AppName:    "the_infanta",
			Type:       "gunicorn",
			Machine:    107,
			InstanceId: "i-0000043e",
			Ip:         url,
			Status:     provision.StatusBuilding,
		},
	}
	p := JujuProvisioner{}
	units, err := p.CollectStatus()
	c.Assert(err, gocheck.IsNil)
	cp := make([]provision.Unit, len(units))
	copy(cp, units)
	if cp[0].Type == "gunicorn" {
		cp[0], cp[1] = cp[1], cp[0]
	}
	c.Assert(cp, gocheck.DeepEquals, expected)
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
	var wg sync.WaitGroup
	wg.Add(1)
	collection := p.unitsCollection()
	defer collection.Close()
	go func() {
		q := bson.M{"_id": bson.M{"$in": []string{"as_i_rise/0", "the_infanta/1"}}}
		for {
			if n, _ := collection.Find(q).Count(); n == 2 {
				break
			}
			runtime.Gosched()
		}
		collection.Remove(q)
		wg.Done()
	}()
	wg.Wait()
}
开发者ID:rochacon,项目名称:tsuru,代码行数:53,代码来源:collector_test.go

示例6: TestNewShouldCreateNewGitBareRepository

func (s *S) TestNewShouldCreateNewGitBareRepository(c *gocheck.C) {
	tmpdir, err := commandmocker.Add("git", "$*")
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	_, err = New("myRepo", []string{"pumpkin"}, true)
	c.Assert(err, gocheck.IsNil)
	conn, err := db.Conn()
	c.Assert(err, gocheck.IsNil)
	defer conn.Close()
	defer conn.Repository().Remove(bson.M{"_id": "myRepo"})
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
}
开发者ID:kenpu,项目名称:gandalf,代码行数:12,代码来源:repository_test.go

示例7: TestExecuteWithoutArgs

func (s *S) TestExecuteWithoutArgs(c *gocheck.C) {
	tmpdir, err := commandmocker.Add("ls", "ok")
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	var e OsExecutor
	var b bytes.Buffer
	err = e.Execute("ls", nil, nil, &b, &b)
	c.Assert(err, gocheck.IsNil)
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
	c.Assert(commandmocker.Parameters(tmpdir), gocheck.IsNil)
	c.Assert(b.String(), gocheck.Equals, "ok")
}
开发者ID:ningjh,项目名称:tsuru,代码行数:12,代码来源:exec_test.go

示例8: TestRemoveUnitUnknownByJuju

func (s *S) TestRemoveUnitUnknownByJuju(c *gocheck.C) {
	output := `013-01-11 20:02:07,883 INFO Connecting to environment...
2013-01-11 20:02:10,147 INFO Connected to environment.
2013-01-11 20:02:10,160 ERROR Service unit 'two/2' was not found`
	tmpdir, err := commandmocker.Error("juju", output, 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("two", "rush", 3)
	p := JujuProvisioner{}
	err = p.RemoveUnit(app, "two/2")
	c.Assert(err, gocheck.IsNil)
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
}
开发者ID:renanoliveira,项目名称:tsuru,代码行数:13,代码来源:provisioner_test.go

示例9: TestCollectStatusFailure

func (s *S) TestCollectStatusFailure(c *gocheck.C) {
	tmpdir, err := commandmocker.Error("juju", "juju failed", 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	p := JujuProvisioner{}
	_, err = p.CollectStatus()
	c.Assert(err, gocheck.NotNil)
	pErr, ok := err.(*provision.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(pErr.Reason, gocheck.Equals, "juju failed")
	c.Assert(pErr.Err.Error(), gocheck.Equals, "exit status 1")
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:13,代码来源:collector_test.go

示例10: TestExecute

func (s *S) TestExecute(c *gocheck.C) {
	tmpdir, err := commandmocker.Add("ls", "ok")
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	var e OsExecutor
	var b bytes.Buffer
	err = e.Execute("ls", []string{"-lsa"}, nil, &b, &b)
	c.Assert(err, gocheck.IsNil)
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
	expected := []string{"-lsa"}
	c.Assert(commandmocker.Parameters(tmpdir), gocheck.DeepEquals, expected)
	c.Assert(b.String(), gocheck.Equals, "ok")
}
开发者ID:ningjh,项目名称:tsuru,代码行数:13,代码来源:exec_test.go

示例11: TestNewBareShouldNotPassTemplateOptionWhenItsNotSetInConfig

func (s *S) TestNewBareShouldNotPassTemplateOptionWhenItsNotSetInConfig(c *gocheck.C) {
	config.Unset("git:bare:template")
	bareLocation, err := config.GetString("git:bare:location")
	c.Assert(err, gocheck.IsNil)
	barePath := path.Join(bareLocation, "foo.git")
	dir, err := commandmocker.Add("git", "$*")
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(dir)
	err = newBare("foo")
	c.Assert(err, gocheck.IsNil)
	c.Assert(commandmocker.Ran(dir), gocheck.Equals, true)
	expected := fmt.Sprintf("init %s --bare", barePath)
	c.Assert(commandmocker.Output(dir), gocheck.Equals, expected)
}
开发者ID:rfloriano,项目名称:gandalf,代码行数:14,代码来源:git_test.go

示例12: TestNewBareShouldPassTemplateOptionWhenItExistsOnConfig

func (s *S) TestNewBareShouldPassTemplateOptionWhenItExistsOnConfig(c *check.C) {
	bareTemplate := "/var/templates"
	bareLocation, err := config.GetString("git:bare:location")
	config.Set("git:bare:template", bareTemplate)
	defer config.Unset("git:bare:template")
	barePath := path.Join(bareLocation, "foo.git")
	dir, err := commandmocker.Add("git", "$*")
	c.Assert(err, check.IsNil)
	defer commandmocker.Remove(dir)
	err = newBare("foo")
	c.Assert(err, check.IsNil)
	c.Assert(commandmocker.Ran(dir), check.Equals, true)
	expected := fmt.Sprintf("init %s --bare --template=%s", barePath, bareTemplate)
	c.Assert(commandmocker.Output(dir), check.Equals, expected)
}
开发者ID:ricardodani,项目名称:gandalf,代码行数:15,代码来源:git_test.go

示例13: TestExecuteActionShouldNotCallSSH_ORIGINAL_COMMANDWhenRepositoryDoesNotExists

func (s *S) TestExecuteActionShouldNotCallSSH_ORIGINAL_COMMANDWhenRepositoryDoesNotExists(c *gocheck.C) {
	dir, err := commandmocker.Add("git-receive-pack", "$*")
	c.Check(err, gocheck.IsNil)
	defer commandmocker.Remove(dir)
	os.Args = []string{"gandalf", s.user.Name}
	os.Setenv("SSH_ORIGINAL_COMMAND", "git-receive-pack 'ghostapp.git'")
	defer func() {
		os.Args = []string{}
		os.Setenv("SSH_ORIGINAL_COMMAND", "")
	}()
	stdout := &bytes.Buffer{}
	errorMsg := "You don't have access to write in this repository."
	executeAction(hasWritePermission, errorMsg, stdout)
	c.Assert(commandmocker.Ran(dir), gocheck.Equals, false)
}
开发者ID:heynemann,项目名称:gandalf,代码行数:15,代码来源:gandalf_test.go

示例14: TestInstanceMachineHealWhenEverythingIsOk

func (s *S) TestInstanceMachineHealWhenEverythingIsOk(c *gocheck.C) {
	fexec := &etesting.FakeExecutor{}
	setExecut(fexec)
	defer setExecut(nil)
	jujuTmpdir, err := commandmocker.Add("juju", collectOutput)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(jujuTmpdir)
	h := instanceMachineHealer{}
	err = h.Heal()
	c.Assert(err, gocheck.IsNil)
	args := []string{
		"status", // for juju status that gets the output
	}
	c.Assert(commandmocker.Ran(jujuTmpdir), gocheck.Equals, true)
	c.Assert(commandmocker.Parameters(jujuTmpdir), gocheck.DeepEquals, args)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:16,代码来源:healer_test.go

示例15: TestExecuteWithoutArgs

func (s *S) TestExecuteWithoutArgs(c *gocheck.C) {
	tmpdir, err := commandmocker.Add("ls", "ok")
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	var e OsExecutor
	var b bytes.Buffer
	opts := ExecuteOptions{
		Cmd:    "ls",
		Stdout: &b,
		Stderr: &b,
	}
	err = e.Execute(opts)
	c.Assert(err, gocheck.IsNil)
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
	c.Assert(commandmocker.Parameters(tmpdir), gocheck.IsNil)
	c.Assert(b.String(), gocheck.Equals, "ok")
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:17,代码来源:exec_test.go


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