github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/compose_top_linux_test.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "fmt" 21 "testing" 22 23 "github.com/containerd/nerdctl/pkg/infoutil" 24 "github.com/containerd/nerdctl/pkg/rootlessutil" 25 "github.com/containerd/nerdctl/pkg/testutil" 26 ) 27 28 func TestComposeTop(t *testing.T) { 29 if rootlessutil.IsRootless() && infoutil.CgroupsVersion() == "1" { 30 t.Skip("test skipped for rootless containers on cgroup v1") 31 } 32 33 base := testutil.NewBase(t) 34 var dockerComposeYAML = fmt.Sprintf(` 35 version: '3.1' 36 37 services: 38 svc0: 39 image: %s 40 command: "sleep infinity" 41 svc1: 42 image: %s 43 `, testutil.CommonImage, testutil.NginxAlpineImage) 44 45 comp := testutil.NewComposeDir(t, dockerComposeYAML) 46 defer comp.CleanUp() 47 projectName := comp.ProjectName() 48 t.Logf("projectName=%q", projectName) 49 50 base.ComposeCmd("-f", comp.YAMLFullPath(), "up", "-d").AssertOK() 51 defer base.ComposeCmd("-f", comp.YAMLFullPath(), "down", "-v").AssertOK() 52 53 // a running container should have the process command in output 54 base.ComposeCmd("-f", comp.YAMLFullPath(), "top", "svc0").AssertOutContains("sleep infinity") 55 base.ComposeCmd("-f", comp.YAMLFullPath(), "top", "svc1").AssertOutContains("nginx") 56 }