1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #17200 from maaquib/16756-integration-cli-events-test

Using checkers assert for integration-cli/docker_cli_events_test.go
This commit is contained in:
Vincent Demeester 2015-11-12 16:43:12 +01:00
commit ce29a8cc37

View file

@ -39,12 +39,8 @@ func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
since, until := f(start), f(end) since, until := f(start), f(end)
out, _ := dockerCmd(c, "events", "--since="+since, "--until="+until) out, _ := dockerCmd(c, "events", "--since="+since, "--until="+until)
events := strings.Split(strings.TrimSpace(out), "\n") events := strings.Split(strings.TrimSpace(out), "\n")
if len(events) != 2 { c.Assert(events, checker.HasLen, 2, check.Commentf("unexpected events, was expecting only 2 events tag/untag (since=%s, until=%s) out=%s", since, until, out))
c.Fatalf("unexpected events, was expecting only 2 events tag/untag (since=%s, until=%s) out=%s", since, until, out) c.Assert(out, checker.Contains, "untag", check.Commentf("expected 'untag' event not found (since=%s, until=%s)", since, until))
}
if !strings.Contains(out, "untag") {
c.Fatalf("expected 'untag' event not found (since=%s, until=%s) out=%s", since, until, out)
}
} }
} }
@ -58,18 +54,15 @@ func (s *DockerSuite) TestEventsUntag(c *check.C) {
dockerCmd(c, "rmi", "utest:tag2") dockerCmd(c, "rmi", "utest:tag2")
eventsCmd := exec.Command(dockerBinary, "events", "--since=1") eventsCmd := exec.Command(dockerBinary, "events", "--since=1")
out, exitCode, _, err := runCommandWithOutputForDuration(eventsCmd, time.Duration(time.Millisecond*200)) out, exitCode, _, err := runCommandWithOutputForDuration(eventsCmd, time.Duration(time.Millisecond*200))
if exitCode != 0 || err != nil { c.Assert(err, checker.IsNil)
c.Fatalf("Failed to get events - exit code %d: %s", exitCode, err) c.Assert(exitCode, checker.Equals, 0, check.Commentf("Failed to get events"))
}
events := strings.Split(out, "\n") events := strings.Split(out, "\n")
nEvents := len(events) nEvents := len(events)
// The last element after the split above will be an empty string, so we // 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 // get the two elements before the last, which are the untags we're
// looking for. // looking for.
for _, v := range events[nEvents-3 : nEvents-1] { for _, v := range events[nEvents-3 : nEvents-1] {
if !strings.Contains(v, "untag") { c.Assert(v, checker.Contains, "untag", check.Commentf("event should be untag"))
c.Fatalf("event should be untag, not %#v", v)
}
} }
} }
@ -77,25 +70,18 @@ func (s *DockerSuite) TestEventsContainerFailStartDie(c *check.C) {
out, _ := dockerCmd(c, "images", "-q") out, _ := dockerCmd(c, "images", "-q")
image := strings.Split(out, "\n")[0] image := strings.Split(out, "\n")[0]
if _, _, err := dockerCmdWithError("run", "--name", "testeventdie", image, "blerg"); err == nil { _, _, err := dockerCmdWithError("run", "--name", "testeventdie", image, "blerg")
c.Fatalf("Container run with command blerg should have failed, but it did not") c.Assert(err, checker.NotNil, check.Commentf("Container run with command blerg should have failed, but it did not, out=%s", out))
}
out, _ = dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) out, _ = dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
events := strings.Split(out, "\n") events := strings.Split(out, "\n")
if len(events) <= 1 { c.Assert(len(events), checker.GreaterThan, 1) //Missing expected event
c.Fatalf("Missing expected event")
}
startEvent := strings.Fields(events[len(events)-3]) startEvent := strings.Fields(events[len(events)-3])
dieEvent := strings.Fields(events[len(events)-2]) dieEvent := strings.Fields(events[len(events)-2])
if startEvent[len(startEvent)-1] != "start" { c.Assert(startEvent[len(startEvent)-1], checker.Equals, "start", check.Commentf("event should be start, not %#v", startEvent))
c.Fatalf("event should be start, not %#v", startEvent) c.Assert(dieEvent[len(dieEvent)-1], checker.Equals, "die", check.Commentf("event should be die, not %#v", dieEvent))
}
if dieEvent[len(dieEvent)-1] != "die" {
c.Fatalf("event should be die, not %#v", dieEvent)
}
} }
@ -117,17 +103,13 @@ func (s *DockerSuite) TestEventsLimit(c *check.C) {
close(errChan) close(errChan)
for err := range errChan { for err := range errChan {
if err != nil { c.Assert(err, checker.IsNil, check.Commentf("%q failed with error", strings.Join(args, " ")))
c.Fatalf("%q failed with error: %v", strings.Join(args, " "), err)
}
} }
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
events := strings.Split(out, "\n") events := strings.Split(out, "\n")
nEvents := len(events) - 1 nEvents := len(events) - 1
if nEvents != 64 { c.Assert(nEvents, checker.Equals, 64, check.Commentf("events should be limited to 64, but received %d", nEvents))
c.Fatalf("events should be limited to 64, but received %d", nEvents)
}
} }
func (s *DockerSuite) TestEventsContainerEvents(c *check.C) { func (s *DockerSuite) TestEventsContainerEvents(c *check.C) {
@ -136,29 +118,17 @@ func (s *DockerSuite) TestEventsContainerEvents(c *check.C) {
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
events := strings.Split(out, "\n") events := strings.Split(out, "\n")
events = events[:len(events)-1] events = events[:len(events)-1]
if len(events) < 5 { c.Assert(len(events), checker.GreaterOrEqualThan, 5) //Missing expected event
c.Fatalf("Missing expected event")
}
createEvent := strings.Fields(events[len(events)-5]) createEvent := strings.Fields(events[len(events)-5])
attachEvent := strings.Fields(events[len(events)-4]) attachEvent := strings.Fields(events[len(events)-4])
startEvent := strings.Fields(events[len(events)-3]) startEvent := strings.Fields(events[len(events)-3])
dieEvent := strings.Fields(events[len(events)-2]) dieEvent := strings.Fields(events[len(events)-2])
destroyEvent := strings.Fields(events[len(events)-1]) destroyEvent := strings.Fields(events[len(events)-1])
if createEvent[len(createEvent)-1] != "create" { c.Assert(createEvent[len(createEvent)-1], checker.Equals, "create", check.Commentf("event should be create, not %#v", createEvent))
c.Fatalf("event should be create, not %#v", createEvent) c.Assert(attachEvent[len(attachEvent)-1], checker.Equals, "attach", check.Commentf("event should be attach, not %#v", attachEvent))
} c.Assert(startEvent[len(startEvent)-1], checker.Equals, "start", check.Commentf("event should be start, not %#v", startEvent))
if attachEvent[len(attachEvent)-1] != "attach" { c.Assert(dieEvent[len(dieEvent)-1], checker.Equals, "die", check.Commentf("event should be die, not %#v", dieEvent))
c.Fatalf("event should be attach, not %#v", attachEvent) c.Assert(destroyEvent[len(destroyEvent)-1], checker.Equals, "destroy", check.Commentf("event should be destroy, not %#v", destroyEvent))
}
if startEvent[len(startEvent)-1] != "start" {
c.Fatalf("event should be start, not %#v", startEvent)
}
if dieEvent[len(dieEvent)-1] != "die" {
c.Fatalf("event should be die, not %#v", dieEvent)
}
if destroyEvent[len(destroyEvent)-1] != "destroy" {
c.Fatalf("event should be destroy, not %#v", destroyEvent)
}
} }
@ -171,29 +141,17 @@ func (s *DockerSuite) TestEventsContainerEventsSinceUnixEpoch(c *check.C) {
fmt.Sprintf("--until=%d", daemonTime(c).Unix())) fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
events := strings.Split(out, "\n") events := strings.Split(out, "\n")
events = events[:len(events)-1] events = events[:len(events)-1]
if len(events) < 5 { c.Assert(len(events), checker.GreaterOrEqualThan, 5) //Missing expected event
c.Fatalf("Missing expected event")
}
createEvent := strings.Fields(events[len(events)-5]) createEvent := strings.Fields(events[len(events)-5])
attachEvent := strings.Fields(events[len(events)-4]) attachEvent := strings.Fields(events[len(events)-4])
startEvent := strings.Fields(events[len(events)-3]) startEvent := strings.Fields(events[len(events)-3])
dieEvent := strings.Fields(events[len(events)-2]) dieEvent := strings.Fields(events[len(events)-2])
destroyEvent := strings.Fields(events[len(events)-1]) destroyEvent := strings.Fields(events[len(events)-1])
if createEvent[len(createEvent)-1] != "create" { c.Assert(createEvent[len(createEvent)-1], checker.Equals, "create", check.Commentf("event should be create, not %#v", createEvent))
c.Fatalf("event should be create, not %#v", createEvent) c.Assert(attachEvent[len(attachEvent)-1], checker.Equals, "attach", check.Commentf("event should be attach, not %#v", attachEvent))
} c.Assert(startEvent[len(startEvent)-1], checker.Equals, "start", check.Commentf("event should be start, not %#v", startEvent))
if attachEvent[len(attachEvent)-1] != "attach" { c.Assert(dieEvent[len(dieEvent)-1], checker.Equals, "die", check.Commentf("event should be die, not %#v", dieEvent))
c.Fatalf("event should be attach, not %#v", attachEvent) c.Assert(destroyEvent[len(destroyEvent)-1], checker.Equals, "destroy", check.Commentf("event should be destroy, not %#v", destroyEvent))
}
if startEvent[len(startEvent)-1] != "start" {
c.Fatalf("event should be start, not %#v", startEvent)
}
if dieEvent[len(dieEvent)-1] != "die" {
c.Fatalf("event should be die, not %#v", dieEvent)
}
if destroyEvent[len(destroyEvent)-1] != "destroy" {
c.Fatalf("event should be destroy, not %#v", destroyEvent)
}
} }
@ -204,27 +162,17 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) {
`FROM scratch `FROM scratch
MAINTAINER "docker"`, MAINTAINER "docker"`,
true) true)
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err) c.Assert(deleteImages(name), checker.IsNil)
}
if err := deleteImages(name); err != nil {
c.Fatal(err)
}
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
events := strings.Split(out, "\n") events := strings.Split(out, "\n")
events = events[:len(events)-1] events = events[:len(events)-1]
if len(events) < 2 { c.Assert(len(events), checker.GreaterOrEqualThan, 2) //Missing expected event
c.Fatalf("Missing expected event")
}
untagEvent := strings.Fields(events[len(events)-2]) untagEvent := strings.Fields(events[len(events)-2])
deleteEvent := strings.Fields(events[len(events)-1]) deleteEvent := strings.Fields(events[len(events)-1])
if untagEvent[len(untagEvent)-1] != "untag" { c.Assert(untagEvent[len(untagEvent)-1], checker.Equals, "untag", check.Commentf("untag should be untag, not %#v", untagEvent))
c.Fatalf("untag should be untag, not %#v", untagEvent) c.Assert(deleteEvent[len(deleteEvent)-1], checker.Equals, "delete", check.Commentf("untag should be delete, not %#v", untagEvent))
}
if deleteEvent[len(deleteEvent)-1] != "delete" {
c.Fatalf("delete should be delete, not %#v", deleteEvent)
}
} }
func (s *DockerSuite) TestEventsImageTag(c *check.C) { func (s *DockerSuite) TestEventsImageTag(c *check.C) {
@ -239,15 +187,11 @@ func (s *DockerSuite) TestEventsImageTag(c *check.C) {
fmt.Sprintf("--until=%d", daemonTime(c).Unix())) fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
events := strings.Split(strings.TrimSpace(out), "\n") events := strings.Split(strings.TrimSpace(out), "\n")
if len(events) != 1 { c.Assert(events, checker.HasLen, 1, check.Commentf("was expecting 1 event. out=%s", out))
c.Fatalf("was expecting 1 event. out=%s", out)
}
event := strings.TrimSpace(events[0]) event := strings.TrimSpace(events[0])
expectedStr := image + ": tag" expectedStr := image + ": tag"
if !strings.HasSuffix(event, expectedStr) { c.Assert(event, checker.HasSuffix, expectedStr, check.Commentf("wrong event format. expected='%s' got=%s", expectedStr, event))
c.Fatalf("wrong event format. expected='%s' got=%s", expectedStr, event)
}
} }
@ -265,9 +209,7 @@ func (s *DockerSuite) TestEventsImagePull(c *check.C) {
events := strings.Split(strings.TrimSpace(out), "\n") events := strings.Split(strings.TrimSpace(out), "\n")
event := strings.TrimSpace(events[len(events)-1]) event := strings.TrimSpace(events[len(events)-1])
if !strings.HasSuffix(event, "hello-world:latest: pull") { c.Assert(event, checker.HasSuffix, "hello-world:latest: pull", check.Commentf("Missing pull event - got:%q", event))
c.Fatalf("Missing pull event - got:%q", event)
}
} }
@ -279,12 +221,8 @@ func (s *DockerSuite) TestEventsImageImport(c *check.C) {
eventImport := make(chan struct{}) eventImport := make(chan struct{})
eventsCmd := exec.Command(dockerBinary, "events", "--since", strconv.FormatInt(since, 10)) eventsCmd := exec.Command(dockerBinary, "events", "--since", strconv.FormatInt(since, 10))
stdout, err := eventsCmd.StdoutPipe() stdout, err := eventsCmd.StdoutPipe()
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err) c.Assert(eventsCmd.Start(), checker.IsNil)
}
if err := eventsCmd.Start(); err != nil {
c.Fatal(err)
}
defer eventsCmd.Process.Kill() defer eventsCmd.Process.Kill()
go func() { go func() {
@ -306,9 +244,7 @@ func (s *DockerSuite) TestEventsImageImport(c *check.C) {
exec.Command(dockerBinary, "export", cleanedContainerID), exec.Command(dockerBinary, "export", cleanedContainerID),
exec.Command(dockerBinary, "import", "-"), exec.Command(dockerBinary, "import", "-"),
) )
if err != nil { c.Assert(err, checker.IsNil, check.Commentf("import failed with output: %q", out))
c.Errorf("import failed with errors: %v, output: %q", err, out)
}
newContainerID := strings.TrimSpace(out) newContainerID := strings.TrimSpace(out)
id <- newContainerID id <- newContainerID
@ -328,9 +264,7 @@ func (s *DockerSuite) TestEventsFilters(c *check.C) {
for _, event := range events { for _, event := range events {
eventFields := strings.Fields(event) eventFields := strings.Fields(event)
eventName := eventFields[len(eventFields)-1] eventName := eventFields[len(eventFields)-1]
if ok, err := regexp.MatchString(match, eventName); err != nil || !ok { c.Assert(eventName, checker.Matches, match)
c.Fatalf("event should match %s, got %#v, err: %v", match, eventFields, err)
}
} }
} }
@ -345,9 +279,7 @@ func (s *DockerSuite) TestEventsFilters(c *check.C) {
// make sure we at least got 2 start events // make sure we at least got 2 start events
count := strings.Count(out, "start") count := strings.Count(out, "start")
if count < 2 { c.Assert(strings.Count(out, "start"), checker.GreaterOrEqualThan, 2, check.Commentf("should have had 2 start events but had %d, out: %s", count, out))
c.Fatalf("should have had 2 start events but had %d, out: %s", count, out)
}
} }
@ -365,9 +297,7 @@ func (s *DockerSuite) TestEventsFilterImageName(c *check.C) {
out, _ = dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", fmt.Sprintf("image=%s", name)) out, _ = dockerCmd(c, "events", fmt.Sprintf("--since=%d", since), fmt.Sprintf("--until=%d", daemonTime(c).Unix()), "--filter", fmt.Sprintf("image=%s", name))
events := strings.Split(out, "\n") events := strings.Split(out, "\n")
events = events[:len(events)-1] events = events[:len(events)-1]
if len(events) == 0 { c.Assert(events, checker.Not(checker.HasLen), 0) //Expected events but found none for the image busybox:latest
c.Fatalf("Expected events but found none for the image busybox:latest")
}
count1 := 0 count1 := 0
count2 := 0 count2 := 0
@ -378,9 +308,8 @@ func (s *DockerSuite) TestEventsFilterImageName(c *check.C) {
count2++ count2++
} }
} }
if count1 == 0 || count2 == 0 { c.Assert(count1, checker.Not(checker.Equals), 0, check.Commentf("Expected event from container but got %d from %s", count1, container1))
c.Fatalf("Expected events from each container but got %d from %s and %d from %s", count1, container1, count2, container2) c.Assert(count2, checker.Not(checker.Equals), 0, check.Commentf("Expected event from container but got %d from %s", count2, container2))
}
} }
@ -407,7 +336,7 @@ func (s *DockerSuite) TestEventsFilterLabels(c *check.C) {
for _, e := range events { for _, e := range events {
c.Assert(e, checker.Contains, container1) c.Assert(e, checker.Contains, container1)
c.Assert(e, check.Not(checker.Contains), container2) c.Assert(e, checker.Not(checker.Contains), container2)
} }
} }
@ -421,9 +350,7 @@ func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) {
_, err := buildImage(name, fmt.Sprintf(` _, err := buildImage(name, fmt.Sprintf(`
FROM busybox:latest FROM busybox:latest
LABEL %s`, label), true) LABEL %s`, label), true)
if err != nil { c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image"))
c.Fatalf("Couldn't create image: %q", err)
}
dockerCmd(c, "tag", name, "labelfiltertest:tag1") dockerCmd(c, "tag", name, "labelfiltertest:tag1")
dockerCmd(c, "tag", name, "labelfiltertest:tag2") dockerCmd(c, "tag", name, "labelfiltertest:tag2")
@ -439,7 +366,7 @@ func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) {
events := strings.Split(strings.TrimSpace(out), "\n") events := strings.Split(strings.TrimSpace(out), "\n")
// 2 events from the "docker tag" command, another one is from "docker build" // 2 events from the "docker tag" command, another one is from "docker build"
c.Assert(len(events), checker.Equals, 3, check.Commentf("Events == %s", events)) c.Assert(events, checker.HasLen, 3, check.Commentf("Events == %s", events))
for _, e := range events { for _, e := range events {
c.Assert(e, checker.Contains, "labelfiltertest") c.Assert(e, checker.Contains, "labelfiltertest")
} }
@ -453,9 +380,7 @@ func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
for _, name := range []string{"container_1", "container_2"} { for _, name := range []string{"container_1", "container_2"} {
dockerCmd(c, "run", "--name", name, "busybox", "true") dockerCmd(c, "run", "--name", name, "busybox", "true")
id, err := inspectField(name, "Id") id, err := inspectField(name, "Id")
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err)
}
nameID[name] = id nameID[name] = id
} }
@ -484,16 +409,12 @@ func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
// filter by names // filter by names
out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+name) out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+name)
events := strings.Split(strings.TrimSuffix(out, "\n"), "\n") events := strings.Split(strings.TrimSuffix(out, "\n"), "\n")
if err := checkEvents(ID, events); err != nil { c.Assert(checkEvents(ID, events), checker.IsNil)
c.Fatal(err)
}
// filter by ID's // filter by ID's
out, _ = dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+ID) out, _ = dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+ID)
events = strings.Split(strings.TrimSuffix(out, "\n"), "\n") events = strings.Split(strings.TrimSuffix(out, "\n"), "\n")
if err := checkEvents(ID, events); err != nil { c.Assert(checkEvents(ID, events), checker.IsNil)
c.Fatal(err)
}
} }
} }
@ -509,12 +430,8 @@ func (s *DockerSuite) TestEventsStreaming(c *check.C) {
eventsCmd := exec.Command(dockerBinary, "events", "--since", strconv.FormatInt(start, 10)) eventsCmd := exec.Command(dockerBinary, "events", "--since", strconv.FormatInt(start, 10))
stdout, err := eventsCmd.StdoutPipe() stdout, err := eventsCmd.StdoutPipe()
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err) c.Assert(eventsCmd.Start(), checker.IsNil, check.Commentf("failed to start 'docker events'"))
}
if err := eventsCmd.Start(); err != nil {
c.Fatalf("failed to start 'docker events': %s", err)
}
defer eventsCmd.Process.Kill() defer eventsCmd.Process.Kill()
go func() { go func() {
@ -581,15 +498,13 @@ func (s *DockerSuite) TestEventsCommit(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
c.Assert(waitRun(cID), check.IsNil) c.Assert(waitRun(cID), checker.IsNil)
dockerCmd(c, "commit", "-m", "test", cID) dockerCmd(c, "commit", "-m", "test", cID)
dockerCmd(c, "stop", cID) dockerCmd(c, "stop", cID)
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
if !strings.Contains(out, " commit\n") { c.Assert(out, checker.Contains, " commit\n", check.Commentf("Missing 'commit' log event"))
c.Fatalf("Missing 'commit' log event\n%s", out)
}
} }
func (s *DockerSuite) TestEventsCopy(c *check.C) { func (s *DockerSuite) TestEventsCopy(c *check.C) {
@ -600,36 +515,26 @@ func (s *DockerSuite) TestEventsCopy(c *check.C) {
id, err := buildImage("cpimg", ` id, err := buildImage("cpimg", `
FROM busybox FROM busybox
RUN echo HI > /tmp/file`, true) RUN echo HI > /tmp/file`, true)
if err != nil { c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image"))
c.Fatalf("Couldn't create image: %q", err)
}
// Create an empty test file. // Create an empty test file.
tempFile, err := ioutil.TempFile("", "test-events-copy-") tempFile, err := ioutil.TempFile("", "test-events-copy-")
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err)
}
defer os.Remove(tempFile.Name()) defer os.Remove(tempFile.Name())
if err := tempFile.Close(); err != nil { c.Assert(tempFile.Close(), checker.IsNil)
c.Fatal(err)
}
dockerCmd(c, "create", "--name=cptest", id) dockerCmd(c, "create", "--name=cptest", id)
dockerCmd(c, "cp", "cptest:/tmp/file", tempFile.Name()) dockerCmd(c, "cp", "cptest:/tmp/file", tempFile.Name())
out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since))) out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since)))
if !strings.Contains(out, " archive-path\n") { c.Assert(out, checker.Contains, " archive-path\n", check.Commentf("Missing 'archive-path' log event\n"))
c.Fatalf("Missing 'archive-path' log event\n%s", out)
}
dockerCmd(c, "cp", tempFile.Name(), "cptest:/tmp/filecopy") dockerCmd(c, "cp", tempFile.Name(), "cptest:/tmp/filecopy")
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since))) out, _ = dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+strconv.Itoa(int(since)))
if !strings.Contains(out, " extract-to-dir\n") { c.Assert(out, checker.Contains, " extract-to-dir\n", check.Commentf("Missing 'extract-to-dir' log event"))
c.Fatalf("Missing 'extract-to-dir' log event\n%s", out)
}
} }
func (s *DockerSuite) TestEventsResize(c *check.C) { func (s *DockerSuite) TestEventsResize(c *check.C) {
@ -638,19 +543,17 @@ func (s *DockerSuite) TestEventsResize(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
c.Assert(waitRun(cID), check.IsNil) c.Assert(waitRun(cID), checker.IsNil)
endpoint := "/containers/" + cID + "/resize?h=80&w=24" endpoint := "/containers/" + cID + "/resize?h=80&w=24"
status, _, err := sockRequest("POST", endpoint, nil) status, _, err := sockRequest("POST", endpoint, nil)
c.Assert(status, check.Equals, http.StatusOK) c.Assert(status, checker.Equals, http.StatusOK)
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
dockerCmd(c, "stop", cID) dockerCmd(c, "stop", cID)
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
if !strings.Contains(out, " resize\n") { c.Assert(out, checker.Contains, " resize\n", check.Commentf("Missing 'resize' log event"))
c.Fatalf("Missing 'resize' log event\n%s", out)
}
} }
func (s *DockerSuite) TestEventsAttach(c *check.C) { func (s *DockerSuite) TestEventsAttach(c *check.C) {
@ -662,32 +565,27 @@ func (s *DockerSuite) TestEventsAttach(c *check.C) {
cmd := exec.Command(dockerBinary, "attach", cID) cmd := exec.Command(dockerBinary, "attach", cID)
stdin, err := cmd.StdinPipe() stdin, err := cmd.StdinPipe()
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
defer stdin.Close() defer stdin.Close()
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
defer stdout.Close() defer stdout.Close()
c.Assert(cmd.Start(), check.IsNil) c.Assert(cmd.Start(), checker.IsNil)
defer cmd.Process.Kill() defer cmd.Process.Kill()
// Make sure we're done attaching by writing/reading some stuff // Make sure we're done attaching by writing/reading some stuff
if _, err := stdin.Write([]byte("hello\n")); err != nil { _, err = stdin.Write([]byte("hello\n"))
c.Fatal(err) c.Assert(err, checker.IsNil)
}
out, err = bufio.NewReader(stdout).ReadString('\n') out, err = bufio.NewReader(stdout).ReadString('\n')
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
if strings.TrimSpace(out) != "hello" { c.Assert(strings.TrimSpace(out), checker.Equals, "hello", check.Commentf("expected 'hello'"))
c.Fatalf("expected 'hello', got %q", out)
}
c.Assert(stdin.Close(), check.IsNil) c.Assert(stdin.Close(), checker.IsNil)
dockerCmd(c, "stop", cID) dockerCmd(c, "stop", cID)
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
if !strings.Contains(out, " attach\n") { c.Assert(out, checker.Contains, " attach\n", check.Commentf("Missing 'attach' log event"))
c.Fatalf("Missing 'attach' log event\n%s", out)
}
} }
func (s *DockerSuite) TestEventsRename(c *check.C) { func (s *DockerSuite) TestEventsRename(c *check.C) {
@ -698,9 +596,7 @@ func (s *DockerSuite) TestEventsRename(c *check.C) {
dockerCmd(c, "rename", "oldName", "newName") dockerCmd(c, "rename", "oldName", "newName")
out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=newName", "--until="+strconv.Itoa(int(since))) out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=newName", "--until="+strconv.Itoa(int(since)))
if !strings.Contains(out, " rename\n") { c.Assert(out, checker.Contains, " rename\n", check.Commentf("Missing 'rename' log event\n"))
c.Fatalf("Missing 'rename' log event\n%s", out)
}
} }
func (s *DockerSuite) TestEventsTop(c *check.C) { func (s *DockerSuite) TestEventsTop(c *check.C) {
@ -709,15 +605,13 @@ func (s *DockerSuite) TestEventsTop(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
c.Assert(waitRun(cID), check.IsNil) c.Assert(waitRun(cID), checker.IsNil)
dockerCmd(c, "top", cID) dockerCmd(c, "top", cID)
dockerCmd(c, "stop", cID) dockerCmd(c, "stop", cID)
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since))) out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
if !strings.Contains(out, " top\n") { c.Assert(out, checker.Contains, " top\n", check.Commentf("Missing 'top' log event"))
c.Fatalf("Missing 'top' log event\n%s", out)
}
} }
// #13753 // #13753
@ -725,7 +619,7 @@ func (s *DockerSuite) TestEventsDefaultEmpty(c *check.C) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "busybox") dockerCmd(c, "run", "busybox")
out, _ := dockerCmd(c, "events", fmt.Sprintf("--until=%d", daemonTime(c).Unix())) out, _ := dockerCmd(c, "events", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
c.Assert(strings.TrimSpace(out), check.Equals, "") c.Assert(strings.TrimSpace(out), checker.Equals, "")
} }
// #14316 // #14316
@ -737,14 +631,12 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cID := strings.TrimSpace(out) cID := strings.TrimSpace(out)
c.Assert(waitRun(cID), check.IsNil) c.Assert(waitRun(cID), checker.IsNil)
dockerCmd(c, "commit", cID, repoName) dockerCmd(c, "commit", cID, repoName)
dockerCmd(c, "stop", cID) dockerCmd(c, "stop", cID)
dockerCmd(c, "push", repoName) dockerCmd(c, "push", repoName)
out, _ = dockerCmd(c, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since))) out, _ = dockerCmd(c, "events", "--since=0", "-f", "image="+repoName, "-f", "event=push", "--until="+strconv.Itoa(int(since)))
if !strings.Contains(out, repoName+": push\n") { c.Assert(out, checker.Contains, repoName+": push\n", check.Commentf("Missing 'push' log event"))
c.Fatalf("Missing 'push' log event for image %s\n%s", repoName, out)
}
} }