cli/compose/loader: TestMarshallConfig: fix duplicate version

The version was originally added in 570ee9cb54,
at the time the `expected` config did not have a `version:` field. A later
refactor in 0cf2e6353a updated the `expected`
config to have a `version:` included. However, the test was not updated,
which now resulted in the test using a compose file with a duplicate version
field:

    version: '3.10'
    version: "3.10"
      services:
        foo:
          build:

This issue was masked by `yaml.Unmarshal()` from `gopkg.in/yaml.v2` which
silently ignores the duplicate, taking the value of the last occurrence. When
upgrading to `gopkg.in/yaml.v3`, the duplicate value resulted in an error:

    yaml: unmarshal errors:
        line 2: mapping key "version" already defined at line 1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-16 19:46:08 +01:00
parent 2b7d10cf93
commit c18dd2719e
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 2 additions and 2 deletions

View File

@ -19,8 +19,8 @@ func TestMarshallConfig(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(expected, string(actual))) assert.Check(t, is.Equal(expected, string(actual)))
// Make sure the expected still // Make sure the expected can be parsed.
dict, err := ParseYAML([]byte("version: '3.10'\n" + expected)) dict, err := ParseYAML([]byte(expected))
assert.NilError(t, err) assert.NilError(t, err)
_, err = Load(buildConfigDetails(dict, map[string]string{})) _, err = Load(buildConfigDetails(dict, map[string]string{}))
assert.NilError(t, err) assert.NilError(t, err)