github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/compose_up_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 "os" 22 "path/filepath" 23 "runtime" 24 "testing" 25 26 "github.com/containerd/nerdctl/pkg/testutil" 27 "gotest.tools/v3/assert" 28 "gotest.tools/v3/icmd" 29 ) 30 31 // https://github.com/containerd/nerdctl/issues/1942 32 func TestComposeUpDetailedError(t *testing.T) { 33 if runtime.GOOS != "linux" { 34 t.Skip("FIXME: test does not work on Windows yet (runtime \"io.containerd.runc.v2\" binary not installed \"containerd-shim-runc-v2.exe\": file does not exist)") 35 } 36 base := testutil.NewBase(t) 37 dockerComposeYAML := fmt.Sprintf(` 38 services: 39 foo: 40 image: %s 41 runtime: invalid 42 `, testutil.CommonImage) 43 comp := testutil.NewComposeDir(t, dockerComposeYAML) 44 defer comp.CleanUp() 45 46 c := base.ComposeCmd("-f", comp.YAMLFullPath(), "up", "-d") 47 expected := icmd.Expected{ 48 ExitCode: 1, 49 Err: `exec: \"invalid\": executable file not found in $PATH`, 50 } 51 if base.Target == testutil.Docker { 52 expected.Err = `unknown or invalid runtime name: invalid` 53 } 54 c.Assert(expected) 55 } 56 57 // https://github.com/containerd/nerdctl/issues/1652 58 func TestComposeUpBindCreateHostPath(t *testing.T) { 59 if runtime.GOOS == "windows" { 60 t.Skip(`FIXME: no support for Windows path: (error: "volume target must be an absolute path, got \"/mnt\")`) 61 } 62 63 base := testutil.NewBase(t) 64 65 var dockerComposeYAML = fmt.Sprintf(` 66 services: 67 test: 68 image: %s 69 command: sh -euxc "echo hi >/mnt/test" 70 volumes: 71 # ./foo should be automatically created 72 - ./foo:/mnt 73 `, testutil.CommonImage) 74 75 comp := testutil.NewComposeDir(t, dockerComposeYAML) 76 defer comp.CleanUp() 77 78 base.ComposeCmd("-f", comp.YAMLFullPath(), "up").AssertOK() 79 defer base.ComposeCmd("-f", comp.YAMLFullPath(), "down").AssertOK() 80 testFile := filepath.Join(comp.Dir(), "foo", "test") 81 testB, err := os.ReadFile(testFile) 82 assert.NilError(t, err) 83 assert.Equal(t, "hi\n", string(testB)) 84 }