mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
Add test for rm'd containers
This commit is contained in:
@@ -11,9 +11,11 @@ import (
|
||||
|
||||
client "github.com/fsouza/go-dockerclient"
|
||||
|
||||
"github.com/weaveworks/scope/common/mtime"
|
||||
"github.com/weaveworks/scope/probe/docker"
|
||||
"github.com/weaveworks/scope/report"
|
||||
"github.com/weaveworks/scope/test"
|
||||
"github.com/weaveworks/scope/test/reflect"
|
||||
)
|
||||
|
||||
type mockContainer struct {
|
||||
@@ -377,3 +379,57 @@ func TestRegistryEvents(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRegistryDelete(t *testing.T) {
|
||||
mtime.NowForce(mtime.Now())
|
||||
defer mtime.NowReset()
|
||||
|
||||
mdc := newMockClient()
|
||||
setupStubs(mdc, func() {
|
||||
registry, _ := docker.NewRegistry(10*time.Second, nil, true, "")
|
||||
defer registry.Stop()
|
||||
runtime.Gosched()
|
||||
|
||||
// Collect all the events.
|
||||
mtx := sync.Mutex{}
|
||||
nodes := []report.Node{}
|
||||
registry.WatchContainerUpdates(func(n report.Node) {
|
||||
mtx.Lock()
|
||||
defer mtx.Unlock()
|
||||
nodes = append(nodes, n)
|
||||
})
|
||||
|
||||
check := func(want []docker.Container) {
|
||||
test.Poll(t, 100*time.Millisecond, want, func() interface{} {
|
||||
return allContainers(registry)
|
||||
})
|
||||
}
|
||||
|
||||
want := []docker.Container{&mockContainer{container1}}
|
||||
check(want)
|
||||
|
||||
{
|
||||
mdc.Lock()
|
||||
mdc.apiContainers = []client.APIContainers{}
|
||||
delete(mdc.containers, "ping")
|
||||
mdc.Unlock()
|
||||
mdc.send(&client.APIEvents{Status: docker.DestroyEvent, ID: "ping"})
|
||||
runtime.Gosched()
|
||||
|
||||
check([]docker.Container{})
|
||||
|
||||
mtx.Lock()
|
||||
want := []report.Node{
|
||||
report.MakeNodeWith(report.MakeContainerNodeID("ping"), map[string]string{
|
||||
docker.ContainerID: "ping",
|
||||
docker.ContainerState: "deleted",
|
||||
}),
|
||||
}
|
||||
if !reflect.DeepEqual(want, nodes) {
|
||||
t.Errorf("Didn't get right container updates: %v", test.Diff(want, nodes))
|
||||
}
|
||||
nodes = []report.Node{}
|
||||
mtx.Unlock()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user