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


Golang testing.NewFakeApp函数代码示例

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


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

示例1: TestSwap

func (s *ELBSuite) TestSwap(c *gocheck.C) {
	var p JujuProvisioner
	app1 := testing.NewFakeApp("app1", "python", 1)
	app2 := testing.NewFakeApp("app2", "python", 1)
	id1 := s.server.NewInstance()
	defer s.server.RemoveInstance(id1)
	id2 := s.server.NewInstance()
	defer s.server.RemoveInstance(id2)
	router, err := Router()
	c.Assert(err, gocheck.IsNil)
	err = router.AddBackend(app1.GetName())
	c.Assert(err, gocheck.IsNil)
	defer router.RemoveBackend(app1.GetName())
	err = router.AddRoute(app1.GetName(), id1)
	c.Assert(err, gocheck.IsNil)
	err = router.AddBackend(app2.GetName())
	c.Assert(err, gocheck.IsNil)
	defer router.RemoveBackend(app2.GetName())
	err = router.AddRoute(app2.GetName(), id2)
	c.Assert(err, gocheck.IsNil)
	err = p.Swap(app1, app2)
	c.Assert(err, gocheck.IsNil)
	app2Routes, err := router.Routes(app2.GetName())
	c.Assert(err, gocheck.IsNil)
	c.Assert(app2Routes, gocheck.DeepEquals, []string{id2})
	app1Routes, err := router.Routes(app1.GetName())
	c.Assert(err, gocheck.IsNil)
	c.Assert(app1Routes, gocheck.DeepEquals, []string{id1})
	addr, err := router.Addr(app1.GetName())
	c.Assert(err, gocheck.IsNil)
	c.Assert(addr, gocheck.Equals, "app2-some-aws-stuff.us-east-1.elb.amazonaws.com")
	addr, err = router.Addr(app2.GetName())
	c.Assert(err, gocheck.IsNil)
	c.Assert(addr, gocheck.Equals, "app1-some-aws-stuff.us-east-1.elb.amazonaws.com")
}
开发者ID:renanoliveira,项目名称:tsuru,代码行数:35,代码来源:provisioner_test.go

示例2: TestSwap

func (s *S) TestSwap(c *gocheck.C) {
	var p dockerProvisioner
	app1 := testing.NewFakeApp("app1", "python", 1)
	app2 := testing.NewFakeApp("app2", "python", 1)
	rtesting.FakeRouter.AddBackend(app1.GetName())
	rtesting.FakeRouter.AddRoute(app1.GetName(), "127.0.0.1")
	rtesting.FakeRouter.AddBackend(app2.GetName())
	rtesting.FakeRouter.AddRoute(app2.GetName(), "127.0.0.2")
	err := p.Swap(app1, app2)
	c.Assert(err, gocheck.IsNil)
	c.Assert(rtesting.FakeRouter.HasBackend(app1.GetName()), gocheck.Equals, true)
	c.Assert(rtesting.FakeRouter.HasBackend(app2.GetName()), gocheck.Equals, true)
	c.Assert(rtesting.FakeRouter.HasRoute(app2.GetName(), "127.0.0.1"), gocheck.Equals, true)
	c.Assert(rtesting.FakeRouter.HasRoute(app1.GetName(), "127.0.0.2"), gocheck.Equals, true)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:15,代码来源:provisioner_test.go

示例3: TestSetEnvironVariablesToAppBackward

func (s *S) TestSetEnvironVariablesToAppBackward(c *gocheck.C) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(`{"DATABASE_USER":"root","DATABASE_PASSWORD":"s3cr3t"}`))
	}))
	defer ts.Close()
	service := Service{Name: "mysql", Endpoint: map[string]string{"production": ts.URL}}
	err := service.Create()
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Services().RemoveId(service.Name)
	si := ServiceInstance{
		Name:        "my-mysql",
		ServiceName: "mysql",
		Teams:       []string{s.team.Name},
	}
	err = si.Create()
	c.Assert(err, gocheck.IsNil)
	defer s.conn.ServiceInstances().RemoveId(si.Name)
	a := testing.NewFakeApp("myapp", "static", 1)
	ctx := action.FWContext{
		Params: []interface{}{a, si},
	}
	r, err := setEnvironVariablesToApp.Forward(ctx)
	c.Assert(err, gocheck.IsNil)
	bwCtx := action.BWContext{
		Params:   []interface{}{a},
		FWResult: r,
	}
	setEnvironVariablesToApp.Backward(bwCtx)
	c.Assert(a.Envs(), gocheck.DeepEquals, map[string]bind.EnvVar{})
}
开发者ID:ningjh,项目名称:tsuru,代码行数:30,代码来源:actions_test.go

示例4: TestContainerCreate

func (s *S) TestContainerCreate(c *gocheck.C) {
	app := testing.NewFakeApp("app-name", "brainfuck", 1)
	app.Memory = 15
	rtesting.FakeRouter.AddBackend(app.GetName())
	defer rtesting.FakeRouter.RemoveBackend(app.GetName())
	dockerCluster().PullImage(
		docker.PullImageOptions{Repository: "tsuru/brainfuck"},
		docker.AuthConfiguration{},
	)
	cont := container{Name: "myName", AppName: app.GetName(), Type: app.GetPlatform(), Status: "created"}
	err := cont.create(app, getImage(app), []string{"docker", "run"})
	c.Assert(err, gocheck.IsNil)
	defer s.removeTestContainer(&cont)
	c.Assert(cont.ID, gocheck.Not(gocheck.Equals), "")
	c.Assert(cont, gocheck.FitsTypeOf, container{})
	c.Assert(cont.AppName, gocheck.Equals, app.GetName())
	c.Assert(cont.Type, gocheck.Equals, app.GetPlatform())
	u, _ := url.Parse(s.server.URL())
	host, _, _ := net.SplitHostPort(u.Host)
	c.Assert(cont.HostAddr, gocheck.Equals, host)
	user, err := config.GetString("docker:ssh:user")
	c.Assert(err, gocheck.IsNil)
	c.Assert(cont.User, gocheck.Equals, user)
	dcli, _ := docker.NewClient(s.server.URL())
	container, err := dcli.InspectContainer(cont.ID)
	c.Assert(err, gocheck.IsNil)
	c.Assert(container.Path, gocheck.Equals, "docker")
	c.Assert(container.Args, gocheck.DeepEquals, []string{"run"})
	c.Assert(container.Config.User, gocheck.Equals, user)
	c.Assert(container.Config.Memory, gocheck.Equals, int64(app.Memory*1024*1024))
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:31,代码来源:docker_test.go

示例5: TestExecuteCommandOnceWithoutContainers

func (s *S) TestExecuteCommandOnceWithoutContainers(c *gocheck.C) {
	app := testing.NewFakeApp("almah", "static", 2)
	p := dockerProvisioner{}
	var stdout, stderr bytes.Buffer
	err := p.ExecuteCommandOnce(&stdout, &stderr, app, "ls", "-lh")
	c.Assert(err, gocheck.Not(gocheck.IsNil))
}
开发者ID:rochacon,项目名称:tsuru,代码行数:7,代码来源:provisioner_test.go

示例6: TestProvisionerExecuteCommand

func (s *S) TestProvisionerExecuteCommand(c *gocheck.C) {
	var handler FakeSSHServer
	handler.output = ". .."
	server := httptest.NewServer(&handler)
	defer server.Close()
	host, port, _ := net.SplitHostPort(server.Listener.Addr().String())
	portNumber, _ := strconv.Atoi(port)
	config.Set("docker:ssh-agent-port", portNumber)
	defer config.Unset("docker:ssh-agent-port")
	app := testing.NewFakeApp("starbreaker", "python", 1)
	container, err := s.newContainer(&newContainerOpts{AppName: app.GetName()})
	c.Assert(err, gocheck.IsNil)
	defer s.removeTestContainer(container)
	container.HostAddr = host
	coll := collection()
	defer coll.Close()
	coll.Update(bson.M{"id": container.ID}, container)
	var stdout, stderr bytes.Buffer
	var p dockerProvisioner
	err = p.ExecuteCommand(&stdout, &stderr, app, "ls", "-ar")
	c.Assert(err, gocheck.IsNil)
	c.Assert(stderr.Bytes(), gocheck.IsNil)
	c.Assert(stdout.String(), gocheck.Equals, ". ..")
	body := handler.bodies[0]
	input := cmdInput{Cmd: "ls", Args: []string{"-ar"}}
	c.Assert(body, gocheck.DeepEquals, input)
	ip, _, _ := container.networkInfo()
	path := fmt.Sprintf("/container/%s/cmd", ip)
	c.Assert(handler.requests[0].URL.Path, gocheck.DeepEquals, path)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:30,代码来源:provisioner_test.go

示例7: TestProvisionerDestroy

func (s *S) TestProvisionerDestroy(c *gocheck.C) {
	err := newImage("tsuru/python", s.server.URL())
	c.Assert(err, gocheck.IsNil)
	cont, err := s.newContainer(nil)
	c.Assert(err, gocheck.IsNil)
	app := testing.NewFakeApp(cont.AppName, "python", 1)
	var p dockerProvisioner
	p.Provision(app)
	c.Assert(p.Destroy(app), gocheck.IsNil)
	ok := make(chan bool, 1)
	go func() {
		coll := collection()
		defer coll.Close()
		for {
			ct, err := coll.Find(bson.M{"appname": cont.AppName}).Count()
			if err != nil {
				c.Fatal(err)
			}
			if ct == 0 {
				ok <- true
				return
			}
			runtime.Gosched()
		}
	}()
	select {
	case <-ok:
	case <-time.After(10e9):
		c.Fatal("Timed out waiting for the container to be destroyed (10 seconds)")
	}
	c.Assert(rtesting.FakeRouter.HasBackend("myapp"), gocheck.Equals, false)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:32,代码来源:provisioner_test.go

示例8: TestStartedUnitsShouldReturnTrueForUnreachable

func (s *S) TestStartedUnitsShouldReturnTrueForUnreachable(c *gocheck.C) {
	app := testing.NewFakeApp("almah", "static", 1)
	app.SetUnitStatus(provision.StatusUnreachable, 0)
	p := JujuProvisioner{}
	units := p.startedUnits(app)
	c.Assert(units, gocheck.HasLen, 1)
}
开发者ID:renanoliveira,项目名称:tsuru,代码行数:7,代码来源:provisioner_test.go

示例9: TestProvisionerRestart

func (s *S) TestProvisionerRestart(c *gocheck.C) {
	var p dockerProvisioner
	app := testing.NewFakeApp("almah", "static", 1)
	container, err := s.newContainer(&newContainerOpts{AppName: app.GetName()})
	c.Assert(err, gocheck.IsNil)
	defer s.removeTestContainer(container)
	err = p.Start(app)
	c.Assert(err, gocheck.IsNil)
	dockerContainer, err := dCluster.InspectContainer(container.ID)
	c.Assert(err, gocheck.IsNil)
	c.Assert(dockerContainer.State.Running, gocheck.Equals, true)
	container.IP = ""
	container.HostPort = ""
	coll := collection()
	defer coll.Close()
	coll.Update(bson.M{"id": container.ID}, container)
	err = p.Restart(app)
	c.Assert(err, gocheck.IsNil)
	dockerContainer, err = dCluster.InspectContainer(container.ID)
	c.Assert(err, gocheck.IsNil)
	c.Assert(dockerContainer.State.Running, gocheck.Equals, true)
	container, err = getContainer(container.ID)
	c.Assert(err, gocheck.IsNil)
	expectedIP := dockerContainer.NetworkSettings.IPAddress
	expectedPort := dockerContainer.NetworkSettings.Ports["8888/tcp"][0].HostPort
	c.Assert(container.IP, gocheck.Equals, expectedIP)
	c.Assert(container.HostPort, gocheck.Equals, expectedPort)
	c.Assert(container.Status, gocheck.Equals, provision.StatusStarted.String())
	expectedSSHPort := dockerContainer.NetworkSettings.Ports["22/tcp"][0].HostPort
	c.Assert(container.SSHHostPort, gocheck.Equals, expectedSSHPort)
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:31,代码来源:provisioner_test.go

示例10: TestProvisionerRemoveUnits

func (s *S) TestProvisionerRemoveUnits(c *gocheck.C) {
	err := newImage("tsuru/python", s.server.URL())
	c.Assert(err, gocheck.IsNil)
	container1, err := s.newContainer(&newContainerOpts{Status: "building"})
	c.Assert(err, gocheck.IsNil)
	defer rtesting.FakeRouter.RemoveBackend(container1.AppName)
	container2, err := s.newContainer(&newContainerOpts{Status: "building"})
	c.Assert(err, gocheck.IsNil)
	defer rtesting.FakeRouter.RemoveBackend(container2.AppName)
	container3, err := s.newContainer(&newContainerOpts{Status: "started"})
	c.Assert(err, gocheck.IsNil)
	defer s.removeTestContainer(container3)
	client, err := docker.NewClient(s.server.URL())
	c.Assert(err, gocheck.IsNil)
	err = client.StartContainer(container1.ID, nil)
	c.Assert(err, gocheck.IsNil)
	err = client.StartContainer(container2.ID, nil)
	c.Assert(err, gocheck.IsNil)
	app := testing.NewFakeApp(container1.AppName, "python", 0)
	var p dockerProvisioner
	err = p.RemoveUnits(app, 2)
	c.Assert(err, gocheck.IsNil)
	_, err = getContainer(container1.ID)
	c.Assert(err, gocheck.NotNil)
	_, err = getContainer(container2.ID)
	c.Assert(err, gocheck.NotNil)
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:27,代码来源:provisioner_test.go

示例11: TestProvisionerAddUnitsWithErrorDoesntLeaveLostUnits

func (s *S) TestProvisionerAddUnitsWithErrorDoesntLeaveLostUnits(c *gocheck.C) {
	callCount := 0
	s.server.CustomHandler("/containers/create", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		callCount++
		if callCount == 2 {
			w.WriteHeader(http.StatusInternalServerError)
			return
		}
		s.server.DefaultHandler().ServeHTTP(w, r)
	}))
	defer s.server.CustomHandler("/containers/create", s.server.DefaultHandler())
	err := newImage("tsuru/python", s.server.URL())
	c.Assert(err, gocheck.IsNil)
	var p dockerProvisioner
	app := testing.NewFakeApp("myapp", "python", 0)
	p.Provision(app)
	defer p.Destroy(app)
	coll := collection()
	defer coll.Close()
	coll.Insert(container{ID: "c-89320", AppName: app.GetName(), Version: "a345fe", Image: "tsuru/python"})
	defer coll.RemoveId(bson.M{"id": "c-89320"})
	_, err = p.AddUnits(app, 3)
	c.Assert(err, gocheck.NotNil)
	count, err := coll.Find(bson.M{"appname": app.GetName()}).Count()
	c.Assert(err, gocheck.IsNil)
	c.Assert(count, gocheck.Equals, 1)
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:27,代码来源:provisioner_test.go

示例12: TestHandleMessagesWithPendingUnits

func (s *ELBSuite) TestHandleMessagesWithPendingUnits(c *gocheck.C) {
	id := s.server.NewInstance()
	defer s.server.RemoveInstance(id)
	app := testing.NewFakeApp("2112", "python", 1)
	router, err := Router()
	c.Assert(err, gocheck.IsNil)
	err = router.AddBackend(app.GetName())
	defer router.RemoveBackend(app.GetName())
	output := strings.Replace(collectOutputNoInstanceID, "i-00004444", id, 1)
	tmpdir, err := commandmocker.Add("juju", output)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	handle(&queue.Message{
		Action: addUnitToLoadBalancer,
		Args:   []string{"2112", "2112/0", "2112/1"},
	})
	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, 1)
	c.Assert(instances[0].InstanceId, gocheck.Equals, id)
	msg, err := getQueue(queueName).Get(5e9)
	c.Assert(err, gocheck.IsNil)
	c.Assert(msg.Action, gocheck.Equals, addUnitToLoadBalancer)
	c.Assert(msg.Args, gocheck.DeepEquals, []string{"2112", "2112/1"})
}
开发者ID:rochacon,项目名称:tsuru,代码行数:27,代码来源:queue_test.go

示例13: 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

示例14: TestHandleMessageWithoutUnits

func (s *ELBSuite) TestHandleMessageWithoutUnits(c *gocheck.C) {
	instIds := make([]string, 3)
	for i := 0; i < len(instIds); i++ {
		id := s.server.NewInstance()
		defer s.server.RemoveInstance(id)
		instIds[i] = id
	}
	replace := []string{"i-00004444", "i-00004445", "i-00004450"}
	output := simpleCollectOutput
	for i, r := range replace {
		output = strings.Replace(output, r, instIds[i], 1)
	}
	tmpdir, err := commandmocker.Add("juju", output)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("symfonia", "python", 1)
	router, err := Router()
	c.Assert(err, gocheck.IsNil)
	err = router.AddBackend(app.GetName())
	c.Assert(err, gocheck.IsNil)
	defer router.RemoveBackend(app.GetName())
	handle(&queue.Message{
		Action: addUnitToLoadBalancer,
		Args:   []string{"symfonia"},
	})
	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, 3)
	ids := []string{instances[0].InstanceId, instances[1].InstanceId, instances[2].InstanceId}
	sort.Strings(ids)
	sort.Strings(instIds)
	c.Assert(ids, gocheck.DeepEquals, instIds)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:35,代码来源:queue_test.go

示例15: TestRunWithAgentCmds

func (s *S) TestRunWithAgentCmds(c *gocheck.C) {
	app := testing.NewFakeApp("app-name", "python", 1)
	host_env := bind.EnvVar{
		Name:   "TSURU_HOST",
		Value:  "tsuru_host",
		Public: true,
	}
	token_env := bind.EnvVar{
		Name:   "TSURU_APP_TOKEN",
		Value:  "app_token",
		Public: true,
	}
	app.SetEnv(host_env)
	app.SetEnv(token_env)
	runCmd, err := config.GetString("docker:run-cmd:bin")
	c.Assert(err, gocheck.IsNil)
	unitAgentCmd := fmt.Sprintf("(tsuru_unit_agent tsuru_host app_token app-name %s || %s)", runCmd, runCmd)
	ssh, err := sshCmds()
	sshCmd := strings.Join(ssh, " && ")
	c.Assert(err, gocheck.IsNil)
	cmd := fmt.Sprintf("%s && %s", unitAgentCmd, sshCmd)
	expected := []string{"/bin/bash", "-c", cmd}
	cmds, err := runWithAgentCmds(app)
	c.Assert(err, gocheck.IsNil)
	c.Assert(cmds, gocheck.DeepEquals, expected)
}
开发者ID:rochacon,项目名称:tsuru,代码行数:26,代码来源:commands_test.go


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