mirror of https://github.com/docker/compose.git
Add containers.filter and e2e test
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
79af862613
commit
a7ed600bde
|
@ -26,29 +26,20 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Top(ctx context.Context, projectName string, services []string) ([]compose.ContainerProcSummary, error) {
|
||||
var containers Containers
|
||||
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
||||
Filters: filters.NewArgs(projectFilter(projectName)),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ignore := func(string) bool {
|
||||
return false
|
||||
}
|
||||
if len(services) > 0 {
|
||||
ignore = func(s string) bool {
|
||||
return !contains(services, s)
|
||||
}
|
||||
containers = containers.filter(isService(services...))
|
||||
}
|
||||
summary := make([]compose.ContainerProcSummary, len(containers))
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
for i, c := range containers {
|
||||
container := c
|
||||
service := c.Labels[serviceLabel]
|
||||
if ignore(service) {
|
||||
continue
|
||||
}
|
||||
i := i
|
||||
eg.Go(func() error {
|
||||
topContent, err := s.apiClient.ContainerTop(ctx, container.ID, []string{})
|
||||
|
|
|
@ -65,6 +65,14 @@ func TestLocalComposeUp(t *testing.T) {
|
|||
res.Assert(t, icmd.Expected{Out: projectName + "_default"})
|
||||
})
|
||||
|
||||
t.Run("top", func(t *testing.T) {
|
||||
res := c.RunDockerCmd("compose", "-p", projectName, "top")
|
||||
output := res.Stdout()
|
||||
assert.Assert(t, strings.Contains(output, `UID PID PPID C STIME TTY TIME CMD`))
|
||||
assert.Assert(t, strings.Contains(output, `java -Xmx8m -Xms8m -jar /app/words.jar`))
|
||||
assert.Assert(t, strings.Contains(output, `/dispatcher`))
|
||||
})
|
||||
|
||||
t.Run("check compose labels", func(t *testing.T) {
|
||||
wd, _ := os.Getwd()
|
||||
res := c.RunDockerCmd("inspect", projectName+"_web_1")
|
||||
|
|
Loading…
Reference in New Issue