Fixes #6856
Docker-DCO-1.1-Signed-off-by: Brian Goff <cpuguy83@gmail.com> (github: cpuguy83)
| ... | ... |
@@ -1,12 +1,14 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "fmt" |
|
| 4 | 5 |
"os/exec" |
| 5 | 6 |
"strings" |
| 6 | 7 |
"testing" |
| 8 |
+ "time" |
|
| 7 | 9 |
) |
| 8 | 10 |
|
| 9 |
-func TestCLIGetEvents(t *testing.T) {
|
|
| 11 |
+func TestCLIGetEventsUntag(t *testing.T) {
|
|
| 10 | 12 |
out, _, _ := cmd(t, "images", "-q") |
| 11 | 13 |
image := strings.Split(out, "\n")[0] |
| 12 | 14 |
cmd(t, "tag", image, "utest:tag1") |
| ... | ... |
@@ -27,3 +29,29 @@ func TestCLIGetEvents(t *testing.T) {
|
| 27 | 27 |
} |
| 28 | 28 |
logDone("events - untags are logged")
|
| 29 | 29 |
} |
| 30 |
+ |
|
| 31 |
+func TestCLIGetEventsPause(t *testing.T) {
|
|
| 32 |
+ out, _, _ := cmd(t, "images", "-q") |
|
| 33 |
+ image := strings.Split(out, "\n")[0] |
|
| 34 |
+ cmd(t, "run", "-d", "--name", "testeventpause", image, "sleep", "2") |
|
| 35 |
+ cmd(t, "pause", "testeventpause") |
|
| 36 |
+ cmd(t, "unpause", "testeventpause") |
|
| 37 |
+ eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", time.Now().Unix()))
|
|
| 38 |
+ out, _, _ = runCommandWithOutput(eventsCmd) |
|
| 39 |
+ events := strings.Split(out, "\n") |
|
| 40 |
+ if len(events) <= 1 {
|
|
| 41 |
+ t.Fatalf("Missing expected event")
|
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ pauseEvent := strings.Fields(events[len(events)-3]) |
|
| 45 |
+ unpauseEvent := strings.Fields(events[len(events)-2]) |
|
| 46 |
+ |
|
| 47 |
+ if pauseEvent[len(pauseEvent)-1] != "pause" {
|
|
| 48 |
+ t.Fatalf("event should be pause, not %#v", pauseEvent)
|
|
| 49 |
+ } |
|
| 50 |
+ if unpauseEvent[len(unpauseEvent)-1] != "unpause" {
|
|
| 51 |
+ t.Fatalf("event should be pause, not %#v", unpauseEvent)
|
|
| 52 |
+ } |
|
| 53 |
+ |
|
| 54 |
+ logDone("events - pause/unpause is logged")
|
|
| 55 |
+} |
| ... | ... |
@@ -183,6 +183,7 @@ func (srv *Server) ContainerPause(job *engine.Job) engine.Status {
|
| 183 | 183 |
if err := container.Pause(); err != nil {
|
| 184 | 184 |
return job.Errorf("Cannot pause container %s: %s", name, err)
|
| 185 | 185 |
} |
| 186 |
+ srv.LogEvent("pause", container.ID, srv.daemon.Repositories().ImageName(container.Image))
|
|
| 186 | 187 |
return engine.StatusOK |
| 187 | 188 |
} |
| 188 | 189 |
|
| ... | ... |
@@ -198,6 +199,7 @@ func (srv *Server) ContainerUnpause(job *engine.Job) engine.Status {
|
| 198 | 198 |
if err := container.Unpause(); err != nil {
|
| 199 | 199 |
return job.Errorf("Cannot unpause container %s: %s", name, err)
|
| 200 | 200 |
} |
| 201 |
+ srv.LogEvent("unpause", container.ID, srv.daemon.Repositories().ImageName(container.Image))
|
|
| 201 | 202 |
return engine.StatusOK |
| 202 | 203 |
} |
| 203 | 204 |
|