mirror of
https://github.com/docker/compose.git
synced 2025-07-19 19:54:28 +02:00
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) {
|
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{
|
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
||||||
Filters: filters.NewArgs(projectFilter(projectName)),
|
Filters: filters.NewArgs(projectFilter(projectName)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ignore := func(string) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if len(services) > 0 {
|
if len(services) > 0 {
|
||||||
ignore = func(s string) bool {
|
containers = containers.filter(isService(services...))
|
||||||
return !contains(services, s)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
summary := make([]compose.ContainerProcSummary, len(containers))
|
summary := make([]compose.ContainerProcSummary, len(containers))
|
||||||
eg, ctx := errgroup.WithContext(ctx)
|
eg, ctx := errgroup.WithContext(ctx)
|
||||||
for i, c := range containers {
|
for i, c := range containers {
|
||||||
container := c
|
container := c
|
||||||
service := c.Labels[serviceLabel]
|
|
||||||
if ignore(service) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
i := i
|
i := i
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
topContent, err := s.apiClient.ContainerTop(ctx, container.ID, []string{})
|
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"})
|
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) {
|
t.Run("check compose labels", func(t *testing.T) {
|
||||||
wd, _ := os.Getwd()
|
wd, _ := os.Getwd()
|
||||||
res := c.RunDockerCmd("inspect", projectName+"_web_1")
|
res := c.RunDockerCmd("inspect", projectName+"_web_1")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user