diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index 244a71fa74..1e655e666a 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -43,7 +43,7 @@ func (s *DockerCLIEventSuite) TestEventsTimestampFormats(c *testing.T) { // Start stopwatch, generate an event start := daemonTime(c) time.Sleep(1100 * time.Millisecond) // so that first event occur in different second from since (just for the case) - dockerCmd(c, "run", "--rm", "--name", name, "busybox", "true") + cli.DockerCmd(c, "run", "--rm", "--name", name, "busybox", "true") time.Sleep(1100 * time.Millisecond) // so that until > since end := daemonTime(c) @@ -55,7 +55,7 @@ func (s *DockerCLIEventSuite) TestEventsTimestampFormats(c *testing.T) { // --since=$start must contain only the 'untag' event for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} { since, until := f(start), f(end) - out, _ := dockerCmd(c, "events", "--since="+since, "--until="+until) + out := cli.DockerCmd(c, "events", "--since="+since, "--until="+until).Stdout() events := strings.Split(out, "\n") events = events[:len(events)-1] @@ -68,10 +68,10 @@ func (s *DockerCLIEventSuite) TestEventsTimestampFormats(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsUntag(c *testing.T) { image := "busybox" - dockerCmd(c, "tag", image, "utest:tag1") - dockerCmd(c, "tag", image, "utest:tag2") - dockerCmd(c, "rmi", "utest:tag1") - dockerCmd(c, "rmi", "utest:tag2") + cli.DockerCmd(c, "tag", image, "utest:tag1") + cli.DockerCmd(c, "tag", image, "utest:tag2") + cli.DockerCmd(c, "rmi", "utest:tag1") + cli.DockerCmd(c, "rmi", "utest:tag2") result := icmd.RunCmd(icmd.Cmd{ Command: []string{dockerBinary, "events", "--since=1"}, @@ -90,9 +90,9 @@ func (s *DockerCLIEventSuite) TestEventsUntag(c *testing.T) { } func (s *DockerCLIEventSuite) TestEventsContainerEvents(c *testing.T) { - dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true") + cli.DockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true") - out, _ := dockerCmd(c, "events", "--until", daemonUnixTime(c)) + out := cli.DockerCmd(c, "events", "--until", daemonUnixTime(c)).Stdout() events := strings.Split(out, "\n") events = events[:len(events)-1] @@ -105,9 +105,9 @@ func (s *DockerCLIEventSuite) TestEventsContainerEvents(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsContainerEventsAttrSort(c *testing.T) { since := daemonUnixTime(c) - dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true") + cli.DockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true") - out, _ := dockerCmd(c, "events", "--filter", "container=container-events-test", "--since", since, "--until", daemonUnixTime(c)) + out := cli.DockerCmd(c, "events", "--filter", "container=container-events-test", "--since", since, "--until", daemonUnixTime(c)).Stdout() events := strings.Split(out, "\n") nEvents := len(events) @@ -127,10 +127,10 @@ func (s *DockerCLIEventSuite) TestEventsContainerEventsAttrSort(c *testing.T) { } func (s *DockerCLIEventSuite) TestEventsContainerEventsSinceUnixEpoch(c *testing.T) { - dockerCmd(c, "run", "--rm", "--name", "since-epoch-test", "busybox", "true") + cli.DockerCmd(c, "run", "--rm", "--name", "since-epoch-test", "busybox", "true") timeBeginning := time.Unix(0, 0).Format(time.RFC3339Nano) timeBeginning = strings.ReplaceAll(timeBeginning, "Z", ".000000000Z") - out, _ := dockerCmd(c, "events", "--since", timeBeginning, "--until", daemonUnixTime(c)) + out := cli.DockerCmd(c, "events", "--since", timeBeginning, "--until", daemonUnixTime(c)).Stdout() events := strings.Split(out, "\n") events = events[:len(events)-1] @@ -144,10 +144,9 @@ func (s *DockerCLIEventSuite) TestEventsImageTag(c *testing.T) { time.Sleep(1 * time.Second) // because API has seconds granularity since := daemonUnixTime(c) image := "testimageevents:tag" - dockerCmd(c, "tag", "busybox", image) + cli.DockerCmd(c, "tag", "busybox", image) - out, _ := dockerCmd(c, "events", - "--since", since, "--until", daemonUnixTime(c)) + out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c)).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Equal(c, len(events), 1, "was expecting 1 event. out=%s", out) @@ -164,11 +163,9 @@ func (s *DockerCLIEventSuite) TestEventsImagePull(c *testing.T) { since := daemonUnixTime(c) testRequires(c, Network) - dockerCmd(c, "pull", "hello-world") - - out, _ := dockerCmd(c, "events", - "--since", since, "--until", daemonUnixTime(c)) + cli.DockerCmd(c, "pull", "hello-world") + out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c)).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") event := strings.TrimSpace(events[len(events)-1]) matches := eventstestutils.ScanMap(event) @@ -181,7 +178,7 @@ func (s *DockerCLIEventSuite) TestEventsImageImport(c *testing.T) { // more reliable (@swernli) testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "-d", "busybox", "true") + out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout() cleanedContainerID := strings.TrimSpace(out) since := daemonUnixTime(c) @@ -192,7 +189,7 @@ func (s *DockerCLIEventSuite) TestEventsImageImport(c *testing.T) { assert.NilError(c, err, "import failed with output: %q", out) imageRef := strings.TrimSpace(out) - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=import") + out = cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=import").Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Equal(c, len(events), 1) matches := eventstestutils.ScanMap(events[0]) @@ -203,35 +200,35 @@ func (s *DockerCLIEventSuite) TestEventsImageImport(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsImageLoad(c *testing.T) { testRequires(c, DaemonIsLinux) myImageName := "footest:v1" - dockerCmd(c, "tag", "busybox", myImageName) + cli.DockerCmd(c, "tag", "busybox", myImageName) since := daemonUnixTime(c) - out, _ := dockerCmd(c, "images", "-q", "--no-trunc", myImageName) + out := cli.DockerCmd(c, "images", "-q", "--no-trunc", myImageName).Stdout() longImageID := strings.TrimSpace(out) assert.Assert(c, longImageID != "", "Id should not be empty") - dockerCmd(c, "save", "-o", "saveimg.tar", myImageName) - dockerCmd(c, "rmi", myImageName) - out, _ = dockerCmd(c, "images", "-q", myImageName) + cli.DockerCmd(c, "save", "-o", "saveimg.tar", myImageName) + cli.DockerCmd(c, "rmi", myImageName) + out = cli.DockerCmd(c, "images", "-q", myImageName).Stdout() noImageID := strings.TrimSpace(out) assert.Equal(c, noImageID, "", "Should not have any image") - dockerCmd(c, "load", "-i", "saveimg.tar") + cli.DockerCmd(c, "load", "-i", "saveimg.tar") result := icmd.RunCommand("rm", "-rf", "saveimg.tar") result.Assert(c, icmd.Success) - out, _ = dockerCmd(c, "images", "-q", "--no-trunc", myImageName) + out = cli.DockerCmd(c, "images", "-q", "--no-trunc", myImageName).Stdout() imageID := strings.TrimSpace(out) assert.Equal(c, imageID, longImageID, "Should have same image id as before") - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=load") + out = cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=load").Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Equal(c, len(events), 1) matches := eventstestutils.ScanMap(events[0]) assert.Equal(c, matches["id"], imageID, "matches: %v\nout:\n%s\n", matches, out) assert.Equal(c, matches["action"], "load", "matches: %v\nout:\n%s\n", matches, out) - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=save") + out = cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=save").Stdout() events = strings.Split(strings.TrimSpace(out), "\n") assert.Equal(c, len(events), 1) matches = eventstestutils.ScanMap(events[0]) @@ -244,11 +241,11 @@ func (s *DockerCLIEventSuite) TestEventsPluginOps(c *testing.T) { since := daemonUnixTime(c) - dockerCmd(c, "plugin", "install", pNameWithTag, "--grant-all-permissions") - dockerCmd(c, "plugin", "disable", pNameWithTag) - dockerCmd(c, "plugin", "remove", pNameWithTag) + cli.DockerCmd(c, "plugin", "install", pNameWithTag, "--grant-all-permissions") + cli.DockerCmd(c, "plugin", "disable", pNameWithTag) + cli.DockerCmd(c, "plugin", "remove", pNameWithTag) - out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c)) + out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c)).Stdout() events := strings.Split(out, "\n") events = events[:len(events)-1] @@ -260,12 +257,12 @@ func (s *DockerCLIEventSuite) TestEventsPluginOps(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilters(c *testing.T) { since := daemonUnixTime(c) - dockerCmd(c, "run", "--rm", "busybox", "true") - dockerCmd(c, "run", "--rm", "busybox", "true") - out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=die") + cli.DockerCmd(c, "run", "--rm", "busybox", "true") + cli.DockerCmd(c, "run", "--rm", "busybox", "true") + out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=die").Stdout() parseEvents(c, out, "die") - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=die", "--filter", "event=start") + out = cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=die", "--filter", "event=start").Stdout() parseEvents(c, out, "die|start") // make sure we at least got 2 start events @@ -276,14 +273,14 @@ func (s *DockerCLIEventSuite) TestEventsFilters(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFilterImageName(c *testing.T) { since := daemonUnixTime(c) - out, _ := dockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true") + out := cli.DockerCmd(c, "run", "--name", "container_1", "-d", "busybox:latest", "true").Stdout() container1 := strings.TrimSpace(out) - out, _ = dockerCmd(c, "run", "--name", "container_2", "-d", "busybox", "true") + out = cli.DockerCmd(c, "run", "--name", "container_2", "-d", "busybox", "true").Stdout() container2 := strings.TrimSpace(out) name := "busybox" - out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", fmt.Sprintf("image=%s", name)) + out = cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", fmt.Sprintf("image=%s", name)).Stdout() events := strings.Split(out, "\n") events = events[:len(events)-1] assert.Assert(c, len(events) != 0, "Expected events but found none for the image busybox:latest") @@ -305,23 +302,22 @@ func (s *DockerCLIEventSuite) TestEventsFilterLabels(c *testing.T) { since := strconv.FormatUint(uint64(daemonTime(c).Unix()), 10) label := "io.docker.testing=foo" - out, exit := dockerCmd(c, "create", "-l", label, "busybox") - assert.Equal(c, exit, 0) - container1 := strings.TrimSpace(out) + result := cli.DockerCmd(c, "create", "-l", label, "busybox") + assert.Equal(c, result.ExitCode, 0) + container1 := strings.TrimSpace(result.Stdout()) - out, exit = dockerCmd(c, "create", "busybox") - assert.Equal(c, exit, 0) - container2 := strings.TrimSpace(out) + result = cli.DockerCmd(c, "create", "busybox") + assert.Equal(c, result.ExitCode, 0) + container2 := strings.TrimSpace(result.Stdout()) // fetch events with `--until`, so that the client detaches after a second // instead of staying attached, waiting for more events to arrive. - out, _ = dockerCmd( - c, + out := cli.DockerCmd(c, "events", "--since", since, "--until", strconv.FormatUint(uint64(daemonTime(c).Add(time.Second).Unix()), 10), "--filter", "label="+label, - ) + ).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Assert(c, len(events) > 0) @@ -345,17 +341,17 @@ func (s *DockerCLIEventSuite) TestEventsFilterImageLabels(c *testing.T) { buildImageSuccessfully(c, name, build.WithDockerfile(fmt.Sprintf(` FROM busybox:latest LABEL %s`, label))) - dockerCmd(c, "tag", name, "labelfiltertest:tag1") - dockerCmd(c, "tag", name, "labelfiltertest:tag2") - dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") + cli.DockerCmd(c, "tag", name, "labelfiltertest:tag1") + cli.DockerCmd(c, "tag", name, "labelfiltertest:tag2") + cli.DockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") - out, _ := dockerCmd( - c, + out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", fmt.Sprintf("label=%s", label), - "--filter", "type=image") + "--filter", "type=image", + ).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") @@ -371,7 +367,7 @@ func (s *DockerCLIEventSuite) TestEventsFilterContainer(c *testing.T) { nameID := make(map[string]string) for _, name := range []string{"container_1", "container_2"} { - dockerCmd(c, "run", "--name", name, "busybox", "true") + cli.DockerCmd(c, "run", "--name", name, "busybox", "true") id := inspectField(c, name, "Id") nameID[name] = id } @@ -393,12 +389,12 @@ func (s *DockerCLIEventSuite) TestEventsFilterContainer(c *testing.T) { for name, ID := range nameID { // filter by names - out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+name) + out := cli.DockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+name).Stdout() events := strings.Split(strings.TrimSuffix(out, "\n"), "\n") assert.NilError(c, checkEvents(ID, events)) // filter by ID's - out, _ = dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+ID) + out = cli.DockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+ID).Stdout() events = strings.Split(strings.TrimSuffix(out, "\n"), "\n") assert.NilError(c, checkEvents(ID, events)) } @@ -408,8 +404,7 @@ func (s *DockerCLIEventSuite) TestEventsCommit(c *testing.T) { // Problematic on Windows as cannot commit a running container testRequires(c, DaemonIsLinux) - out := runSleepingContainer(c) - cID := strings.TrimSpace(out) + cID := runSleepingContainer(c) cli.WaitRun(c, cID) cli.DockerCmd(c, "commit", "-m", "test", cID) @@ -417,7 +412,7 @@ func (s *DockerCLIEventSuite) TestEventsCommit(c *testing.T) { cli.WaitExited(c, cID, 5*time.Second) until := daemonUnixTime(c) - out = cli.DockerCmd(c, "events", "-f", "container="+cID, "--until="+until).Combined() + out := cli.DockerCmd(c, "events", "-f", "container="+cID, "--until="+until).Combined() assert.Assert(c, strings.Contains(out, "commit"), "Missing 'commit' log event") } @@ -435,25 +430,24 @@ func (s *DockerCLIEventSuite) TestEventsCopy(c *testing.T) { assert.NilError(c, tempFile.Close()) - dockerCmd(c, "create", "--name=cptest", id) + cli.DockerCmd(c, "create", "--name=cptest", id) - dockerCmd(c, "cp", "cptest:/file", tempFile.Name()) + cli.DockerCmd(c, "cp", "cptest:/file", tempFile.Name()) until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+until) + out := cli.DockerCmd(c, "events", "--since=0", "-f", "container=cptest", "--until="+until).Stdout() assert.Assert(c, strings.Contains(out, "archive-path"), "Missing 'archive-path' log event") - dockerCmd(c, "cp", tempFile.Name(), "cptest:/filecopy") + cli.DockerCmd(c, "cp", tempFile.Name(), "cptest:/filecopy") until = daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "container=cptest", "--until="+until) + out = cli.DockerCmd(c, "events", "-f", "container=cptest", "--until="+until).Stdout() assert.Assert(c, strings.Contains(out, "extract-to-dir"), "Missing 'extract-to-dir' log event") } func (s *DockerCLIEventSuite) TestEventsResize(c *testing.T) { - out := runSleepingContainer(c, "-d", "-t") - cID := strings.TrimSpace(out) - assert.NilError(c, waitRun(cID)) + cID := runSleepingContainer(c, "-d", "-t") + cli.WaitRun(c, cID) apiClient, err := client.NewClientWithOpts(client.FromEnv) assert.NilError(c, err) @@ -466,10 +460,10 @@ func (s *DockerCLIEventSuite) TestEventsResize(c *testing.T) { err = apiClient.ContainerResize(testutil.GetContext(c), cID, options) assert.NilError(c, err) - dockerCmd(c, "stop", cID) + cli.DockerCmd(c, "stop", cID) until := daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until) + out := cli.DockerCmd(c, "events", "-f", "container="+cID, "--until="+until).Combined() assert.Assert(c, strings.Contains(out, "resize"), "Missing 'resize' log event") } @@ -512,13 +506,13 @@ func (s *DockerCLIEventSuite) TestEventsAttach(c *testing.T) { } func (s *DockerCLIEventSuite) TestEventsRename(c *testing.T) { - out, _ := dockerCmd(c, "run", "--name", "oldName", "busybox", "true") + out := cli.DockerCmd(c, "run", "--name", "oldName", "busybox", "true").Stdout() cID := strings.TrimSpace(out) - dockerCmd(c, "rename", "oldName", "newName") + cli.DockerCmd(c, "rename", "oldName", "newName") until := daemonUnixTime(c) // filter by the container id because the name in the event will be the new name. - out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until", until) + out = cli.DockerCmd(c, "events", "-f", "container="+cID, "--until", until).Stdout() assert.Assert(c, strings.Contains(out, "rename"), "Missing 'rename' log event") } @@ -526,15 +520,14 @@ func (s *DockerCLIEventSuite) TestEventsTop(c *testing.T) { // Problematic on Windows as Windows does not support top testRequires(c, DaemonIsLinux) - out := runSleepingContainer(c, "-d") - cID := strings.TrimSpace(out) - assert.NilError(c, waitRun(cID)) + cID := runSleepingContainer(c, "-d") + cli.WaitRun(c, cID) - dockerCmd(c, "top", cID) - dockerCmd(c, "stop", cID) + cli.DockerCmd(c, "top", cID) + cli.DockerCmd(c, "stop", cID) until := daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until) + out := cli.DockerCmd(c, "events", "-f", "container="+cID, "--until="+until).Combined() assert.Assert(c, strings.Contains(out, "top"), "Missing 'top' log event") } @@ -544,19 +537,19 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *testing.T) { // supporting push testRequires(c, DaemonIsLinux) testRequires(c, Network) - repoName := fmt.Sprintf("%v/dockercli/testf", privateRegistryURL) + imgRepoName := fmt.Sprintf("%v/dockercli/testf", privateRegistryURL) - out, _ := dockerCmd(c, "run", "-d", "busybox", "top") + out := cli.DockerCmd(c, "run", "-d", "busybox", "top").Stdout() cID := strings.TrimSpace(out) - assert.NilError(c, waitRun(cID)) + cli.WaitRun(c, cID) - dockerCmd(c, "commit", cID, repoName) - dockerCmd(c, "stop", cID) - dockerCmd(c, "push", repoName) + cli.DockerCmd(c, "commit", cID, imgRepoName) + cli.DockerCmd(c, "stop", cID) + cli.DockerCmd(c, "push", imgRepoName) until := daemonUnixTime(c) - out, _ = dockerCmd(c, "events", "-f", "image="+repoName, "-f", "event=push", "--until", until) - assert.Assert(c, strings.Contains(out, repoName), "Missing 'push' log event for %s", repoName) + out = cli.DockerCmd(c, "events", "-f", "image="+imgRepoName, "-f", "event=push", "--until", until).Stdout() + assert.Assert(c, strings.Contains(out, imgRepoName), "Missing 'push' log event for %s", imgRepoName) } func (s *DockerCLIEventSuite) TestEventsFilterType(c *testing.T) { @@ -570,17 +563,17 @@ func (s *DockerCLIEventSuite) TestEventsFilterType(c *testing.T) { buildImageSuccessfully(c, name, build.WithDockerfile(fmt.Sprintf(` FROM busybox:latest LABEL %s`, label))) - dockerCmd(c, "tag", name, "labelfiltertest:tag1") - dockerCmd(c, "tag", name, "labelfiltertest:tag2") - dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") + cli.DockerCmd(c, "tag", name, "labelfiltertest:tag1") + cli.DockerCmd(c, "tag", name, "labelfiltertest:tag2") + cli.DockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3") - out, _ := dockerCmd( - c, + out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", fmt.Sprintf("label=%s", label), - "--filter", "type=image") + "--filter", "type=image", + ).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") @@ -590,24 +583,24 @@ func (s *DockerCLIEventSuite) TestEventsFilterType(c *testing.T) { assert.Check(c, strings.Contains(e, "labelfiltertest")) } - out, _ = dockerCmd( - c, + out = cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", fmt.Sprintf("label=%s", label), - "--filter", "type=container") + "--filter", "type=container", + ).Stdout() events = strings.Split(strings.TrimSpace(out), "\n") // Events generated by the container that builds the image assert.Equal(c, len(events), 2, "Events == %s", events) - out, _ = dockerCmd( - c, + out = cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), - "--filter", "type=network") + "--filter", "type=network", + ).Stdout() events = strings.Split(strings.TrimSpace(out), "\n") assert.Assert(c, len(events) >= 1, "Events == %s", events) } @@ -616,45 +609,42 @@ func (s *DockerCLIEventSuite) TestEventsFilterType(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsSpecialFiltersWithExecCreate(c *testing.T) { since := daemonUnixTime(c) runSleepingContainer(c, "--name", "test-container", "-d") - waitRun("test-container") + cli.WaitRun(c, "test-container") - dockerCmd(c, "exec", "test-container", "echo", "hello-world") + cli.DockerCmd(c, "exec", "test-container", "echo", "hello-world") - out, _ := dockerCmd( - c, + out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event='exec_create: echo hello-world'", - ) + ).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Equal(c, len(events), 1, out) - out, _ = dockerCmd( - c, + out = cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=exec_create", - ) + ).Stdout() assert.Equal(c, len(events), 1, out) } func (s *DockerCLIEventSuite) TestEventsFilterImageInContainerAction(c *testing.T) { since := daemonUnixTime(c) - dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") - waitRun("test-container") + cli.DockerCmd(c, "run", "-d", "busybox", "true") - out, _ := dockerCmd(c, "events", "--filter", "image=busybox", "--since", since, "--until", daemonUnixTime(c)) + out := cli.DockerCmd(c, "events", "--filter", "image=busybox", "--since", since, "--until", daemonUnixTime(c)).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Assert(c, len(events) > 1, out) } func (s *DockerCLIEventSuite) TestEventsContainerRestart(c *testing.T) { - dockerCmd(c, "run", "-d", "--name=testEvent", "--restart=on-failure:3", "busybox", "false") + cli.DockerCmd(c, "run", "-d", "--name=testEvent", "--restart=on-failure:3", "busybox", "false") // wait until test2 is auto removed. waitTime := 10 * time.Second @@ -671,7 +661,7 @@ func (s *DockerCLIEventSuite) TestEventsContainerRestart(c *testing.T) { startCount int dieCount int ) - out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c), "-f", "container=testEvent") + out := cli.DockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c), "-f", "container=testEvent").Stdout() events := strings.Split(strings.TrimSpace(out), "\n") nEvents := len(events) @@ -694,8 +684,7 @@ func (s *DockerCLIEventSuite) TestEventsContainerRestart(c *testing.T) { } func (s *DockerCLIEventSuite) TestEventsSinceInTheFuture(c *testing.T) { - dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") - waitRun("test-container") + cli.DockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") since := daemonTime(c) until := since.Add(time.Duration(-24) * time.Hour) @@ -708,15 +697,13 @@ func (s *DockerCLIEventSuite) TestEventsSinceInTheFuture(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsUntilInThePast(c *testing.T) { since := daemonUnixTime(c) - dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") - waitRun("test-container") + cli.DockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true") until := daemonUnixTime(c) - dockerCmd(c, "run", "--name", "test-container2", "-d", "busybox", "true") - waitRun("test-container2") + cli.DockerCmd(c, "run", "--name", "test-container2", "-d", "busybox", "true") - out, _ := dockerCmd(c, "events", "--filter", "image=busybox", "--since", since, "--until", until) + out := cli.DockerCmd(c, "events", "--filter", "image=busybox", "--since", since, "--until", until).Stdout() assert.Assert(c, !strings.Contains(out, "test-container2")) assert.Assert(c, strings.Contains(out, "test-container")) @@ -724,9 +711,9 @@ func (s *DockerCLIEventSuite) TestEventsUntilInThePast(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFormat(c *testing.T) { since := daemonUnixTime(c) - dockerCmd(c, "run", "--rm", "busybox", "true") - dockerCmd(c, "run", "--rm", "busybox", "true") - out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--format", "{{json .}}") + cli.DockerCmd(c, "run", "--rm", "busybox", "true") + cli.DockerCmd(c, "run", "--rm", "busybox", "true") + out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--format", "{{json .}}").Stdout() dec := json.NewDecoder(strings.NewReader(out)) // make sure we got 2 start events startCount := 0 @@ -747,7 +734,7 @@ func (s *DockerCLIEventSuite) TestEventsFormat(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFormatBadFunc(c *testing.T) { // make sure it fails immediately, without receiving any event - result := dockerCmdWithResult("events", "--format", "{{badFuncString .}}") + result := cli.Docker(cli.Args("events", "--format", "{{badFuncString .}}")) result.Assert(c, icmd.Expected{ Error: "exit status 64", ExitCode: 64, @@ -757,7 +744,7 @@ func (s *DockerCLIEventSuite) TestEventsFormatBadFunc(c *testing.T) { func (s *DockerCLIEventSuite) TestEventsFormatBadField(c *testing.T) { // make sure it fails immediately, without receiving any event - result := dockerCmdWithResult("events", "--format", "{{.badFieldString}}") + result := cli.Docker(cli.Args("events", "--format", "{{.badFieldString}}")) result.Assert(c, icmd.Expected{ Error: "exit status 64", ExitCode: 64, diff --git a/integration-cli/docker_cli_events_unix_test.go b/integration-cli/docker_cli_events_unix_test.go index a213ff072a..1e22763bc3 100644 --- a/integration-cli/docker_cli_events_unix_test.go +++ b/integration-cli/docker_cli_events_unix_test.go @@ -14,6 +14,7 @@ import ( "unicode" "github.com/creack/pty" + "github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/integration-cli/cli/build" "golang.org/x/sys/unix" "gotest.tools/v3/assert" @@ -24,7 +25,7 @@ import ( // #5979 func (s *DockerCLIEventSuite) TestEventsRedirectStdout(c *testing.T) { since := daemonUnixTime(c) - dockerCmd(c, "run", "busybox", "true") + cli.DockerCmd(c, "run", "busybox", "true") file, err := os.CreateTemp("", "") assert.NilError(c, err, "could not create temp file") @@ -67,7 +68,7 @@ func (s *DockerCLIEventSuite) TestEventsOOMDisableFalse(c *testing.T) { c.Fatal("Timeout waiting for container to die on OOM") } - out, _ := dockerCmd(c, "events", "--since=0", "-f", "container=oomFalse", "--until", daemonUnixTime(c)) + out := cli.DockerCmd(c, "events", "--since=0", "-f", "container=oomFalse", "--until", daemonUnixTime(c)).Stdout() events := strings.Split(strings.TrimSuffix(out, "\n"), "\n") nEvents := len(events) @@ -98,7 +99,7 @@ func (s *DockerCLIEventSuite) TestEventsOOMDisableTrue(c *testing.T) { } }() - assert.NilError(c, waitRun("oomTrue")) + cli.WaitRun(c, "oomTrue") defer dockerCmdWithResult("kill", "oomTrue") containerID := inspectField(c, "oomTrue", "Id") @@ -130,13 +131,13 @@ func (s *DockerCLIEventSuite) TestEventsOOMDisableTrue(c *testing.T) { // #18453 func (s *DockerCLIEventSuite) TestEventsContainerFilterByName(c *testing.T) { testRequires(c, DaemonIsLinux) - cOut, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top") + cOut := cli.DockerCmd(c, "run", "--name=foo", "-d", "busybox", "top").Stdout() c1 := strings.TrimSpace(cOut) - waitRun("foo") - cOut, _ = dockerCmd(c, "run", "--name=bar", "-d", "busybox", "top") + cli.WaitRun(c, "foo") + cOut = cli.DockerCmd(c, "run", "--name=bar", "-d", "busybox", "top").Stdout() c2 := strings.TrimSpace(cOut) - waitRun("bar") - out, _ := dockerCmd(c, "events", "-f", "container=foo", "--since=0", "--until", daemonUnixTime(c)) + cli.WaitRun(c, "bar") + out := cli.DockerCmd(c, "events", "-f", "container=foo", "--since=0", "--until", daemonUnixTime(c)).Stdout() assert.Assert(c, strings.Contains(out, c1), out) assert.Assert(c, !strings.Contains(out, c2), out) } @@ -153,7 +154,7 @@ func (s *DockerCLIEventSuite) TestEventsContainerFilterBeforeCreate(c *testing.T // Sleep for a second to make sure we are testing the case where events are listened before container starts. time.Sleep(time.Second) - id, _ := dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top") + id := cli.DockerCmd(c, "run", "--name=foo", "-d", "busybox", "top").Stdout() cID := strings.TrimSpace(id) for i := 0; ; i++ { out := buf.String() @@ -173,16 +174,15 @@ func (s *DockerCLIEventSuite) TestVolumeEvents(c *testing.T) { since := daemonUnixTime(c) // Observe create/mount volume actions - dockerCmd(c, "volume", "create", "test-event-volume-local") - dockerCmd(c, "run", "--name", "test-volume-container", "--volume", "test-event-volume-local:/foo", "-d", "busybox", "true") - waitRun("test-volume-container") + cli.DockerCmd(c, "volume", "create", "test-event-volume-local") + cli.DockerCmd(c, "run", "--name", "test-volume-container", "--volume", "test-event-volume-local:/foo", "-d", "busybox", "true") // Observe unmount/destroy volume actions - dockerCmd(c, "rm", "-f", "test-volume-container") - dockerCmd(c, "volume", "rm", "test-event-volume-local") + cli.DockerCmd(c, "rm", "-f", "test-volume-container") + cli.DockerCmd(c, "volume", "rm", "test-event-volume-local") until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since", since, "--until", until) + out := cli.DockerCmd(c, "events", "--since", since, "--until", until).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Assert(c, len(events) > 3) @@ -200,16 +200,15 @@ func (s *DockerCLIEventSuite) TestNetworkEvents(c *testing.T) { since := daemonUnixTime(c) // Observe create/connect network actions - dockerCmd(c, "network", "create", "test-event-network-local") - dockerCmd(c, "run", "--name", "test-network-container", "--net", "test-event-network-local", "-d", "busybox", "true") - waitRun("test-network-container") + cli.DockerCmd(c, "network", "create", "test-event-network-local") + cli.DockerCmd(c, "run", "--name", "test-network-container", "--net", "test-event-network-local", "-d", "busybox", "true") // Observe disconnect/destroy network actions - dockerCmd(c, "rm", "-f", "test-network-container") - dockerCmd(c, "network", "rm", "test-event-network-local") + cli.DockerCmd(c, "rm", "-f", "test-network-container") + cli.DockerCmd(c, "network", "rm", "test-event-network-local") until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since", since, "--until", until) + out := cli.DockerCmd(c, "events", "--since", since, "--until", until).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Assert(c, len(events) > 4) @@ -225,18 +224,18 @@ func (s *DockerCLIEventSuite) TestEventsContainerWithMultiNetwork(c *testing.T) testRequires(c, DaemonIsLinux) // Observe create/connect network actions - dockerCmd(c, "network", "create", "test-event-network-local-1") - dockerCmd(c, "network", "create", "test-event-network-local-2") - dockerCmd(c, "run", "--name", "test-network-container", "--net", "test-event-network-local-1", "-td", "busybox", "sh") - waitRun("test-network-container") - dockerCmd(c, "network", "connect", "test-event-network-local-2", "test-network-container") + cli.DockerCmd(c, "network", "create", "test-event-network-local-1") + cli.DockerCmd(c, "network", "create", "test-event-network-local-2") + cli.DockerCmd(c, "run", "--name", "test-network-container", "--net", "test-event-network-local-1", "-td", "busybox", "sh") + cli.WaitRun(c, "test-network-container") + cli.DockerCmd(c, "network", "connect", "test-event-network-local-2", "test-network-container") since := daemonUnixTime(c) - dockerCmd(c, "stop", "-t", "1", "test-network-container") + cli.DockerCmd(c, "stop", "-t", "1", "test-network-container") until := daemonUnixTime(c) - out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "-f", "type=network") + out := cli.DockerCmd(c, "events", "--since", since, "--until", until, "-f", "type=network").Stdout() netEvents := strings.Split(strings.TrimSpace(out), "\n") // received two network disconnect events @@ -258,7 +257,7 @@ func (s *DockerCLIEventSuite) TestEventsStreaming(c *testing.T) { assert.NilError(c, err) defer observer.Stop() - out, _ := dockerCmd(c, "run", "-d", "busybox:latest", "true") + out := cli.DockerCmd(c, "run", "-d", "busybox:latest", "true").Stdout() containerID := strings.TrimSpace(out) testActions := map[string]chan bool{ @@ -293,7 +292,7 @@ func (s *DockerCLIEventSuite) TestEventsStreaming(c *testing.T) { // ignore, done } - dockerCmd(c, "rm", containerID) + cli.DockerCmd(c, "rm", containerID) select { case <-time.After(5 * time.Second): @@ -347,10 +346,10 @@ func (s *DockerCLIEventSuite) TestEventsFilterVolumeAndNetworkType(c *testing.T) since := daemonUnixTime(c) - dockerCmd(c, "network", "create", "test-event-network-type") - dockerCmd(c, "volume", "create", "test-event-volume-type") + cli.DockerCmd(c, "network", "create", "test-event-network-type") + cli.DockerCmd(c, "volume", "create", "test-event-volume-type") - out, _ := dockerCmd(c, "events", "--filter", "type=volume", "--filter", "type=network", "--since", since, "--until", daemonUnixTime(c)) + out := cli.DockerCmd(c, "events", "--filter", "type=volume", "--filter", "type=network", "--since", since, "--until", daemonUnixTime(c)).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Assert(c, len(events) >= 2, out) @@ -366,8 +365,8 @@ func (s *DockerCLIEventSuite) TestEventsFilterVolumeID(c *testing.T) { since := daemonUnixTime(c) - dockerCmd(c, "volume", "create", "test-event-volume-id") - out, _ := dockerCmd(c, "events", "--filter", "volume=test-event-volume-id", "--since", since, "--until", daemonUnixTime(c)) + cli.DockerCmd(c, "volume", "create", "test-event-volume-id") + out := cli.DockerCmd(c, "events", "--filter", "volume=test-event-volume-id", "--since", since, "--until", daemonUnixTime(c)).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Equal(c, len(events), 1) @@ -381,8 +380,8 @@ func (s *DockerCLIEventSuite) TestEventsFilterNetworkID(c *testing.T) { since := daemonUnixTime(c) - dockerCmd(c, "network", "create", "test-event-network-local") - out, _ := dockerCmd(c, "events", "--filter", "network=test-event-network-local", "--since", since, "--until", daemonUnixTime(c)) + cli.DockerCmd(c, "network", "create", "test-event-network-local") + out := cli.DockerCmd(c, "events", "--filter", "network=test-event-network-local", "--since", since, "--until", daemonUnixTime(c)).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") assert.Equal(c, len(events), 1) assert.Assert(c, strings.Contains(events[0], "test-event-network-local"))