From e2768f49a3c26af4edb32c37d8ce4ab4687eaabe Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Wed, 10 Feb 2016 13:18:10 -0800 Subject: [PATCH] Fixed the docker handle id test --- client/driver/docker_test.go | 37 ++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/client/driver/docker_test.go b/client/driver/docker_test.go index 0eb09ce2e..58f2c0953 100644 --- a/client/driver/docker_test.go +++ b/client/driver/docker_test.go @@ -4,6 +4,8 @@ import ( "fmt" "io/ioutil" "math/rand" + "os" + "os/exec" "path/filepath" "reflect" "runtime/debug" @@ -11,9 +13,11 @@ import ( "time" docker "github.com/fsouza/go-dockerclient" + "github.com/hashicorp/go-plugin" "github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/driver/env" cstructs "github.com/hashicorp/nomad/client/driver/structs" + "github.com/hashicorp/nomad/helper/discover" "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/testutil" ) @@ -125,16 +129,37 @@ func dockerSetup(t *testing.T, task *structs.Task) (*docker.Client, DriverHandle func TestDockerDriver_Handle(t *testing.T) { t.Parallel() + + bin, err := discover.NomadExecutable() + if err != nil { + t.Fatalf("got an err: %v", err) + } + + f, _ := ioutil.TempFile(os.TempDir(), "") + defer f.Close() + defer os.Remove(f.Name()) + pluginConfig := &plugin.ClientConfig{ + Cmd: exec.Command(bin, "syslog", f.Name()), + } + logCollector, pluginClient, err := createLogCollector(pluginConfig, os.Stdout, &config.Config{}) + if err != nil { + t.Fatalf("got an err: %v", err) + } + defer pluginClient.Kill() + h := &DockerHandle{ - imageID: "imageid", - containerID: "containerid", - killTimeout: 5 * time.Nanosecond, - doneCh: make(chan struct{}), - waitCh: make(chan *cstructs.WaitResult, 1), + imageID: "imageid", + logCollector: logCollector, + pluginClient: pluginClient, + containerID: "containerid", + killTimeout: 5 * time.Nanosecond, + doneCh: make(chan struct{}), + waitCh: make(chan *cstructs.WaitResult, 1), } actual := h.ID() - expected := `DOCKER:{"ImageID":"imageid","ContainerID":"containerid","KillTimeout":5}` + expected := fmt.Sprintf("DOCKER:{\"ImageID\":\"imageid\",\"ContainerID\":\"containerid\",\"KillTimeout\":5,\"PluginConfig\":{\"Pid\":%d,\"AddrNet\":\"unix\",\"AddrName\":\"%s\"}}", + pluginClient.ReattachConfig().Pid, pluginClient.ReattachConfig().Addr.String()) if actual != expected { t.Errorf("Expected `%s`, found `%s`", expected, actual) }