github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/compose_restart_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 TestComposeRestart(t *testing.T) { 27 base := testutil.NewBase(t) 28 var dockerComposeYAML = fmt.Sprintf(` 29 version: '3.1' 30 31 services: 32 wordpress: 33 image: %s 34 ports: 35 - 8080:80 36 environment: 37 WORDPRESS_DB_HOST: db 38 WORDPRESS_DB_USER: exampleuser 39 WORDPRESS_DB_PASSWORD: examplepass 40 WORDPRESS_DB_NAME: exampledb 41 volumes: 42 - wordpress:/var/www/html 43 db: 44 image: %s 45 environment: 46 MYSQL_DATABASE: exampledb 47 MYSQL_USER: exampleuser 48 MYSQL_PASSWORD: examplepass 49 MYSQL_RANDOM_ROOT_PASSWORD: '1' 50 volumes: 51 - db:/var/lib/mysql 52 53 volumes: 54 wordpress: 55 db: 56 `, testutil.WordpressImage, testutil.MariaDBImage) 57 58 comp := testutil.NewComposeDir(t, dockerComposeYAML) 59 defer comp.CleanUp() 60 projectName := comp.ProjectName() 61 t.Logf("projectName=%q", projectName) 62 63 base.ComposeCmd("-f", comp.YAMLFullPath(), "up", "-d").AssertOK() 64 defer base.ComposeCmd("-f", comp.YAMLFullPath(), "down", "-v").Run() 65 66 // stop and restart a single service. 67 base.ComposeCmd("-f", comp.YAMLFullPath(), "stop", "db").AssertOK() 68 base.ComposeCmd("-f", comp.YAMLFullPath(), "ps", "db", "-a").AssertOutContainsAny("Exit", "exited") 69 base.ComposeCmd("-f", comp.YAMLFullPath(), "restart", "db").AssertOK() 70 base.ComposeCmd("-f", comp.YAMLFullPath(), "ps", "db").AssertOutContainsAny("Up", "running") 71 72 // stop one service and restart all (also check `--timeout` arg). 73 base.ComposeCmd("-f", comp.YAMLFullPath(), "stop", "db").AssertOK() 74 base.ComposeCmd("-f", comp.YAMLFullPath(), "ps", "db", "-a").AssertOutContainsAny("Exit", "exited") 75 base.ComposeCmd("-f", comp.YAMLFullPath(), "restart", "--timeout", "5").AssertOK() 76 base.ComposeCmd("-f", comp.YAMLFullPath(), "ps", "db").AssertOutContainsAny("Up", "running") 77 base.ComposeCmd("-f", comp.YAMLFullPath(), "ps", "wordpress").AssertOutContainsAny("Up", "running") 78 }