From 70f8c62415f651ae8e525c2a4c626384020373bc Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Thu, 30 Jul 2015 11:30:08 +0200 Subject: [PATCH] Don't panic tests on Darwin. Use the proper DialStub in the container setup. Also, one change to increase test coverage. --- probe/docker/container.go | 2 +- probe/docker/container_test.go | 4 ++++ probe/process/walker_test.go | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/probe/docker/container.go b/probe/docker/container.go index a9f8459c3..83a98c82b 100644 --- a/probe/docker/container.go +++ b/probe/docker/container.go @@ -122,7 +122,7 @@ func (c *container) StartGatheringStats() error { return } - dial, err := net.Dial(url.Scheme, url.Path) + dial, err := DialStub(url.Scheme, url.Path) if err != nil { log.Printf("docker container: %v", err) return diff --git a/probe/docker/container_test.go b/probe/docker/container_test.go index cd467e5d6..ce8349a90 100644 --- a/probe/docker/container_test.go +++ b/probe/docker/container_test.go @@ -4,6 +4,8 @@ import ( "bufio" "encoding/json" "io" + "io/ioutil" + "log" "net" "net/http" "runtime" @@ -31,6 +33,8 @@ func (c *mockConnection) Close() error { } func TestContainer(t *testing.T) { + log.SetOutput(ioutil.Discard) + oldDialStub, oldNewClientConnStub := docker.DialStub, docker.NewClientConnStub defer func() { docker.DialStub, docker.NewClientConnStub = oldDialStub, oldNewClientConnStub }() diff --git a/probe/process/walker_test.go b/probe/process/walker_test.go index 8008eda73..22af5ea62 100644 --- a/probe/process/walker_test.go +++ b/probe/process/walker_test.go @@ -8,6 +8,17 @@ import ( "github.com/weaveworks/scope/test" ) +func TestBasicWalk(t *testing.T) { + // Don't panic or error. + var ( + procRoot = "/proc" + procFunc = func(process.Process) {} + ) + if err := process.NewWalker(procRoot).Walk(procFunc); err != nil { + t.Fatal(err) + } +} + func TestCache(t *testing.T) { processes := []process.Process{ {PID: 1, PPID: 0, Comm: "init"},