cli/command/stack: TestConfigMergeInterpolation: various fixes
- Make the package-level configMergeTests local to the test itself. - Rename fields to better describe intent - Remove some redundant variables - Reverse "expected" and "actual" fields for consistency - Use assert.Check() to not fail early Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Родитель
4d2fb68b93
Коммит
bf3f419b6e
|
@ -17,29 +17,30 @@ func TestConfigWithEmptyComposeFile(t *testing.T) {
|
|||
assert.ErrorContains(t, cmd.Execute(), `Please specify a Compose file`)
|
||||
}
|
||||
|
||||
var configMergeTests = []struct {
|
||||
name string
|
||||
skipInterpolation bool
|
||||
first string
|
||||
second string
|
||||
merged string
|
||||
}{
|
||||
{
|
||||
name: "With Interpolation",
|
||||
skipInterpolation: false,
|
||||
first: `version: "3.7"
|
||||
func TestConfigMergeInterpolation(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
skipInterpolation bool
|
||||
fileOne string
|
||||
fileTwo string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "With Interpolation",
|
||||
skipInterpolation: false,
|
||||
fileOne: `version: "3.7"
|
||||
services:
|
||||
foo:
|
||||
image: busybox:latest
|
||||
command: cat file1.txt
|
||||
`,
|
||||
second: `version: "3.7"
|
||||
fileTwo: `version: "3.7"
|
||||
services:
|
||||
foo:
|
||||
image: busybox:${VERSION}
|
||||
command: cat file2.txt
|
||||
`,
|
||||
merged: `version: "3.7"
|
||||
expected: `version: "3.7"
|
||||
services:
|
||||
foo:
|
||||
command:
|
||||
|
@ -47,23 +48,23 @@ services:
|
|||
- file2.txt
|
||||
image: busybox:1.0
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "Without Interpolation",
|
||||
skipInterpolation: true,
|
||||
first: `version: "3.7"
|
||||
},
|
||||
{
|
||||
name: "Without Interpolation",
|
||||
skipInterpolation: true,
|
||||
fileOne: `version: "3.7"
|
||||
services:
|
||||
foo:
|
||||
image: busybox:latest
|
||||
command: cat file1.txt
|
||||
`,
|
||||
second: `version: "3.7"
|
||||
fileTwo: `version: "3.7"
|
||||
services:
|
||||
foo:
|
||||
image: busybox:${VERSION}
|
||||
command: cat file2.txt
|
||||
`,
|
||||
merged: `version: "3.7"
|
||||
expected: `version: "3.7"
|
||||
services:
|
||||
foo:
|
||||
command:
|
||||
|
@ -71,34 +72,27 @@ services:
|
|||
- file2.txt
|
||||
image: busybox:${VERSION}
|
||||
`,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func TestConfigMergeInterpolation(t *testing.T) {
|
||||
for _, tt := range configMergeTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
firstConfig := []byte(tt.first)
|
||||
secondConfig := []byte(tt.second)
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
firstConfigData, err := loader.ParseYAML([]byte(tc.fileOne))
|
||||
assert.Check(t, err)
|
||||
secondConfigData, err := loader.ParseYAML([]byte(tc.fileTwo))
|
||||
assert.Check(t, err)
|
||||
|
||||
firstConfigData, err := loader.ParseYAML(firstConfig)
|
||||
assert.NilError(t, err)
|
||||
secondConfigData, err := loader.ParseYAML(secondConfig)
|
||||
assert.NilError(t, err)
|
||||
|
||||
env := map[string]string{
|
||||
"VERSION": "1.0",
|
||||
}
|
||||
|
||||
cfg, err := outputConfig(composetypes.ConfigDetails{
|
||||
actual, err := outputConfig(composetypes.ConfigDetails{
|
||||
ConfigFiles: []composetypes.ConfigFile{
|
||||
{Config: firstConfigData, Filename: "firstConfig"},
|
||||
{Config: secondConfigData, Filename: "secondConfig"},
|
||||
},
|
||||
Environment: env,
|
||||
}, tt.skipInterpolation)
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Equal(t, cfg, tt.merged)
|
||||
Environment: map[string]string{
|
||||
"VERSION": "1.0",
|
||||
},
|
||||
}, tc.skipInterpolation)
|
||||
assert.Check(t, err)
|
||||
assert.Equal(t, tc.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче