-
Notifications
You must be signed in to change notification settings - Fork 6
/
events_test.go
55 lines (50 loc) · 1.32 KB
/
events_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package adoc
import (
"fmt"
"testing"
"time"
)
func TestEventsPolling(t *testing.T) {
events, err := docker.EventsSince("", time.Hour, 5*time.Minute)
if err != nil {
t.Fatalf("Cannot poll the events, %s", err)
}
d("Events", events)
}
func TestEventsMonitor(t *testing.T) {
monitorId := docker.MonitorEvents("", func(event Event, err error) {
if err != nil {
t.Errorf("Error when calling monitor, %s", err)
} else {
d("Event", event)
}
})
fmt.Println("Please do some docker operations")
time.Sleep(1 * time.Minute)
docker.StopMonitor(monitorId)
}
func TestStatsMonitor(t *testing.T) {
containerConf := ContainerConfig{
AttachStdout: true,
AttachStderr: true,
Cmd: []string{"python", "app.py"},
Image: "training/webapp",
}
id, err := docker.CreateContainer(containerConf, HostConfig{})
if err != nil {
t.Fatalf("Cannot create the container, %s", err)
}
if err := docker.StartContainer(id); err != nil {
t.Fatalf("Cannot start the container, %s", err)
}
monitorId := docker.MonitorStats(id, func(stats Stats, err error) {
if err != nil {
t.Errorf("Error when calling monitor, %s", err)
} else {
d("Stats CpuUsage.PercpuUsage", stats.CpuStats.CpuUsage.PercpuUsage)
}
})
time.Sleep(30 * time.Second)
docker.StopMonitor(monitorId)
docker.RemoveContainer(id, true, true)
}