github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/compose_pause_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/testutil" 24 ) 25 26 func TestComposePauseAndUnpause(t *testing.T) { 27 base := testutil.NewBase(t) 28 switch base.Info().CgroupDriver { 29 case "none", "": 30 t.Skip("requires cgroup (for pausing)") 31 } 32 33 var dockerComposeYAML = fmt.Sprintf(` 34 version: '3.1' 35 36 services: 37 svc0: 38 image: %s 39 command: "sleep infinity" 40 svc1: 41 image: %s 42 command: "sleep infinity" 43 `, testutil.CommonImage, testutil.CommonImage) 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 // pause a service should (only) pause its own container 54 base.ComposeCmd("-f", comp.YAMLFullPath(), "pause", "svc0").AssertOK() 55 base.ComposeCmd("-f", comp.YAMLFullPath(), "ps", "svc0", "-a").AssertOutContainsAny("Paused", "paused") 56 base.ComposeCmd("-f", comp.YAMLFullPath(), "ps", "svc1").AssertOutContainsAny("Up", "running") 57 58 // unpause should be able to recover the paused service container 59 base.ComposeCmd("-f", comp.YAMLFullPath(), "unpause", "svc0").AssertOK() 60 base.ComposeCmd("-f", comp.YAMLFullPath(), "ps", "svc0").AssertOutContainsAny("Up", "running") 61 }