Skip to content

Commit

Permalink
fix type definition when description is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kd7lxl committed Jul 30, 2021
1 parent aaec4ec commit 6f70de8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pkg/document/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ func parseNilValueType(key string, description helm.ChartValueDescription, autoD

if len(t) > 0 {
t = t[1 : len(t)-1]
description.Description = description.Description[len(t)+3:]
if len(description.Description) > len(t)+3 {
description.Description = description.Description[len(t)+3:]
} else {
description.Description = ""
}
} else {
t = stringType
}
Expand Down
17 changes: 13 additions & 4 deletions pkg/document/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,18 +931,20 @@ animals:
birds:
birdCount:
nonWeirdCats:
undescribedCount:
`)

descriptions := map[string]helm.ChartValueDescription{
"animals.birdCount": {Description: "(int) the number of birds we have"},
"animals.birds": {Description: "(list) the list of birds we have"},
"animals.nonWeirdCats": {Description: "the cats that we have that are not weird"},
"animals.birdCount": {Description: "(int) the number of birds we have"},
"animals.birds": {Description: "(list) the list of birds we have"},
"animals.nonWeirdCats": {Description: "the cats that we have that are not weird"},
"animals.undescribedCount": {Description: "(int)"},
}

valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

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

assert.Equal(t, "animals.birdCount", valuesRows[0].Key)
assert.Equal(t, intType, valuesRows[0].Type)
Expand All @@ -964,6 +966,13 @@ animals:
assert.Equal(t, "", valuesRows[2].AutoDefault)
assert.Equal(t, "the cats that we have that are not weird", valuesRows[2].Description)
assert.Equal(t, "", valuesRows[2].AutoDescription)

assert.Equal(t, "animals.undescribedCount", valuesRows[3].Key)
assert.Equal(t, intType, valuesRows[3].Type)
assert.Equal(t, "`nil`", valuesRows[3].Default)
assert.Equal(t, "", valuesRows[3].AutoDefault)
assert.Equal(t, "", valuesRows[3].Description)
assert.Equal(t, "", valuesRows[3].AutoDescription)
}

func TestNilValuesWithDefaults(t *testing.T) {
Expand Down

0 comments on commit 6f70de8

Please sign in to comment.