integration-cli: DockerCLIEventSuite: replace dockerCmd and waitRun
Also removing some waitRun call, as they were not actually checked for results, and the tests depended on that behavior (to get events about the container starting etc). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
cf95278122
commit
8c661b5e9a
2 changed files with 149 additions and 163 deletions
|
@ -43,7 +43,7 @@ func (s *DockerCLIEventSuite) TestEventsTimestampFormats(c *testing.T) {
|
||||||
// Start stopwatch, generate an event
|
// Start stopwatch, generate an event
|
||||||
start := daemonTime(c)
|
start := daemonTime(c)
|
||||||
time.Sleep(1100 * time.Millisecond) // so that first event occur in different second from since (just for the case)
|
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
|
time.Sleep(1100 * time.Millisecond) // so that until > since
|
||||||
end := daemonTime(c)
|
end := daemonTime(c)
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ func (s *DockerCLIEventSuite) TestEventsTimestampFormats(c *testing.T) {
|
||||||
// --since=$start must contain only the 'untag' event
|
// --since=$start must contain only the 'untag' event
|
||||||
for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} {
|
for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} {
|
||||||
since, until := f(start), f(end)
|
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 := strings.Split(out, "\n")
|
||||||
events = events[:len(events)-1]
|
events = events[:len(events)-1]
|
||||||
|
|
||||||
|
@ -68,10 +68,10 @@ func (s *DockerCLIEventSuite) TestEventsTimestampFormats(c *testing.T) {
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsUntag(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsUntag(c *testing.T) {
|
||||||
image := "busybox"
|
image := "busybox"
|
||||||
dockerCmd(c, "tag", image, "utest:tag1")
|
cli.DockerCmd(c, "tag", image, "utest:tag1")
|
||||||
dockerCmd(c, "tag", image, "utest:tag2")
|
cli.DockerCmd(c, "tag", image, "utest:tag2")
|
||||||
dockerCmd(c, "rmi", "utest:tag1")
|
cli.DockerCmd(c, "rmi", "utest:tag1")
|
||||||
dockerCmd(c, "rmi", "utest:tag2")
|
cli.DockerCmd(c, "rmi", "utest:tag2")
|
||||||
|
|
||||||
result := icmd.RunCmd(icmd.Cmd{
|
result := icmd.RunCmd(icmd.Cmd{
|
||||||
Command: []string{dockerBinary, "events", "--since=1"},
|
Command: []string{dockerBinary, "events", "--since=1"},
|
||||||
|
@ -90,9 +90,9 @@ func (s *DockerCLIEventSuite) TestEventsUntag(c *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsContainerEvents(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 := strings.Split(out, "\n")
|
||||||
events = events[:len(events)-1]
|
events = events[:len(events)-1]
|
||||||
|
|
||||||
|
@ -105,9 +105,9 @@ func (s *DockerCLIEventSuite) TestEventsContainerEvents(c *testing.T) {
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsContainerEventsAttrSort(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsContainerEventsAttrSort(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
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")
|
events := strings.Split(out, "\n")
|
||||||
|
|
||||||
nEvents := len(events)
|
nEvents := len(events)
|
||||||
|
@ -127,10 +127,10 @@ func (s *DockerCLIEventSuite) TestEventsContainerEventsAttrSort(c *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsContainerEventsSinceUnixEpoch(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 := time.Unix(0, 0).Format(time.RFC3339Nano)
|
||||||
timeBeginning = strings.ReplaceAll(timeBeginning, "Z", ".000000000Z")
|
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 := strings.Split(out, "\n")
|
||||||
events = events[:len(events)-1]
|
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
|
time.Sleep(1 * time.Second) // because API has seconds granularity
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
image := "testimageevents:tag"
|
image := "testimageevents:tag"
|
||||||
dockerCmd(c, "tag", "busybox", image)
|
cli.DockerCmd(c, "tag", "busybox", image)
|
||||||
|
|
||||||
out, _ := dockerCmd(c, "events",
|
out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c)).Stdout()
|
||||||
"--since", since, "--until", daemonUnixTime(c))
|
|
||||||
|
|
||||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Equal(c, len(events), 1, "was expecting 1 event. out=%s", out)
|
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)
|
since := daemonUnixTime(c)
|
||||||
testRequires(c, Network)
|
testRequires(c, Network)
|
||||||
|
|
||||||
dockerCmd(c, "pull", "hello-world")
|
cli.DockerCmd(c, "pull", "hello-world")
|
||||||
|
|
||||||
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")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
event := strings.TrimSpace(events[len(events)-1])
|
event := strings.TrimSpace(events[len(events)-1])
|
||||||
matches := eventstestutils.ScanMap(event)
|
matches := eventstestutils.ScanMap(event)
|
||||||
|
@ -181,7 +178,7 @@ func (s *DockerCLIEventSuite) TestEventsImageImport(c *testing.T) {
|
||||||
// more reliable (@swernli)
|
// more reliable (@swernli)
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
|
|
||||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
|
||||||
cleanedContainerID := strings.TrimSpace(out)
|
cleanedContainerID := strings.TrimSpace(out)
|
||||||
|
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
|
@ -192,7 +189,7 @@ func (s *DockerCLIEventSuite) TestEventsImageImport(c *testing.T) {
|
||||||
assert.NilError(c, err, "import failed with output: %q", out)
|
assert.NilError(c, err, "import failed with output: %q", out)
|
||||||
imageRef := strings.TrimSpace(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")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Equal(c, len(events), 1)
|
assert.Equal(c, len(events), 1)
|
||||||
matches := eventstestutils.ScanMap(events[0])
|
matches := eventstestutils.ScanMap(events[0])
|
||||||
|
@ -203,35 +200,35 @@ func (s *DockerCLIEventSuite) TestEventsImageImport(c *testing.T) {
|
||||||
func (s *DockerCLIEventSuite) TestEventsImageLoad(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsImageLoad(c *testing.T) {
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
myImageName := "footest:v1"
|
myImageName := "footest:v1"
|
||||||
dockerCmd(c, "tag", "busybox", myImageName)
|
cli.DockerCmd(c, "tag", "busybox", myImageName)
|
||||||
since := daemonUnixTime(c)
|
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)
|
longImageID := strings.TrimSpace(out)
|
||||||
assert.Assert(c, longImageID != "", "Id should not be empty")
|
assert.Assert(c, longImageID != "", "Id should not be empty")
|
||||||
|
|
||||||
dockerCmd(c, "save", "-o", "saveimg.tar", myImageName)
|
cli.DockerCmd(c, "save", "-o", "saveimg.tar", myImageName)
|
||||||
dockerCmd(c, "rmi", myImageName)
|
cli.DockerCmd(c, "rmi", myImageName)
|
||||||
out, _ = dockerCmd(c, "images", "-q", myImageName)
|
out = cli.DockerCmd(c, "images", "-q", myImageName).Stdout()
|
||||||
noImageID := strings.TrimSpace(out)
|
noImageID := strings.TrimSpace(out)
|
||||||
assert.Equal(c, noImageID, "", "Should not have any image")
|
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 := icmd.RunCommand("rm", "-rf", "saveimg.tar")
|
||||||
result.Assert(c, icmd.Success)
|
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)
|
imageID := strings.TrimSpace(out)
|
||||||
assert.Equal(c, imageID, longImageID, "Should have same image id as before")
|
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")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Equal(c, len(events), 1)
|
assert.Equal(c, len(events), 1)
|
||||||
matches := eventstestutils.ScanMap(events[0])
|
matches := eventstestutils.ScanMap(events[0])
|
||||||
assert.Equal(c, matches["id"], imageID, "matches: %v\nout:\n%s\n", matches, out)
|
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)
|
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")
|
events = strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Equal(c, len(events), 1)
|
assert.Equal(c, len(events), 1)
|
||||||
matches = eventstestutils.ScanMap(events[0])
|
matches = eventstestutils.ScanMap(events[0])
|
||||||
|
@ -244,11 +241,11 @@ func (s *DockerCLIEventSuite) TestEventsPluginOps(c *testing.T) {
|
||||||
|
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
|
|
||||||
dockerCmd(c, "plugin", "install", pNameWithTag, "--grant-all-permissions")
|
cli.DockerCmd(c, "plugin", "install", pNameWithTag, "--grant-all-permissions")
|
||||||
dockerCmd(c, "plugin", "disable", pNameWithTag)
|
cli.DockerCmd(c, "plugin", "disable", pNameWithTag)
|
||||||
dockerCmd(c, "plugin", "remove", 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 := strings.Split(out, "\n")
|
||||||
events = events[:len(events)-1]
|
events = events[:len(events)-1]
|
||||||
|
|
||||||
|
@ -260,12 +257,12 @@ func (s *DockerCLIEventSuite) TestEventsPluginOps(c *testing.T) {
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsFilters(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsFilters(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
dockerCmd(c, "run", "--rm", "busybox", "true")
|
cli.DockerCmd(c, "run", "--rm", "busybox", "true")
|
||||||
dockerCmd(c, "run", "--rm", "busybox", "true")
|
cli.DockerCmd(c, "run", "--rm", "busybox", "true")
|
||||||
out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=die")
|
out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=die").Stdout()
|
||||||
parseEvents(c, out, "die")
|
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")
|
parseEvents(c, out, "die|start")
|
||||||
|
|
||||||
// make sure we at least got 2 start events
|
// 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) {
|
func (s *DockerCLIEventSuite) TestEventsFilterImageName(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
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)
|
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)
|
container2 := strings.TrimSpace(out)
|
||||||
|
|
||||||
name := "busybox"
|
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 := strings.Split(out, "\n")
|
||||||
events = events[:len(events)-1]
|
events = events[:len(events)-1]
|
||||||
assert.Assert(c, len(events) != 0, "Expected events but found none for the image busybox:latest")
|
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)
|
since := strconv.FormatUint(uint64(daemonTime(c).Unix()), 10)
|
||||||
label := "io.docker.testing=foo"
|
label := "io.docker.testing=foo"
|
||||||
|
|
||||||
out, exit := dockerCmd(c, "create", "-l", label, "busybox")
|
result := cli.DockerCmd(c, "create", "-l", label, "busybox")
|
||||||
assert.Equal(c, exit, 0)
|
assert.Equal(c, result.ExitCode, 0)
|
||||||
container1 := strings.TrimSpace(out)
|
container1 := strings.TrimSpace(result.Stdout())
|
||||||
|
|
||||||
out, exit = dockerCmd(c, "create", "busybox")
|
result = cli.DockerCmd(c, "create", "busybox")
|
||||||
assert.Equal(c, exit, 0)
|
assert.Equal(c, result.ExitCode, 0)
|
||||||
container2 := strings.TrimSpace(out)
|
container2 := strings.TrimSpace(result.Stdout())
|
||||||
|
|
||||||
// fetch events with `--until`, so that the client detaches after a second
|
// fetch events with `--until`, so that the client detaches after a second
|
||||||
// instead of staying attached, waiting for more events to arrive.
|
// instead of staying attached, waiting for more events to arrive.
|
||||||
out, _ = dockerCmd(
|
out := cli.DockerCmd(c,
|
||||||
c,
|
|
||||||
"events",
|
"events",
|
||||||
"--since", since,
|
"--since", since,
|
||||||
"--until", strconv.FormatUint(uint64(daemonTime(c).Add(time.Second).Unix()), 10),
|
"--until", strconv.FormatUint(uint64(daemonTime(c).Add(time.Second).Unix()), 10),
|
||||||
"--filter", "label="+label,
|
"--filter", "label="+label,
|
||||||
)
|
).Stdout()
|
||||||
|
|
||||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Assert(c, len(events) > 0)
|
assert.Assert(c, len(events) > 0)
|
||||||
|
@ -345,17 +341,17 @@ func (s *DockerCLIEventSuite) TestEventsFilterImageLabels(c *testing.T) {
|
||||||
buildImageSuccessfully(c, name, build.WithDockerfile(fmt.Sprintf(`
|
buildImageSuccessfully(c, name, build.WithDockerfile(fmt.Sprintf(`
|
||||||
FROM busybox:latest
|
FROM busybox:latest
|
||||||
LABEL %s`, label)))
|
LABEL %s`, label)))
|
||||||
dockerCmd(c, "tag", name, "labelfiltertest:tag1")
|
cli.DockerCmd(c, "tag", name, "labelfiltertest:tag1")
|
||||||
dockerCmd(c, "tag", name, "labelfiltertest:tag2")
|
cli.DockerCmd(c, "tag", name, "labelfiltertest:tag2")
|
||||||
dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3")
|
cli.DockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3")
|
||||||
|
|
||||||
out, _ := dockerCmd(
|
out := cli.DockerCmd(c,
|
||||||
c,
|
|
||||||
"events",
|
"events",
|
||||||
"--since", since,
|
"--since", since,
|
||||||
"--until", daemonUnixTime(c),
|
"--until", daemonUnixTime(c),
|
||||||
"--filter", fmt.Sprintf("label=%s", label),
|
"--filter", fmt.Sprintf("label=%s", label),
|
||||||
"--filter", "type=image")
|
"--filter", "type=image",
|
||||||
|
).Stdout()
|
||||||
|
|
||||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
|
|
||||||
|
@ -371,7 +367,7 @@ func (s *DockerCLIEventSuite) TestEventsFilterContainer(c *testing.T) {
|
||||||
nameID := make(map[string]string)
|
nameID := make(map[string]string)
|
||||||
|
|
||||||
for _, name := range []string{"container_1", "container_2"} {
|
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")
|
id := inspectField(c, name, "Id")
|
||||||
nameID[name] = id
|
nameID[name] = id
|
||||||
}
|
}
|
||||||
|
@ -393,12 +389,12 @@ func (s *DockerCLIEventSuite) TestEventsFilterContainer(c *testing.T) {
|
||||||
|
|
||||||
for name, ID := range nameID {
|
for name, ID := range nameID {
|
||||||
// filter by names
|
// 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")
|
events := strings.Split(strings.TrimSuffix(out, "\n"), "\n")
|
||||||
assert.NilError(c, checkEvents(ID, events))
|
assert.NilError(c, checkEvents(ID, events))
|
||||||
|
|
||||||
// filter by ID's
|
// 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")
|
events = strings.Split(strings.TrimSuffix(out, "\n"), "\n")
|
||||||
assert.NilError(c, checkEvents(ID, events))
|
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
|
// Problematic on Windows as cannot commit a running container
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
|
|
||||||
out := runSleepingContainer(c)
|
cID := runSleepingContainer(c)
|
||||||
cID := strings.TrimSpace(out)
|
|
||||||
cli.WaitRun(c, cID)
|
cli.WaitRun(c, cID)
|
||||||
|
|
||||||
cli.DockerCmd(c, "commit", "-m", "test", 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)
|
cli.WaitExited(c, cID, 5*time.Second)
|
||||||
|
|
||||||
until := daemonUnixTime(c)
|
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")
|
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())
|
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)
|
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")
|
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)
|
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")
|
assert.Assert(c, strings.Contains(out, "extract-to-dir"), "Missing 'extract-to-dir' log event")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsResize(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsResize(c *testing.T) {
|
||||||
out := runSleepingContainer(c, "-d", "-t")
|
cID := runSleepingContainer(c, "-d", "-t")
|
||||||
cID := strings.TrimSpace(out)
|
cli.WaitRun(c, cID)
|
||||||
assert.NilError(c, waitRun(cID))
|
|
||||||
|
|
||||||
apiClient, err := client.NewClientWithOpts(client.FromEnv)
|
apiClient, err := client.NewClientWithOpts(client.FromEnv)
|
||||||
assert.NilError(c, err)
|
assert.NilError(c, err)
|
||||||
|
@ -466,10 +460,10 @@ func (s *DockerCLIEventSuite) TestEventsResize(c *testing.T) {
|
||||||
err = apiClient.ContainerResize(testutil.GetContext(c), cID, options)
|
err = apiClient.ContainerResize(testutil.GetContext(c), cID, options)
|
||||||
assert.NilError(c, err)
|
assert.NilError(c, err)
|
||||||
|
|
||||||
dockerCmd(c, "stop", cID)
|
cli.DockerCmd(c, "stop", cID)
|
||||||
|
|
||||||
until := daemonUnixTime(c)
|
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")
|
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) {
|
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)
|
cID := strings.TrimSpace(out)
|
||||||
dockerCmd(c, "rename", "oldName", "newName")
|
cli.DockerCmd(c, "rename", "oldName", "newName")
|
||||||
|
|
||||||
until := daemonUnixTime(c)
|
until := daemonUnixTime(c)
|
||||||
// filter by the container id because the name in the event will be the new name.
|
// 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")
|
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
|
// Problematic on Windows as Windows does not support top
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
|
|
||||||
out := runSleepingContainer(c, "-d")
|
cID := runSleepingContainer(c, "-d")
|
||||||
cID := strings.TrimSpace(out)
|
cli.WaitRun(c, cID)
|
||||||
assert.NilError(c, waitRun(cID))
|
|
||||||
|
|
||||||
dockerCmd(c, "top", cID)
|
cli.DockerCmd(c, "top", cID)
|
||||||
dockerCmd(c, "stop", cID)
|
cli.DockerCmd(c, "stop", cID)
|
||||||
|
|
||||||
until := daemonUnixTime(c)
|
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")
|
assert.Assert(c, strings.Contains(out, "top"), "Missing 'top' log event")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,19 +537,19 @@ func (s *DockerRegistrySuite) TestEventsImageFilterPush(c *testing.T) {
|
||||||
// supporting push
|
// supporting push
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
testRequires(c, Network)
|
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)
|
cID := strings.TrimSpace(out)
|
||||||
assert.NilError(c, waitRun(cID))
|
cli.WaitRun(c, cID)
|
||||||
|
|
||||||
dockerCmd(c, "commit", cID, repoName)
|
cli.DockerCmd(c, "commit", cID, imgRepoName)
|
||||||
dockerCmd(c, "stop", cID)
|
cli.DockerCmd(c, "stop", cID)
|
||||||
dockerCmd(c, "push", repoName)
|
cli.DockerCmd(c, "push", imgRepoName)
|
||||||
|
|
||||||
until := daemonUnixTime(c)
|
until := daemonUnixTime(c)
|
||||||
out, _ = dockerCmd(c, "events", "-f", "image="+repoName, "-f", "event=push", "--until", until)
|
out = cli.DockerCmd(c, "events", "-f", "image="+imgRepoName, "-f", "event=push", "--until", until).Stdout()
|
||||||
assert.Assert(c, strings.Contains(out, repoName), "Missing 'push' log event for %s", repoName)
|
assert.Assert(c, strings.Contains(out, imgRepoName), "Missing 'push' log event for %s", imgRepoName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsFilterType(c *testing.T) {
|
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(`
|
buildImageSuccessfully(c, name, build.WithDockerfile(fmt.Sprintf(`
|
||||||
FROM busybox:latest
|
FROM busybox:latest
|
||||||
LABEL %s`, label)))
|
LABEL %s`, label)))
|
||||||
dockerCmd(c, "tag", name, "labelfiltertest:tag1")
|
cli.DockerCmd(c, "tag", name, "labelfiltertest:tag1")
|
||||||
dockerCmd(c, "tag", name, "labelfiltertest:tag2")
|
cli.DockerCmd(c, "tag", name, "labelfiltertest:tag2")
|
||||||
dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3")
|
cli.DockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3")
|
||||||
|
|
||||||
out, _ := dockerCmd(
|
out := cli.DockerCmd(c,
|
||||||
c,
|
|
||||||
"events",
|
"events",
|
||||||
"--since", since,
|
"--since", since,
|
||||||
"--until", daemonUnixTime(c),
|
"--until", daemonUnixTime(c),
|
||||||
"--filter", fmt.Sprintf("label=%s", label),
|
"--filter", fmt.Sprintf("label=%s", label),
|
||||||
"--filter", "type=image")
|
"--filter", "type=image",
|
||||||
|
).Stdout()
|
||||||
|
|
||||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
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"))
|
assert.Check(c, strings.Contains(e, "labelfiltertest"))
|
||||||
}
|
}
|
||||||
|
|
||||||
out, _ = dockerCmd(
|
out = cli.DockerCmd(c,
|
||||||
c,
|
|
||||||
"events",
|
"events",
|
||||||
"--since", since,
|
"--since", since,
|
||||||
"--until", daemonUnixTime(c),
|
"--until", daemonUnixTime(c),
|
||||||
"--filter", fmt.Sprintf("label=%s", label),
|
"--filter", fmt.Sprintf("label=%s", label),
|
||||||
"--filter", "type=container")
|
"--filter", "type=container",
|
||||||
|
).Stdout()
|
||||||
events = strings.Split(strings.TrimSpace(out), "\n")
|
events = strings.Split(strings.TrimSpace(out), "\n")
|
||||||
|
|
||||||
// Events generated by the container that builds the image
|
// Events generated by the container that builds the image
|
||||||
assert.Equal(c, len(events), 2, "Events == %s", events)
|
assert.Equal(c, len(events), 2, "Events == %s", events)
|
||||||
|
|
||||||
out, _ = dockerCmd(
|
out = cli.DockerCmd(c,
|
||||||
c,
|
|
||||||
"events",
|
"events",
|
||||||
"--since", since,
|
"--since", since,
|
||||||
"--until", daemonUnixTime(c),
|
"--until", daemonUnixTime(c),
|
||||||
"--filter", "type=network")
|
"--filter", "type=network",
|
||||||
|
).Stdout()
|
||||||
events = strings.Split(strings.TrimSpace(out), "\n")
|
events = strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Assert(c, len(events) >= 1, "Events == %s", events)
|
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) {
|
func (s *DockerCLIEventSuite) TestEventsSpecialFiltersWithExecCreate(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
runSleepingContainer(c, "--name", "test-container", "-d")
|
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(
|
out := cli.DockerCmd(c,
|
||||||
c,
|
|
||||||
"events",
|
"events",
|
||||||
"--since", since,
|
"--since", since,
|
||||||
"--until", daemonUnixTime(c),
|
"--until", daemonUnixTime(c),
|
||||||
"--filter",
|
"--filter",
|
||||||
"event='exec_create: echo hello-world'",
|
"event='exec_create: echo hello-world'",
|
||||||
)
|
).Stdout()
|
||||||
|
|
||||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Equal(c, len(events), 1, out)
|
assert.Equal(c, len(events), 1, out)
|
||||||
|
|
||||||
out, _ = dockerCmd(
|
out = cli.DockerCmd(c,
|
||||||
c,
|
|
||||||
"events",
|
"events",
|
||||||
"--since", since,
|
"--since", since,
|
||||||
"--until", daemonUnixTime(c),
|
"--until", daemonUnixTime(c),
|
||||||
"--filter",
|
"--filter",
|
||||||
"event=exec_create",
|
"event=exec_create",
|
||||||
)
|
).Stdout()
|
||||||
assert.Equal(c, len(events), 1, out)
|
assert.Equal(c, len(events), 1, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsFilterImageInContainerAction(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsFilterImageInContainerAction(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
|
cli.DockerCmd(c, "run", "-d", "busybox", "true")
|
||||||
waitRun("test-container")
|
|
||||||
|
|
||||||
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")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Assert(c, len(events) > 1, out)
|
assert.Assert(c, len(events) > 1, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsContainerRestart(c *testing.T) {
|
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.
|
// wait until test2 is auto removed.
|
||||||
waitTime := 10 * time.Second
|
waitTime := 10 * time.Second
|
||||||
|
@ -671,7 +661,7 @@ func (s *DockerCLIEventSuite) TestEventsContainerRestart(c *testing.T) {
|
||||||
startCount int
|
startCount int
|
||||||
dieCount 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")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
|
|
||||||
nEvents := len(events)
|
nEvents := len(events)
|
||||||
|
@ -694,8 +684,7 @@ func (s *DockerCLIEventSuite) TestEventsContainerRestart(c *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsSinceInTheFuture(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsSinceInTheFuture(c *testing.T) {
|
||||||
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
|
cli.DockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
|
||||||
waitRun("test-container")
|
|
||||||
|
|
||||||
since := daemonTime(c)
|
since := daemonTime(c)
|
||||||
until := since.Add(time.Duration(-24) * time.Hour)
|
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) {
|
func (s *DockerCLIEventSuite) TestEventsUntilInThePast(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
|
|
||||||
dockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
|
cli.DockerCmd(c, "run", "--name", "test-container", "-d", "busybox", "true")
|
||||||
waitRun("test-container")
|
|
||||||
|
|
||||||
until := daemonUnixTime(c)
|
until := daemonUnixTime(c)
|
||||||
|
|
||||||
dockerCmd(c, "run", "--name", "test-container2", "-d", "busybox", "true")
|
cli.DockerCmd(c, "run", "--name", "test-container2", "-d", "busybox", "true")
|
||||||
waitRun("test-container2")
|
|
||||||
|
|
||||||
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-container2"))
|
||||||
assert.Assert(c, strings.Contains(out, "test-container"))
|
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) {
|
func (s *DockerCLIEventSuite) TestEventsFormat(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
dockerCmd(c, "run", "--rm", "busybox", "true")
|
cli.DockerCmd(c, "run", "--rm", "busybox", "true")
|
||||||
dockerCmd(c, "run", "--rm", "busybox", "true")
|
cli.DockerCmd(c, "run", "--rm", "busybox", "true")
|
||||||
out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--format", "{{json .}}")
|
out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--format", "{{json .}}").Stdout()
|
||||||
dec := json.NewDecoder(strings.NewReader(out))
|
dec := json.NewDecoder(strings.NewReader(out))
|
||||||
// make sure we got 2 start events
|
// make sure we got 2 start events
|
||||||
startCount := 0
|
startCount := 0
|
||||||
|
@ -747,7 +734,7 @@ func (s *DockerCLIEventSuite) TestEventsFormat(c *testing.T) {
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsFormatBadFunc(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsFormatBadFunc(c *testing.T) {
|
||||||
// make sure it fails immediately, without receiving any event
|
// 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{
|
result.Assert(c, icmd.Expected{
|
||||||
Error: "exit status 64",
|
Error: "exit status 64",
|
||||||
ExitCode: 64,
|
ExitCode: 64,
|
||||||
|
@ -757,7 +744,7 @@ func (s *DockerCLIEventSuite) TestEventsFormatBadFunc(c *testing.T) {
|
||||||
|
|
||||||
func (s *DockerCLIEventSuite) TestEventsFormatBadField(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsFormatBadField(c *testing.T) {
|
||||||
// make sure it fails immediately, without receiving any event
|
// 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{
|
result.Assert(c, icmd.Expected{
|
||||||
Error: "exit status 64",
|
Error: "exit status 64",
|
||||||
ExitCode: 64,
|
ExitCode: 64,
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/creack/pty"
|
"github.com/creack/pty"
|
||||||
|
"github.com/docker/docker/integration-cli/cli"
|
||||||
"github.com/docker/docker/integration-cli/cli/build"
|
"github.com/docker/docker/integration-cli/cli/build"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
|
@ -24,7 +25,7 @@ import (
|
||||||
// #5979
|
// #5979
|
||||||
func (s *DockerCLIEventSuite) TestEventsRedirectStdout(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsRedirectStdout(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
dockerCmd(c, "run", "busybox", "true")
|
cli.DockerCmd(c, "run", "busybox", "true")
|
||||||
|
|
||||||
file, err := os.CreateTemp("", "")
|
file, err := os.CreateTemp("", "")
|
||||||
assert.NilError(c, err, "could not create temp file")
|
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")
|
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")
|
events := strings.Split(strings.TrimSuffix(out, "\n"), "\n")
|
||||||
nEvents := len(events)
|
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")
|
defer dockerCmdWithResult("kill", "oomTrue")
|
||||||
containerID := inspectField(c, "oomTrue", "Id")
|
containerID := inspectField(c, "oomTrue", "Id")
|
||||||
|
|
||||||
|
@ -130,13 +131,13 @@ func (s *DockerCLIEventSuite) TestEventsOOMDisableTrue(c *testing.T) {
|
||||||
// #18453
|
// #18453
|
||||||
func (s *DockerCLIEventSuite) TestEventsContainerFilterByName(c *testing.T) {
|
func (s *DockerCLIEventSuite) TestEventsContainerFilterByName(c *testing.T) {
|
||||||
testRequires(c, DaemonIsLinux)
|
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)
|
c1 := strings.TrimSpace(cOut)
|
||||||
waitRun("foo")
|
cli.WaitRun(c, "foo")
|
||||||
cOut, _ = dockerCmd(c, "run", "--name=bar", "-d", "busybox", "top")
|
cOut = cli.DockerCmd(c, "run", "--name=bar", "-d", "busybox", "top").Stdout()
|
||||||
c2 := strings.TrimSpace(cOut)
|
c2 := strings.TrimSpace(cOut)
|
||||||
waitRun("bar")
|
cli.WaitRun(c, "bar")
|
||||||
out, _ := dockerCmd(c, "events", "-f", "container=foo", "--since=0", "--until", daemonUnixTime(c))
|
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, c1), out)
|
||||||
assert.Assert(c, !strings.Contains(out, c2), 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.
|
// Sleep for a second to make sure we are testing the case where events are listened before container starts.
|
||||||
time.Sleep(time.Second)
|
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)
|
cID := strings.TrimSpace(id)
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
out := buf.String()
|
out := buf.String()
|
||||||
|
@ -173,16 +174,15 @@ func (s *DockerCLIEventSuite) TestVolumeEvents(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
|
|
||||||
// Observe create/mount volume actions
|
// Observe create/mount volume actions
|
||||||
dockerCmd(c, "volume", "create", "test-event-volume-local")
|
cli.DockerCmd(c, "volume", "create", "test-event-volume-local")
|
||||||
dockerCmd(c, "run", "--name", "test-volume-container", "--volume", "test-event-volume-local:/foo", "-d", "busybox", "true")
|
cli.DockerCmd(c, "run", "--name", "test-volume-container", "--volume", "test-event-volume-local:/foo", "-d", "busybox", "true")
|
||||||
waitRun("test-volume-container")
|
|
||||||
|
|
||||||
// Observe unmount/destroy volume actions
|
// Observe unmount/destroy volume actions
|
||||||
dockerCmd(c, "rm", "-f", "test-volume-container")
|
cli.DockerCmd(c, "rm", "-f", "test-volume-container")
|
||||||
dockerCmd(c, "volume", "rm", "test-event-volume-local")
|
cli.DockerCmd(c, "volume", "rm", "test-event-volume-local")
|
||||||
|
|
||||||
until := daemonUnixTime(c)
|
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")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Assert(c, len(events) > 3)
|
assert.Assert(c, len(events) > 3)
|
||||||
|
|
||||||
|
@ -200,16 +200,15 @@ func (s *DockerCLIEventSuite) TestNetworkEvents(c *testing.T) {
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
|
|
||||||
// Observe create/connect network actions
|
// Observe create/connect network actions
|
||||||
dockerCmd(c, "network", "create", "test-event-network-local")
|
cli.DockerCmd(c, "network", "create", "test-event-network-local")
|
||||||
dockerCmd(c, "run", "--name", "test-network-container", "--net", "test-event-network-local", "-d", "busybox", "true")
|
cli.DockerCmd(c, "run", "--name", "test-network-container", "--net", "test-event-network-local", "-d", "busybox", "true")
|
||||||
waitRun("test-network-container")
|
|
||||||
|
|
||||||
// Observe disconnect/destroy network actions
|
// Observe disconnect/destroy network actions
|
||||||
dockerCmd(c, "rm", "-f", "test-network-container")
|
cli.DockerCmd(c, "rm", "-f", "test-network-container")
|
||||||
dockerCmd(c, "network", "rm", "test-event-network-local")
|
cli.DockerCmd(c, "network", "rm", "test-event-network-local")
|
||||||
|
|
||||||
until := daemonUnixTime(c)
|
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")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Assert(c, len(events) > 4)
|
assert.Assert(c, len(events) > 4)
|
||||||
|
|
||||||
|
@ -225,18 +224,18 @@ func (s *DockerCLIEventSuite) TestEventsContainerWithMultiNetwork(c *testing.T)
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
|
|
||||||
// Observe create/connect network actions
|
// Observe create/connect network actions
|
||||||
dockerCmd(c, "network", "create", "test-event-network-local-1")
|
cli.DockerCmd(c, "network", "create", "test-event-network-local-1")
|
||||||
dockerCmd(c, "network", "create", "test-event-network-local-2")
|
cli.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")
|
cli.DockerCmd(c, "run", "--name", "test-network-container", "--net", "test-event-network-local-1", "-td", "busybox", "sh")
|
||||||
waitRun("test-network-container")
|
cli.WaitRun(c, "test-network-container")
|
||||||
dockerCmd(c, "network", "connect", "test-event-network-local-2", "test-network-container")
|
cli.DockerCmd(c, "network", "connect", "test-event-network-local-2", "test-network-container")
|
||||||
|
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
|
|
||||||
dockerCmd(c, "stop", "-t", "1", "test-network-container")
|
cli.DockerCmd(c, "stop", "-t", "1", "test-network-container")
|
||||||
|
|
||||||
until := daemonUnixTime(c)
|
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")
|
netEvents := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
|
|
||||||
// received two network disconnect events
|
// received two network disconnect events
|
||||||
|
@ -258,7 +257,7 @@ func (s *DockerCLIEventSuite) TestEventsStreaming(c *testing.T) {
|
||||||
assert.NilError(c, err)
|
assert.NilError(c, err)
|
||||||
defer observer.Stop()
|
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)
|
containerID := strings.TrimSpace(out)
|
||||||
|
|
||||||
testActions := map[string]chan bool{
|
testActions := map[string]chan bool{
|
||||||
|
@ -293,7 +292,7 @@ func (s *DockerCLIEventSuite) TestEventsStreaming(c *testing.T) {
|
||||||
// ignore, done
|
// ignore, done
|
||||||
}
|
}
|
||||||
|
|
||||||
dockerCmd(c, "rm", containerID)
|
cli.DockerCmd(c, "rm", containerID)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
|
@ -347,10 +346,10 @@ func (s *DockerCLIEventSuite) TestEventsFilterVolumeAndNetworkType(c *testing.T)
|
||||||
|
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
|
|
||||||
dockerCmd(c, "network", "create", "test-event-network-type")
|
cli.DockerCmd(c, "network", "create", "test-event-network-type")
|
||||||
dockerCmd(c, "volume", "create", "test-event-volume-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")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Assert(c, len(events) >= 2, out)
|
assert.Assert(c, len(events) >= 2, out)
|
||||||
|
|
||||||
|
@ -366,8 +365,8 @@ func (s *DockerCLIEventSuite) TestEventsFilterVolumeID(c *testing.T) {
|
||||||
|
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
|
|
||||||
dockerCmd(c, "volume", "create", "test-event-volume-id")
|
cli.DockerCmd(c, "volume", "create", "test-event-volume-id")
|
||||||
out, _ := dockerCmd(c, "events", "--filter", "volume=test-event-volume-id", "--since", since, "--until", daemonUnixTime(c))
|
out := cli.DockerCmd(c, "events", "--filter", "volume=test-event-volume-id", "--since", since, "--until", daemonUnixTime(c)).Stdout()
|
||||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Equal(c, len(events), 1)
|
assert.Equal(c, len(events), 1)
|
||||||
|
|
||||||
|
@ -381,8 +380,8 @@ func (s *DockerCLIEventSuite) TestEventsFilterNetworkID(c *testing.T) {
|
||||||
|
|
||||||
since := daemonUnixTime(c)
|
since := daemonUnixTime(c)
|
||||||
|
|
||||||
dockerCmd(c, "network", "create", "test-event-network-local")
|
cli.DockerCmd(c, "network", "create", "test-event-network-local")
|
||||||
out, _ := dockerCmd(c, "events", "--filter", "network=test-event-network-local", "--since", since, "--until", daemonUnixTime(c))
|
out := cli.DockerCmd(c, "events", "--filter", "network=test-event-network-local", "--since", since, "--until", daemonUnixTime(c)).Stdout()
|
||||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
assert.Equal(c, len(events), 1)
|
assert.Equal(c, len(events), 1)
|
||||||
assert.Assert(c, strings.Contains(events[0], "test-event-network-local"))
|
assert.Assert(c, strings.Contains(events[0], "test-event-network-local"))
|
||||||
|
|
Loading…
Reference in a new issue