From a7ed600bde2fe77764b58b1ba818779f06504fe7 Mon Sep 17 00:00:00 2001 From: aiordache Date: Mon, 8 Mar 2021 10:27:24 +0100 Subject: [PATCH] Add containers.filter and e2e test Signed-off-by: aiordache --- local/compose/top.go | 13 ++----------- local/e2e/compose/compose_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/local/compose/top.go b/local/compose/top.go index 1a83eeb52..24549e99f 100644 --- a/local/compose/top.go +++ b/local/compose/top.go @@ -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{}) diff --git a/local/e2e/compose/compose_test.go b/local/e2e/compose/compose_test.go index dc8008f2a..967f2b6dd 100644 --- a/local/e2e/compose/compose_test.go +++ b/local/e2e/compose/compose_test.go @@ -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")