fix issue 1093 (#1094)

This commit is contained in:
yxxhero 2023-10-25 10:42:47 +08:00 committed by GitHub
parent 73c3058d31
commit 34ccbf9056
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -37,10 +37,12 @@ func forbidEnvironmentsWithReleases(filePath string, content []byte) (bool, erro
if k == "environments" || k == "releases" || k == "---" { if k == "environments" || k == "releases" || k == "---" {
if _, ok := resultKeys[k]; !ok { if _, ok := resultKeys[k]; !ok {
result = append(result, k) result = append(result, k)
if k != "---" {
resultKeys[k] = nil resultKeys[k] = nil
} }
} }
} }
}
if len(result) < 2 { if len(result) < 2 {
return false, nil return false, nil

View File

@ -41,6 +41,14 @@ func TestForbidEnvironmentsWithReleases(t *testing.T) {
expectedErr: false, expectedErr: false,
isStrict: false, isStrict: false,
}, },
{
name: "no error when has --- between releases and environments, and --- on top of helmfile.yaml.gotmpl",
filePath: "helmfile.yaml.gotmpl",
content: []byte("---\nenvironments:\n---\nreleases:\n"),
v1mode: false,
expectedErr: false,
isStrict: false,
},
{ {
name: "error when both releases and environments", name: "error when both releases and environments",
filePath: "helmfile.yaml.gotmpl", filePath: "helmfile.yaml.gotmpl",
@ -50,8 +58,8 @@ func TestForbidEnvironmentsWithReleases(t *testing.T) {
isStrict: false, isStrict: false,
}, },
{ {
name: "no error when both releases and environments for plain yaml on v1", name: "error when both releases and environments for plain yaml on v1",
filePath: "helmfile.yaml.gotmpl", filePath: "helmfile.yaml",
content: []byte("environments:\nreleases:\n"), content: []byte("environments:\nreleases:\n"),
v1mode: true, v1mode: true,
expectedErr: true, expectedErr: true,