github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/stack/config_test.go (about) 1 package stack 2 3 import ( 4 "io" 5 "testing" 6 7 "github.com/docker/cli/cli/compose/loader" 8 composetypes "github.com/docker/cli/cli/compose/types" 9 "github.com/docker/cli/internal/test" 10 "gotest.tools/v3/assert" 11 ) 12 13 func TestConfigWithEmptyComposeFile(t *testing.T) { 14 cmd := newConfigCommand(test.NewFakeCli(&fakeClient{})) 15 cmd.SetOut(io.Discard) 16 17 assert.ErrorContains(t, cmd.Execute(), `Please specify a Compose file`) 18 } 19 20 func TestConfigMergeInterpolation(t *testing.T) { 21 tests := []struct { 22 name string 23 skipInterpolation bool 24 fileOne string 25 fileTwo string 26 expected string 27 }{ 28 { 29 name: "With Interpolation", 30 skipInterpolation: false, 31 fileOne: `version: "3.7" 32 services: 33 foo: 34 image: busybox:latest 35 command: cat file1.txt 36 `, 37 fileTwo: `version: "3.7" 38 services: 39 foo: 40 image: busybox:${VERSION} 41 command: cat file2.txt 42 `, 43 expected: `version: "3.7" 44 services: 45 foo: 46 command: 47 - cat 48 - file2.txt 49 image: busybox:1.0 50 `, 51 }, 52 { 53 name: "Without Interpolation", 54 skipInterpolation: true, 55 fileOne: `version: "3.7" 56 services: 57 foo: 58 image: busybox:latest 59 command: cat file1.txt 60 `, 61 fileTwo: `version: "3.7" 62 services: 63 foo: 64 image: busybox:${VERSION} 65 command: cat file2.txt 66 `, 67 expected: `version: "3.7" 68 services: 69 foo: 70 command: 71 - cat 72 - file2.txt 73 image: busybox:${VERSION} 74 `, 75 }, 76 } 77 78 for _, tc := range tests { 79 t.Run(tc.name, func(t *testing.T) { 80 firstConfigData, err := loader.ParseYAML([]byte(tc.fileOne)) 81 assert.Check(t, err) 82 secondConfigData, err := loader.ParseYAML([]byte(tc.fileTwo)) 83 assert.Check(t, err) 84 85 actual, err := outputConfig(composetypes.ConfigDetails{ 86 ConfigFiles: []composetypes.ConfigFile{ 87 {Config: firstConfigData, Filename: "firstConfig"}, 88 {Config: secondConfigData, Filename: "secondConfig"}, 89 }, 90 Environment: map[string]string{ 91 "VERSION": "1.0", 92 }, 93 }, tc.skipInterpolation) 94 assert.Check(t, err) 95 assert.Equal(t, tc.expected, actual) 96 }) 97 } 98 }