• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang dockertest.NewFakeDockerProvisioner函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestRunContainerHealerMaxCounterExceeded

func (s *S) TestRunContainerHealerMaxCounterExceeded(c *check.C) {
	conts := []container.Container{
		{ID: "cont1"}, {ID: "cont2"}, {ID: "cont3"}, {ID: "cont4"},
		{ID: "cont5"}, {ID: "cont6"}, {ID: "cont7"}, {ID: "cont8"},
	}
	for i := 0; i < len(conts)-1; i++ {
		evt, err := NewHealingEvent(conts[i])
		c.Assert(err, check.IsNil)
		err = evt.Update(conts[i+1], nil)
		c.Assert(err, check.IsNil)
	}
	toMoveCont := conts[7]
	toMoveCont.LastSuccessStatusUpdate = time.Now().Add(-2 * time.Minute)
	p, err := dockertest.NewFakeDockerProvisioner()
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	healer := NewContainerHealer(ContainerHealerArgs{Provisioner: p, Locker: dockertest.NewFakeLocker()})
	err = healer.healContainerIfNeeded(toMoveCont)
	c.Assert(err, check.ErrorMatches, "Containers healing: number of healings for container cont8 in the last 30 minutes exceeds limit of 3: 7")
	healingColl, err := healingCollection()
	c.Assert(err, check.IsNil)
	defer healingColl.Close()
	var events []HealingEvent
	err = healingColl.Find(nil).All(&events)
	c.Assert(err, check.IsNil)
	c.Assert(events, check.HasLen, 7)
}
开发者ID:ggarnier,项目名称:tsuru,代码行数:27,代码来源:healer_container_test.go


示例2: TestEnsureContainersStartedForceStopOnlyOnFailure

func (s *S) TestEnsureContainersStartedForceStopOnlyOnFailure(c *check.C) {
	config.Set("docker:bs:image", "myregistry/tsuru/bs")
	_, err := nodecontainer.InitializeBS()
	c.Assert(err, check.IsNil)
	var reqs []*http.Request
	server, err := testing.NewServer("127.0.0.1:0", nil, func(r *http.Request) {
		reqs = append(reqs, r)
	})
	c.Assert(err, check.IsNil)
	defer server.Stop()
	errCount := 0
	server.CustomHandler("/containers/big-sibling", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		reqs = append(reqs, r)
		if r.Method != "DELETE" {
			server.DefaultHandler().ServeHTTP(w, r)
			return
		}
		errCount++
		if errCount > 2 {
			server.DefaultHandler().ServeHTTP(w, r)
		} else {
			w.WriteHeader(http.StatusInternalServerError)
		}
	}))
	p, err := dockertest.NewFakeDockerProvisioner(server.URL())
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	client, err := docker.NewClient(server.URL())
	c.Assert(err, check.IsNil)
	buf := safe.NewBuffer(nil)
	err = ensureContainersStarted(p, buf, true, nil)
	c.Assert(err, check.IsNil)
	reqs = nil
	err = ensureContainersStarted(p, buf, true, nil)
	c.Assert(err, check.IsNil)
	var paths []string
	for _, r := range reqs {
		paths = append(paths, r.Method+" "+r.URL.Path)
	}
	c.Assert(paths, check.DeepEquals, []string{
		"POST /images/create",
		"POST /containers/create",
		"POST /containers/big-sibling/stop",
		"DELETE /containers/big-sibling",
		"DELETE /containers/big-sibling",
		"DELETE /containers/big-sibling",
		"POST /containers/create",
		"GET /version",
		"POST /containers/big-sibling/start",
	})
	c.Assert(reqs[3].URL.Query().Get("force"), check.Equals, "")
	c.Assert(reqs[4].URL.Query().Get("force"), check.Equals, "1")
	c.Assert(reqs[5].URL.Query().Get("force"), check.Equals, "1")
	containers, err := client.ListContainers(docker.ListContainersOptions{All: true})
	c.Assert(err, check.IsNil)
	c.Assert(containers, check.HasLen, 1)
	container, err := client.InspectContainer(containers[0].ID)
	c.Assert(err, check.IsNil)
	c.Assert(container.Name, check.Equals, nodecontainer.BsDefaultName)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:60,代码来源:nodecontainer_test.go


示例3: TestCreateBsContainerSocketAndCustomSysLogPort

func (s *S) TestCreateBsContainerSocketAndCustomSysLogPort(c *check.C) {
	server, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	defer server.Stop()
	server.CustomHandler("/images/create", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		server.DefaultHandler().ServeHTTP(w, r)
		w.Write([]byte(pullOutputNoDigest))
	}))
	config.Set("host", "127.0.0.1:8080")
	config.Set("docker:bs:image", "myregistry/tsuru/bs")
	config.Set("docker:bs:socket", "/tmp/docker.sock")
	defer config.Unset("docker:bs:socket")
	config.Set("docker:bs:syslog-port", 1519)
	defer config.Unset("docker:bs:syslog-port")
	conf, err := LoadConfig(nil)
	c.Assert(err, check.IsNil)
	conf.Add("VAR1", "VALUE1")
	conf.Add("VAR2", "VALUE2")
	conf.Add("TSURU_ENDPOINT", "ignored")
	conf.AddPool("pool1", "VAR2", "VALUE_FOR_POOL1")
	conf.AddPool("pool2", "VAR2", "VALUE_FOR_POOL2")
	conf.AddPool("pool1", "SYSLOG_LISTEN_ADDRESS", "alsoignored")
	err = conf.SaveEnvs()
	c.Assert(err, check.IsNil)
	p, err := dockertest.NewFakeDockerProvisioner()
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	err = createContainer(server.URL(), "pool1", p, true)
	c.Assert(err, check.IsNil)
	client, err := docker.NewClient(server.URL())
	c.Assert(err, check.IsNil)
	containers, err := client.ListContainers(docker.ListContainersOptions{All: true})
	c.Assert(err, check.IsNil)
	c.Assert(containers, check.HasLen, 1)
	container, err := client.InspectContainer(containers[0].ID)
	c.Assert(err, check.IsNil)
	c.Assert(container.Name, check.Equals, "big-sibling")
	c.Assert(container.HostConfig.Binds, check.DeepEquals, []string{"/tmp/docker.sock:/var/run/docker.sock:rw"})
	c.Assert(container.Config.Image, check.Equals, "myregistry/tsuru/bs")
	c.Assert(container.State.Running, check.Equals, true)
	conf, err = LoadConfig(nil)
	c.Assert(err, check.IsNil)
	token, _ := getToken(conf)
	expectedEnv := []string{
		"DOCKER_ENDPOINT=unix:///var/run/docker.sock",
		"TSURU_ENDPOINT=http://127.0.0.1:8080/",
		"TSURU_TOKEN=" + token,
		"SYSLOG_LISTEN_ADDRESS=udp://0.0.0.0:1519",
		"VAR1=VALUE1",
		"VAR2=VALUE_FOR_POOL1",
	}
	sort.Strings(expectedEnv)
	sort.Strings(container.Config.Env)
	c.Assert(container.Config.Env, check.DeepEquals, expectedEnv)
	c.Assert(conf.GetExtraString("image"), check.Equals, "myregistry/tsuru/bs")
}
开发者ID:Endika,项目名称:tsuru,代码行数:58,代码来源:queue_test.go


示例4: newFakeDockerProvisioner

func (s *S) newFakeDockerProvisioner(servers ...string) (*dockertest.FakeDockerProvisioner, error) {
	p, err := dockertest.NewFakeDockerProvisioner(servers...)
	if err != nil {
		return nil, err
	}
	p.SetContainers("127.0.0.1", nil)
	p.SetContainers("localhost", nil)
	err = bs.RegisterQueueTask(p)
	return p, err
}
开发者ID:zhenruyan,项目名称:tsuru,代码行数:10,代码来源:healer_node_test.go


示例5: TestCreateBsContainerTaggedBs

func (s *S) TestCreateBsContainerTaggedBs(c *check.C) {
	server, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	defer server.Stop()
	server.CustomHandler("/images/create", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		server.DefaultHandler().ServeHTTP(w, r)
		w.Write([]byte(pullOutputDigest))
	}))
	client, err := docker.NewClient(server.URL())
	c.Assert(err, check.IsNil)
	err = client.PullImage(docker.PullImageOptions{
		Repository: "base",
	}, docker.AuthConfiguration{})
	_, err = client.CreateContainer(docker.CreateContainerOptions{
		Name:       "big-sibling",
		Config:     &docker.Config{Image: "base"},
		HostConfig: &docker.HostConfig{},
	})
	c.Assert(err, check.IsNil)
	config.Set("host", "127.0.0.1:8080")
	config.Set("docker:bs:image", "localhost:5000/myregistry/tsuru/bs:v1")
	p, err := dockertest.NewFakeDockerProvisioner()
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	err = createContainer(server.URL(), "pool1", p, true)
	c.Assert(err, check.IsNil)
	containers, err := client.ListContainers(docker.ListContainersOptions{All: true})
	c.Assert(err, check.IsNil)
	c.Assert(containers, check.HasLen, 1)
	container, err := client.InspectContainer(containers[0].ID)
	c.Assert(err, check.IsNil)
	c.Assert(container.Name, check.Equals, "big-sibling")
	c.Assert(container.Config.Image, check.Equals, "localhost:5000/myregistry/tsuru/bs:v1")
	c.Assert(container.HostConfig.RestartPolicy, check.Equals, docker.AlwaysRestart())
	c.Assert(container.HostConfig.Privileged, check.Equals, true)
	c.Assert(container.HostConfig.NetworkMode, check.Equals, "host")
	c.Assert(container.State.Running, check.Equals, true)
	expectedEnv := map[string]string{
		"DOCKER_ENDPOINT":       server.URL(),
		"TSURU_ENDPOINT":        "http://127.0.0.1:8080/",
		"TSURU_TOKEN":           "abc123",
		"SYSLOG_LISTEN_ADDRESS": "udp://0.0.0.0:1514",
	}
	gotEnv := parseEnvs(container.Config.Env)
	_, ok := gotEnv["TSURU_TOKEN"]
	c.Assert(ok, check.Equals, true)
	gotEnv["TSURU_TOKEN"] = expectedEnv["TSURU_TOKEN"]
	c.Assert(gotEnv, check.DeepEquals, expectedEnv)
	conf, err := LoadConfig()
	c.Assert(err, check.IsNil)
	c.Assert(conf.Image, check.Equals, "localhost:5000/myregistry/tsuru/bs:v1")
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:54,代码来源:queue_test.go


示例6: TestEnsureContainersStartedGracefullyStop

func (s *S) TestEnsureContainersStartedGracefullyStop(c *check.C) {
	config.Set("docker:bs:image", "myregistry/tsuru/bs")
	_, err := nodecontainer.InitializeBS()
	c.Assert(err, check.IsNil)
	var reqs []*http.Request
	server, err := testing.NewServer("127.0.0.1:0", nil, func(r *http.Request) {
		reqs = append(reqs, r)
	})
	c.Assert(err, check.IsNil)
	defer server.Stop()
	p, err := dockertest.NewFakeDockerProvisioner(server.URL())
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	client, err := docker.NewClient(server.URL())
	c.Assert(err, check.IsNil)
	buf := safe.NewBuffer(nil)
	err = ensureContainersStarted(p, buf, true, nil)
	c.Assert(err, check.IsNil)
	var paths []string
	for _, r := range reqs {
		paths = append(paths, r.Method+" "+r.URL.Path)
	}
	c.Assert(paths, check.DeepEquals, []string{
		"POST /images/create",
		"POST /containers/create",
		"GET /version",
		"POST /containers/big-sibling/start",
	})
	reqs = nil
	err = ensureContainersStarted(p, buf, true, nil)
	c.Assert(err, check.IsNil)
	paths = nil
	for _, r := range reqs {
		paths = append(paths, r.Method+" "+r.URL.Path)
	}
	c.Assert(paths, check.DeepEquals, []string{
		"POST /images/create",
		"POST /containers/create",
		"POST /containers/big-sibling/stop",
		"DELETE /containers/big-sibling",
		"POST /containers/create",
		"GET /version",
		"POST /containers/big-sibling/start",
	})
	c.Assert(reqs[3].URL.Query().Get("force"), check.Equals, "")
	containers, err := client.ListContainers(docker.ListContainersOptions{All: true})
	c.Assert(err, check.IsNil)
	c.Assert(containers, check.HasLen, 1)
	container, err := client.InspectContainer(containers[0].ID)
	c.Assert(err, check.IsNil)
	c.Assert(container.Name, check.Equals, nodecontainer.BsDefaultName)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:52,代码来源:nodecontainer_test.go


示例7: TestCreateBsContainer

func (s *S) TestCreateBsContainer(c *check.C) {
	server, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	defer server.Stop()
	server.CustomHandler("/images/create", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		server.DefaultHandler().ServeHTTP(w, r)
		w.Write([]byte(pullOutputDigest))
	}))
	client, err := docker.NewClient(server.URL())
	c.Assert(err, check.IsNil)
	err = client.PullImage(docker.PullImageOptions{
		Repository: "base",
	}, docker.AuthConfiguration{})
	_, err = client.CreateContainer(docker.CreateContainerOptions{
		Name:       "big-sibling",
		Config:     &docker.Config{Image: "base"},
		HostConfig: &docker.HostConfig{},
	})
	c.Assert(err, check.IsNil)
	config.Set("host", "127.0.0.1:8080")
	config.Set("docker:bs:image", "myregistry/tsuru/bs")
	p, err := dockertest.NewFakeDockerProvisioner()
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	err = createContainer(server.URL(), "pool1", p, true)
	c.Assert(err, check.IsNil)
	containers, err := client.ListContainers(docker.ListContainersOptions{All: true})
	c.Assert(err, check.IsNil)
	c.Assert(containers, check.HasLen, 1)
	container, err := client.InspectContainer(containers[0].ID)
	c.Assert(err, check.IsNil)
	c.Assert(container.Name, check.Equals, "big-sibling")
	c.Assert(container.Config.Image, check.Equals, "myregistry/tsuru/bs")
	c.Assert(container.HostConfig.RestartPolicy, check.Equals, docker.AlwaysRestart())
	c.Assert(container.State.Running, check.Equals, true)
	conf, err := LoadConfig(nil)
	c.Assert(err, check.IsNil)
	token, _ := getToken(conf)
	expectedEnv := []string{
		"DOCKER_ENDPOINT=" + server.URL(),
		"TSURU_ENDPOINT=http://127.0.0.1:8080/",
		"TSURU_TOKEN=" + token,
		"SYSLOG_LISTEN_ADDRESS=udp://0.0.0.0:1514",
	}
	sort.Strings(expectedEnv)
	sort.Strings(container.Config.Env)
	c.Assert(container.Config.Env, check.DeepEquals, expectedEnv)
	c.Assert(conf.GetExtraString("image"), check.Equals, "myregistry/tsuru/[email protected]"+digest)
}
开发者ID:Endika,项目名称:tsuru,代码行数:51,代码来源:queue_test.go


示例8: TestEnsureContainersStartedAlreadyPinned

func (s *S) TestEnsureContainersStartedAlreadyPinned(c *check.C) {
	config.Set("docker:bs:image", "myregistry/tsuru/bs")
	_, err := nodecontainer.InitializeBS()
	c.Assert(err, check.IsNil)
	cont, err := nodecontainer.LoadNodeContainer("", nodecontainer.BsDefaultName)
	c.Assert(err, check.IsNil)
	cont.PinnedImage = "myregistry/tsuru/[email protected]" + digest
	err = nodecontainer.AddNewContainer("", cont)
	c.Assert(err, check.IsNil)
	server, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	defer server.Stop()
	server.CustomHandler("/images/create", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		server.DefaultHandler().ServeHTTP(w, r)
		w.Write([]byte(pullOutputDigest))
	}))
	p, err := dockertest.NewFakeDockerProvisioner(server.URL())
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	client, err := docker.NewClient(server.URL())
	c.Assert(err, check.IsNil)
	err = client.PullImage(docker.PullImageOptions{
		Repository: "base",
	}, docker.AuthConfiguration{})
	c.Assert(err, check.IsNil)
	_, err = client.CreateContainer(docker.CreateContainerOptions{
		Name:       nodecontainer.BsDefaultName,
		Config:     &docker.Config{Image: "base"},
		HostConfig: &docker.HostConfig{},
	})
	c.Assert(err, check.IsNil)
	buf := safe.NewBuffer(nil)
	err = ensureContainersStarted(p, buf, true, nil)
	c.Assert(err, check.IsNil)
	containers, err := client.ListContainers(docker.ListContainersOptions{All: true})
	c.Assert(err, check.IsNil)
	c.Assert(containers, check.HasLen, 1)
	container, err := client.InspectContainer(containers[0].ID)
	c.Assert(err, check.IsNil)
	c.Assert(container.Name, check.Equals, nodecontainer.BsDefaultName)
	c.Assert(container.Config.Image, check.Equals, "myregistry/tsuru/[email protected]"+digest)
	c.Assert(container.HostConfig.RestartPolicy, check.Equals, docker.AlwaysRestart())
	c.Assert(container.State.Running, check.Equals, true)
	nodeContainer, err := nodecontainer.LoadNodeContainer("", nodecontainer.BsDefaultName)
	c.Assert(err, check.IsNil)
	c.Assert(nodeContainer.PinnedImage, check.Equals, "myregistry/tsuru/[email protected]"+digest)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:49,代码来源:nodecontainer_test.go


示例9: TestEnsureContainersStartedPinImgInChild

func (s *S) TestEnsureContainersStartedPinImgInChild(c *check.C) {
	err := nodecontainer.AddNewContainer("", &nodecontainer.NodeContainerConfig{
		Name: "c1",
		Config: docker.Config{
			Image: "myrootimg",
		},
	})
	c.Assert(err, check.IsNil)
	err = nodecontainer.AddNewContainer("p1", &nodecontainer.NodeContainerConfig{
		Name: "c1",
		Config: docker.Config{
			Image: "myregistry/tsuru/bs",
		},
	})
	c.Assert(err, check.IsNil)
	server, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	defer server.Stop()
	server.CustomHandler("/images/create", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		server.DefaultHandler().ServeHTTP(w, r)
		w.Write([]byte(pullOutputDigest))
	}))
	p, err := dockertest.NewFakeDockerProvisioner(server.URL())
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	node, err := p.Cluster().GetNode(server.URL())
	c.Assert(err, check.IsNil)
	node.Metadata["pool"] = "p1"
	_, err = p.Cluster().UpdateNode(node)
	c.Assert(err, check.IsNil)
	buf := safe.NewBuffer(nil)
	err = ensureContainersStarted(p, buf, true, nil)
	c.Assert(err, check.IsNil)
	all, err := nodecontainer.LoadNodeContainersForPoolsMerge("c1", false)
	c.Assert(err, check.IsNil)
	c.Assert(all, check.DeepEquals, map[string]nodecontainer.NodeContainerConfig{
		"":   {Name: "c1", PinnedImage: "", Config: docker.Config{Image: "myrootimg"}},
		"p1": {Name: "c1", PinnedImage: "myregistry/tsuru/[email protected]" + digest, Config: docker.Config{Image: "myregistry/tsuru/bs"}},
	})
}
开发者ID:tsuru,项目名称:tsuru,代码行数:42,代码来源:nodecontainer_test.go


示例10: TestEnsureContainersStartedTryCreatingAfterRmFailure

func (s *S) TestEnsureContainersStartedTryCreatingAfterRmFailure(c *check.C) {
	config.Set("docker:bs:image", "myregistry/tsuru/bs")
	_, err := nodecontainer.InitializeBS()
	c.Assert(err, check.IsNil)
	server, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	defer server.Stop()
	server.CustomHandler("/containers/big-sibling", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.Method == "DELETE" {
			w.WriteHeader(http.StatusInternalServerError)
			w.Write([]byte("my error"))
			return
		}
		server.DefaultHandler().ServeHTTP(w, r)
	}))
	p, err := dockertest.NewFakeDockerProvisioner(server.URL())
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	buf := safe.NewBuffer(nil)
	err = ensureContainersStarted(p, buf, true, nil)
	c.Assert(err, check.IsNil)
	err = ensureContainersStarted(p, buf, true, nil)
	c.Assert(err, check.ErrorMatches, `(?s).*API error \(500\): my error.*unable to remove old node-container.*container already exists.*unable to create new node-container.*`)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:24,代码来源:nodecontainer_test.go


示例11: TestCreateBsContainerSocketAndCustomSysLogPort

func (s *S) TestCreateBsContainerSocketAndCustomSysLogPort(c *check.C) {
	server, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	defer server.Stop()
	server.CustomHandler("/images/create", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		server.DefaultHandler().ServeHTTP(w, r)
		w.Write([]byte(pullOutputNoDigest))
	}))
	config.Set("host", "127.0.0.1:8080")
	config.Set("docker:bs:image", "myregistry/tsuru/bs")
	config.Set("docker:bs:socket", "/tmp/docker.sock")
	defer config.Unset("docker:bs:socket")
	config.Set("docker:bs:syslog-port", 1519)
	defer config.Unset("docker:bs:syslog-port")
	err = SaveEnvs(EnvMap{
		"VAR1": "VALUE1",
		"VAR2": "VALUE2",
	}, PoolEnvMap{
		"pool1": EnvMap{
			"VAR2": "VALUE_FOR_POOL1",
		},
		"pool2": EnvMap{
			"VAR2": "VALUE_FOR_POOL2",
		},
	})
	c.Assert(err, check.IsNil)
	p, err := dockertest.NewFakeDockerProvisioner()
	c.Assert(err, check.IsNil)
	defer p.Destroy()
	err = createContainer(server.URL(), "pool1", p, true)
	c.Assert(err, check.IsNil)
	client, err := docker.NewClient(server.URL())
	c.Assert(err, check.IsNil)
	containers, err := client.ListContainers(docker.ListContainersOptions{All: true})
	c.Assert(err, check.IsNil)
	c.Assert(containers, check.HasLen, 1)
	container, err := client.InspectContainer(containers[0].ID)
	c.Assert(err, check.IsNil)
	c.Assert(container.Name, check.Equals, "big-sibling")
	c.Assert(container.HostConfig.Binds, check.DeepEquals, []string{"/tmp/docker.sock:/var/run/docker.sock:rw"})
	c.Assert(container.Config.Image, check.Equals, "myregistry/tsuru/bs")
	c.Assert(container.State.Running, check.Equals, true)
	expectedEnv := map[string]string{
		"DOCKER_ENDPOINT":       "unix:///var/run/docker.sock",
		"TSURU_ENDPOINT":        "http://127.0.0.1:8080/",
		"TSURU_TOKEN":           "abc123",
		"SYSLOG_LISTEN_ADDRESS": "udp://0.0.0.0:1519",
		"VAR1":                  "VALUE1",
		"VAR2":                  "VALUE_FOR_POOL1",
	}
	gotEnv := parseEnvs(container.Config.Env)
	_, ok := gotEnv["TSURU_TOKEN"]
	c.Assert(ok, check.Equals, true)
	gotEnv["TSURU_TOKEN"] = expectedEnv["TSURU_TOKEN"]
	c.Assert(gotEnv, check.DeepEquals, expectedEnv)
	conf, err := LoadConfig()
	c.Assert(err, check.IsNil)
	c.Assert(conf.Image, check.Equals, "myregistry/tsuru/bs")
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:61,代码来源:queue_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang dockertest.NewFakeLocker函数代码示例发布时间:2022-05-28
下一篇:
Golang container.Container类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap