diff --git a/probe/docker/container_linux_test.go b/probe/docker/container_linux_test.go index c6e3a5cbc..a5714b6e5 100644 --- a/probe/docker/container_linux_test.go +++ b/probe/docker/container_linux_test.go @@ -8,12 +8,14 @@ import ( "log" "net" "net/http" + "reflect" "testing" "time" client "github.com/fsouza/go-dockerclient" "github.com/weaveworks/scope/probe/docker" + "github.com/weaveworks/scope/report" "github.com/weaveworks/scope/test" ) @@ -63,7 +65,35 @@ func TestContainer(t *testing.T) { } // Now see if we go them - test.Poll(t, 100*time.Millisecond, "12345", func() interface{} { - return c.GetNode().Metadata[docker.MemoryUsage] + want := report.MakeNode().WithMetadata(map[string]string{ + "docker_container_command": " ", + "docker_container_created": "01 Jan 01 00:00 UTC", + "docker_container_id": "ping", + "docker_container_ips": "1.2.3.4", + "docker_container_name": "pong", + "docker_container_ports": "1.2.3.4:80->80/tcp, 81/tcp", + "docker_image_id": "baz", + "docker_label_foo1": "bar1", + "docker_label_foo2": "bar2", + "memory_usage": "12345", }) + test.Poll(t, 100*time.Millisecond, want, func() interface{} { + node := c.GetNode() + for k, v := range node.Metadata { + if v == "0" { + delete(node.Metadata, k) + } + } + return node + }) + + if c.Image() != "baz" { + t.Errorf("%s != baz", c.Image()) + } + if c.PID() != 1 { + t.Errorf("%s != 1", c.PID()) + } + if !reflect.DeepEqual(docker.ExtractContainerIPs(c.GetNode()), []string{"1.2.3.4"}) { + t.Errorf("%v != %v", docker.ExtractContainerIPs(c.GetNode()), []string{"1.2.3.4"}) + } } diff --git a/probe/docker/registry_test.go b/probe/docker/registry_test.go index f603f0420..42559f2e0 100644 --- a/probe/docker/registry_test.go +++ b/probe/docker/registry_test.go @@ -104,6 +104,15 @@ var ( State: client.State{Pid: 1, Running: true}, NetworkSettings: &client.NetworkSettings{ IPAddress: "1.2.3.4", + Ports: map[client.Port][]client.PortBinding{ + client.Port("80/tcp"): { + { + HostIP: "1.2.3.4", + HostPort: "80", + }, + }, + client.Port("81/tcp"): {}, + }, }, Config: &client.Config{ Labels: map[string]string{ @@ -198,6 +207,23 @@ func TestRegistry(t *testing.T) { }) } +func TestLookupByPID(t *testing.T) { + mdc := newMockClient() + setupStubs(mdc, func() { + registry, _ := docker.NewRegistry(10 * time.Second) + defer registry.Stop() + + want := docker.Container(&mockContainer{container1}) + test.Poll(t, 100*time.Millisecond, want, func() interface{} { + var have docker.Container + registry.LockedPIDLookup(func(lookup func(int) docker.Container) { + have = lookup(1) + }) + return have + }) + }) +} + func TestRegistryEvents(t *testing.T) { mdc := newMockClient() setupStubs(mdc, func() {