Skip to content

Commit

Permalink
Ignore comment nodes not containing '# --'.
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Miguel Custódio <[email protected]>
  • Loading branch information
bmcustodio committed Jun 8, 2021
1 parent 8abd6f4 commit 5ddabba
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/document/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func getDescriptionFromNode(node *yaml.Node) helm.ChartValueDescription {
return helm.ChartValueDescription{}
}

if !strings.Contains(node.HeadComment, "# --") {
return helm.ChartValueDescription{}
}
commentLines := strings.Split(node.HeadComment, "\n")
keyFromComment, c := helm.ParseComment(commentLines)
if keyFromComment != "" {
Expand Down
42 changes: 42 additions & 0 deletions pkg/document/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1373,3 +1373,45 @@ after: 3
assert.Equal(t, "", valuesRows[0].Description)
assert.Equal(t, "after desc", valuesRows[0].AutoDescription)
}

func TestIgnoreCommentedFields(t *testing.T) {
helmValues := parseYamlValues(`
# -- Qux!
qux: 1
# must not appear
# must not appear too
foo:
# -- Bar!
bar: true
# -- Baz!
baz: false
`)

valuesRows, err := getSortedValuesTableRows(helmValues, make(map[string]helm.ChartValueDescription))

assert.Nil(t, err)
assert.Len(t, valuesRows, 3)

assert.Equal(t, "qux", valuesRows[2].Key)
assert.Equal(t, intType, valuesRows[2].Type)
assert.Equal(t, "`1`", valuesRows[2].Default)
assert.Equal(t, "", valuesRows[2].AutoDefault)
assert.Equal(t, "", valuesRows[2].Description)
assert.Equal(t, "Qux!", valuesRows[2].AutoDescription)

assert.Equal(t, "foo.baz", valuesRows[1].Key)
assert.Equal(t, boolType, valuesRows[1].Type)
assert.Equal(t, "`false`", valuesRows[1].Default)
assert.Equal(t, "", valuesRows[1].AutoDefault)
assert.Equal(t, "", valuesRows[1].Description)
assert.Equal(t, "Baz!", valuesRows[1].AutoDescription)

assert.Equal(t, "foo.bar", valuesRows[0].Key)
assert.Equal(t, boolType, valuesRows[0].Type)
assert.Equal(t, "`true`", valuesRows[0].Default)
assert.Equal(t, "", valuesRows[0].AutoDefault)
assert.Equal(t, "", valuesRows[0].Description)
assert.Equal(t, "Bar!", valuesRows[0].AutoDescription)
}

0 comments on commit 5ddabba

Please sign in to comment.