2014-06-05 06:32:19 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-07-07 11:47:06 -04:00
|
|
|
"fmt"
|
2014-06-05 06:32:19 -04:00
|
|
|
"os/exec"
|
2015-02-24 19:24:19 -05:00
|
|
|
"regexp"
|
2014-07-04 01:12:21 -04:00
|
|
|
"strconv"
|
2014-06-05 06:32:19 -04:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2014-07-07 11:47:06 -04:00
|
|
|
"time"
|
2014-06-05 06:32:19 -04:00
|
|
|
)
|
|
|
|
|
2014-09-19 04:37:50 -04:00
|
|
|
func TestEventsUntag(t *testing.T) {
|
2014-10-23 17:30:11 -04:00
|
|
|
image := "busybox"
|
2014-11-24 10:32:38 -05:00
|
|
|
dockerCmd(t, "tag", image, "utest:tag1")
|
|
|
|
dockerCmd(t, "tag", image, "utest:tag2")
|
|
|
|
dockerCmd(t, "rmi", "utest:tag1")
|
|
|
|
dockerCmd(t, "rmi", "utest:tag2")
|
2015-02-14 04:19:57 -05:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", "--since=1")
|
|
|
|
out, exitCode, _, err := runCommandWithOutputForDuration(eventsCmd, time.Duration(time.Millisecond*200))
|
|
|
|
if exitCode != 0 || err != nil {
|
|
|
|
t.Fatalf("Failed to get events - exit code %d: %s", exitCode, err)
|
|
|
|
}
|
2014-06-05 06:32:19 -04:00
|
|
|
events := strings.Split(out, "\n")
|
2014-10-06 10:26:55 -04:00
|
|
|
nEvents := len(events)
|
2014-06-05 06:32:19 -04:00
|
|
|
// The last element after the split above will be an empty string, so we
|
|
|
|
// get the two elements before the last, which are the untags we're
|
|
|
|
// looking for.
|
2014-10-06 10:26:55 -04:00
|
|
|
for _, v := range events[nEvents-3 : nEvents-1] {
|
2014-06-05 06:32:19 -04:00
|
|
|
if !strings.Contains(v, "untag") {
|
|
|
|
t.Fatalf("event should be untag, not %#v", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logDone("events - untags are logged")
|
|
|
|
}
|
2014-07-07 11:47:06 -04:00
|
|
|
|
2014-09-19 16:54:32 -04:00
|
|
|
func TestEventsContainerFailStartDie(t *testing.T) {
|
2014-11-17 11:05:49 -05:00
|
|
|
defer deleteAllContainers()
|
|
|
|
|
2014-11-24 10:32:38 -05:00
|
|
|
out, _, _ := dockerCmd(t, "images", "-q")
|
2014-09-19 16:54:32 -04:00
|
|
|
image := strings.Split(out, "\n")[0]
|
2015-01-30 12:29:46 -05:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "run", "--name", "testeventdie", image, "blerg")
|
2014-09-19 16:54:32 -04:00
|
|
|
_, _, err := runCommandWithOutput(eventsCmd)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Container run with command blerg should have failed, but it did not")
|
|
|
|
}
|
|
|
|
|
2015-03-10 17:19:32 -04:00
|
|
|
eventsCmd = exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(t).Unix()))
|
2014-09-19 16:54:32 -04:00
|
|
|
out, _, _ = runCommandWithOutput(eventsCmd)
|
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
if len(events) <= 1 {
|
|
|
|
t.Fatalf("Missing expected event")
|
|
|
|
}
|
|
|
|
|
|
|
|
startEvent := strings.Fields(events[len(events)-3])
|
|
|
|
dieEvent := strings.Fields(events[len(events)-2])
|
|
|
|
|
|
|
|
if startEvent[len(startEvent)-1] != "start" {
|
|
|
|
t.Fatalf("event should be start, not %#v", startEvent)
|
|
|
|
}
|
|
|
|
if dieEvent[len(dieEvent)-1] != "die" {
|
|
|
|
t.Fatalf("event should be die, not %#v", dieEvent)
|
|
|
|
}
|
|
|
|
|
2015-02-09 18:01:52 -05:00
|
|
|
logDone("events - container unwilling to start logs die")
|
2014-09-19 16:54:32 -04:00
|
|
|
}
|
|
|
|
|
2014-09-19 04:37:50 -04:00
|
|
|
func TestEventsLimit(t *testing.T) {
|
2014-11-17 11:05:49 -05:00
|
|
|
defer deleteAllContainers()
|
2014-07-04 01:12:21 -04:00
|
|
|
for i := 0; i < 30; i++ {
|
2014-11-24 10:32:38 -05:00
|
|
|
dockerCmd(t, "run", "busybox", "echo", strconv.Itoa(i))
|
2014-07-04 01:12:21 -04:00
|
|
|
}
|
2015-03-10 17:19:32 -04:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(t).Unix()))
|
2014-07-04 01:12:21 -04:00
|
|
|
out, _, _ := runCommandWithOutput(eventsCmd)
|
|
|
|
events := strings.Split(out, "\n")
|
2014-10-06 10:26:55 -04:00
|
|
|
nEvents := len(events) - 1
|
|
|
|
if nEvents != 64 {
|
|
|
|
t.Fatalf("events should be limited to 64, but received %d", nEvents)
|
2014-07-04 01:12:21 -04:00
|
|
|
}
|
|
|
|
logDone("events - limited to 64 entries")
|
|
|
|
}
|
2014-08-11 01:54:59 -04:00
|
|
|
|
2014-09-19 04:37:50 -04:00
|
|
|
func TestEventsContainerEvents(t *testing.T) {
|
2014-11-24 10:32:38 -05:00
|
|
|
dockerCmd(t, "run", "--rm", "busybox", "true")
|
2015-03-10 17:19:32 -04:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(t).Unix()))
|
2014-08-11 01:54:59 -04:00
|
|
|
out, exitCode, err := runCommandWithOutput(eventsCmd)
|
|
|
|
if exitCode != 0 || err != nil {
|
2014-08-13 03:37:30 -04:00
|
|
|
t.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
|
2014-08-11 01:54:59 -04:00
|
|
|
}
|
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
events = events[:len(events)-1]
|
|
|
|
if len(events) < 4 {
|
|
|
|
t.Fatalf("Missing expected event")
|
|
|
|
}
|
|
|
|
createEvent := strings.Fields(events[len(events)-4])
|
|
|
|
startEvent := strings.Fields(events[len(events)-3])
|
|
|
|
dieEvent := strings.Fields(events[len(events)-2])
|
|
|
|
destroyEvent := strings.Fields(events[len(events)-1])
|
|
|
|
if createEvent[len(createEvent)-1] != "create" {
|
|
|
|
t.Fatalf("event should be create, not %#v", createEvent)
|
|
|
|
}
|
|
|
|
if startEvent[len(startEvent)-1] != "start" {
|
2014-11-20 14:46:48 -05:00
|
|
|
t.Fatalf("event should be start, not %#v", startEvent)
|
2014-08-11 01:54:59 -04:00
|
|
|
}
|
|
|
|
if dieEvent[len(dieEvent)-1] != "die" {
|
2014-11-20 14:46:48 -05:00
|
|
|
t.Fatalf("event should be die, not %#v", dieEvent)
|
2014-08-11 01:54:59 -04:00
|
|
|
}
|
|
|
|
if destroyEvent[len(destroyEvent)-1] != "destroy" {
|
2014-11-20 14:46:48 -05:00
|
|
|
t.Fatalf("event should be destroy, not %#v", destroyEvent)
|
2014-08-11 01:54:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
logDone("events - container create, start, die, destroy is logged")
|
|
|
|
}
|
2014-08-11 03:39:47 -04:00
|
|
|
|
2014-09-19 04:37:50 -04:00
|
|
|
func TestEventsImageUntagDelete(t *testing.T) {
|
2014-08-11 03:39:47 -04:00
|
|
|
name := "testimageevents"
|
|
|
|
defer deleteImages(name)
|
|
|
|
_, err := buildImage(name,
|
|
|
|
`FROM scratch
|
|
|
|
MAINTAINER "docker"`,
|
|
|
|
true)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := deleteImages(name); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-03-10 17:19:32 -04:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(t).Unix()))
|
2014-08-11 03:39:47 -04:00
|
|
|
out, exitCode, err := runCommandWithOutput(eventsCmd)
|
|
|
|
if exitCode != 0 || err != nil {
|
2014-08-13 03:37:30 -04:00
|
|
|
t.Fatalf("Failed to get events with exit code %d: %s", exitCode, err)
|
2014-08-11 03:39:47 -04:00
|
|
|
}
|
|
|
|
events := strings.Split(out, "\n")
|
2015-02-19 16:33:23 -05:00
|
|
|
|
2014-08-11 03:39:47 -04:00
|
|
|
events = events[:len(events)-1]
|
|
|
|
if len(events) < 2 {
|
|
|
|
t.Fatalf("Missing expected event")
|
|
|
|
}
|
|
|
|
untagEvent := strings.Fields(events[len(events)-2])
|
|
|
|
deleteEvent := strings.Fields(events[len(events)-1])
|
|
|
|
if untagEvent[len(untagEvent)-1] != "untag" {
|
|
|
|
t.Fatalf("untag should be untag, not %#v", untagEvent)
|
|
|
|
}
|
|
|
|
if deleteEvent[len(deleteEvent)-1] != "delete" {
|
|
|
|
t.Fatalf("delete should be delete, not %#v", deleteEvent)
|
|
|
|
}
|
|
|
|
logDone("events - image untag, delete is logged")
|
|
|
|
}
|
2014-09-25 10:50:10 -04:00
|
|
|
|
2014-10-22 09:48:02 -04:00
|
|
|
func TestEventsImagePull(t *testing.T) {
|
2015-03-10 17:19:32 -04:00
|
|
|
since := daemonTime(t).Unix()
|
2015-02-05 20:46:55 -05:00
|
|
|
|
|
|
|
defer deleteImages("hello-world")
|
|
|
|
|
2014-10-28 17:06:23 -04:00
|
|
|
pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
|
2014-10-22 09:48:02 -04:00
|
|
|
if out, _, err := runCommandWithOutput(pullCmd); err != nil {
|
2014-10-28 17:06:23 -04:00
|
|
|
t.Fatalf("pulling the hello-world image from has failed: %s, %v", out, err)
|
2014-10-22 09:48:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
eventsCmd := exec.Command(dockerBinary, "events",
|
|
|
|
fmt.Sprintf("--since=%d", since),
|
2015-03-10 17:19:32 -04:00
|
|
|
fmt.Sprintf("--until=%d", daemonTime(t).Unix()))
|
2014-10-22 09:48:02 -04:00
|
|
|
out, _, _ := runCommandWithOutput(eventsCmd)
|
|
|
|
|
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
event := strings.TrimSpace(events[len(events)-1])
|
|
|
|
|
2014-10-28 17:06:23 -04:00
|
|
|
if !strings.HasSuffix(event, "hello-world:latest: pull") {
|
2014-10-22 09:48:02 -04:00
|
|
|
t.Fatalf("Missing pull event - got:%q", event)
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("events - image pull is logged")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEventsImageImport(t *testing.T) {
|
2015-02-19 16:33:23 -05:00
|
|
|
defer deleteAllContainers()
|
2015-03-10 17:19:32 -04:00
|
|
|
since := daemonTime(t).Unix()
|
2014-10-22 09:48:02 -04:00
|
|
|
|
2015-02-14 05:27:06 -05:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2014-10-22 09:48:02 -04:00
|
|
|
if err != nil {
|
2015-02-14 05:27:06 -05:00
|
|
|
t.Fatal("failed to create a container", out, err)
|
2014-10-22 09:48:02 -04:00
|
|
|
}
|
2015-02-14 05:27:06 -05:00
|
|
|
cleanedContainerID := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
out, _, err = runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "export", cleanedContainerID),
|
|
|
|
exec.Command(dockerBinary, "import", "-"),
|
|
|
|
)
|
2014-10-22 09:48:02 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("import failed with errors: %v, output: %q", err, out)
|
|
|
|
}
|
|
|
|
|
|
|
|
eventsCmd := exec.Command(dockerBinary, "events",
|
|
|
|
fmt.Sprintf("--since=%d", since),
|
2015-03-10 17:19:32 -04:00
|
|
|
fmt.Sprintf("--until=%d", daemonTime(t).Unix()))
|
2014-10-22 09:48:02 -04:00
|
|
|
out, _, _ = runCommandWithOutput(eventsCmd)
|
|
|
|
|
|
|
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
|
|
|
event := strings.TrimSpace(events[len(events)-1])
|
|
|
|
|
|
|
|
if !strings.HasSuffix(event, ": import") {
|
|
|
|
t.Fatalf("Missing pull event - got:%q", event)
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("events - image import is logged")
|
|
|
|
}
|
2014-11-20 14:46:48 -05:00
|
|
|
|
|
|
|
func TestEventsFilters(t *testing.T) {
|
2015-02-24 19:24:19 -05:00
|
|
|
parseEvents := func(out, match string) {
|
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
events = events[:len(events)-1]
|
|
|
|
for _, event := range events {
|
|
|
|
eventFields := strings.Fields(event)
|
|
|
|
eventName := eventFields[len(eventFields)-1]
|
|
|
|
if ok, err := regexp.MatchString(match, eventName); err != nil || !ok {
|
|
|
|
t.Fatalf("event should match %s, got %#v, err: %v", match, eventFields, err)
|
|
|
|
}
|
|
|
|
}
|
2015-02-19 16:33:23 -05:00
|
|
|
}
|
|
|
|
|
2015-03-10 17:19:32 -04:00
|
|
|
since := daemonTime(t).Unix()
|
2015-02-24 19:24:19 -05:00
|
|
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", "busybox", "true"))
|
2014-11-25 21:34:08 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(out, err)
|
|
|
|
}
|
2015-02-24 19:24:19 -05:00
|
|
|
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", "busybox", "true"))
|
2014-11-25 21:34:08 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(out, err)
|
|
|
|
}
|
2015-03-10 17:19:32 -04:00
|
|
|
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(t).Unix()), "--filter", "event=die"))
|
2015-02-19 16:33:23 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to get events: %s", err)
|
2014-11-20 14:46:48 -05:00
|
|
|
}
|
2015-02-24 19:24:19 -05:00
|
|
|
parseEvents(out, "die")
|
2014-11-20 14:46:48 -05:00
|
|
|
|
2015-03-10 17:19:32 -04:00
|
|
|
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(t).Unix()), "--filter", "event=die", "--filter", "event=start"))
|
2015-02-19 16:33:23 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to get events: %s", err)
|
2014-11-20 14:46:48 -05:00
|
|
|
}
|
2015-02-24 19:24:19 -05:00
|
|
|
parseEvents(out, "((die)|(start))")
|
|
|
|
|
|
|
|
// make sure we at least got 2 start events
|
|
|
|
count := strings.Count(out, "start")
|
2015-02-27 17:48:39 -05:00
|
|
|
if count < 2 {
|
2015-02-24 19:24:19 -05:00
|
|
|
t.Fatalf("should have had 2 start events but had %d, out: %s", count, out)
|
2014-11-20 14:46:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
logDone("events - filters")
|
|
|
|
}
|
2015-02-09 16:02:53 -05:00
|
|
|
|
|
|
|
func TestEventsFilterImageName(t *testing.T) {
|
2015-03-10 17:19:32 -04:00
|
|
|
since := daemonTime(t).Unix()
|
2015-02-09 16:02:53 -05:00
|
|
|
defer deleteAllContainers()
|
|
|
|
|
|
|
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_1", "-d", "busybox", "true"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(out, err)
|
|
|
|
}
|
|
|
|
container1 := stripTrailingCharacters(out)
|
2015-02-09 01:03:42 -05:00
|
|
|
|
2015-02-09 16:02:53 -05:00
|
|
|
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_2", "-d", "busybox", "true"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(out, err)
|
|
|
|
}
|
|
|
|
container2 := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
for _, s := range []string{"busybox", "busybox:latest"} {
|
2015-03-10 17:19:32 -04:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(t).Unix()), "--filter", fmt.Sprintf("image=%s", s))
|
2015-02-09 16:02:53 -05:00
|
|
|
out, _, err := runCommandWithOutput(eventsCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to get events, error: %s(%s)", err, out)
|
|
|
|
}
|
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
events = events[:len(events)-1]
|
|
|
|
if len(events) == 0 {
|
|
|
|
t.Fatalf("Expected events but found none for the image busybox:latest")
|
|
|
|
}
|
|
|
|
count1 := 0
|
|
|
|
count2 := 0
|
|
|
|
for _, e := range events {
|
|
|
|
if strings.Contains(e, container1) {
|
|
|
|
count1++
|
|
|
|
} else if strings.Contains(e, container2) {
|
|
|
|
count2++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if count1 == 0 || count2 == 0 {
|
|
|
|
t.Fatalf("Expected events from each container but got %d from %s and %d from %s", count1, container1, count2, container2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("events - filters using image")
|
2015-02-09 01:03:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEventsFilterContainerID(t *testing.T) {
|
2015-03-10 17:19:32 -04:00
|
|
|
since := daemonTime(t).Unix()
|
2015-02-09 01:03:42 -05:00
|
|
|
defer deleteAllContainers()
|
|
|
|
|
|
|
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "true"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(out, err)
|
|
|
|
}
|
|
|
|
container1 := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "busybox", "true"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(out, err)
|
|
|
|
}
|
|
|
|
container2 := stripTrailingCharacters(out)
|
|
|
|
|
|
|
|
for _, s := range []string{container1, container2, container1[:12], container2[:12]} {
|
2015-03-10 17:19:32 -04:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(t).Unix()), "--filter", fmt.Sprintf("container=%s", s))
|
2015-02-09 01:03:42 -05:00
|
|
|
out, _, err := runCommandWithOutput(eventsCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to get events, error: %s(%s)", err, out)
|
|
|
|
}
|
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
events = events[:len(events)-1]
|
|
|
|
if len(events) == 0 || len(events) > 3 {
|
|
|
|
t.Fatalf("Expected 3 events, got %d: %v", len(events), events)
|
|
|
|
}
|
|
|
|
createEvent := strings.Fields(events[0])
|
|
|
|
if createEvent[len(createEvent)-1] != "create" {
|
|
|
|
t.Fatalf("first event should be create, not %#v", createEvent)
|
|
|
|
}
|
|
|
|
if len(events) > 1 {
|
|
|
|
startEvent := strings.Fields(events[1])
|
|
|
|
if startEvent[len(startEvent)-1] != "start" {
|
|
|
|
t.Fatalf("second event should be start, not %#v", startEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(events) == 3 {
|
|
|
|
dieEvent := strings.Fields(events[len(events)-1])
|
|
|
|
if dieEvent[len(dieEvent)-1] != "die" {
|
|
|
|
t.Fatalf("event should be die, not %#v", dieEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("events - filters using container id")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEventsFilterContainerName(t *testing.T) {
|
2015-03-10 17:19:32 -04:00
|
|
|
since := daemonTime(t).Unix()
|
2015-02-09 01:03:42 -05:00
|
|
|
defer deleteAllContainers()
|
|
|
|
|
|
|
|
_, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_1", "busybox", "true"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "container_2", "busybox", "true"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range []string{"container_1", "container_2"} {
|
2015-03-10 17:19:32 -04:00
|
|
|
eventsCmd := exec.Command(dockerBinary, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(t).Unix()), "--filter", fmt.Sprintf("container=%s", s))
|
2015-02-09 01:03:42 -05:00
|
|
|
out, _, err := runCommandWithOutput(eventsCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to get events, error : %s(%s)", err, out)
|
|
|
|
}
|
|
|
|
events := strings.Split(out, "\n")
|
|
|
|
events = events[:len(events)-1]
|
|
|
|
if len(events) == 0 || len(events) > 3 {
|
|
|
|
t.Fatalf("Expected 3 events, got %d: %v", len(events), events)
|
|
|
|
}
|
|
|
|
createEvent := strings.Fields(events[0])
|
|
|
|
if createEvent[len(createEvent)-1] != "create" {
|
|
|
|
t.Fatalf("first event should be create, not %#v", createEvent)
|
|
|
|
}
|
|
|
|
if len(events) > 1 {
|
|
|
|
startEvent := strings.Fields(events[1])
|
|
|
|
if startEvent[len(startEvent)-1] != "start" {
|
|
|
|
t.Fatalf("second event should be start, not %#v", startEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(events) == 3 {
|
|
|
|
dieEvent := strings.Fields(events[len(events)-1])
|
|
|
|
if dieEvent[len(dieEvent)-1] != "die" {
|
|
|
|
t.Fatalf("event should be die, not %#v", dieEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-09 16:02:53 -05:00
|
|
|
|
2015-02-09 01:03:42 -05:00
|
|
|
logDone("events - filters using container name")
|
2015-02-09 16:02:53 -05:00
|
|
|
}
|