Skip to content

Commit

Permalink
fix: fixes tests by calling correct method
Browse files Browse the repository at this point in the history
  • Loading branch information
norwoodj committed Oct 6, 2020
1 parent 3dd414c commit 445a511
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 55 deletions.
49 changes: 30 additions & 19 deletions pkg/document/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,19 @@ type chartTemplateData struct {
Values []valueRow
}

func getChartTemplateData(chartDocumentationInfo helm.ChartDocumentationInfo, helmDocsVersion string) (chartTemplateData, error) {
// handle empty values file case
if chartDocumentationInfo.ChartValues.Kind == 0 {
return chartTemplateData{
ChartDocumentationInfo: chartDocumentationInfo,
HelmDocsVersion: helmDocsVersion,
Values: make([]valueRow, 0),
}, nil
}

if chartDocumentationInfo.ChartValues.Kind != yaml.DocumentNode {
return chartTemplateData{}, fmt.Errorf("invalid node kind supplied: %d", chartDocumentationInfo.ChartValues.Kind)
}
if chartDocumentationInfo.ChartValues.Content[0].Kind != yaml.MappingNode {
return chartTemplateData{}, fmt.Errorf("values file must resolve to a map, not %s", strconv.Itoa(int(chartDocumentationInfo.ChartValues.Kind)))
}

func getSortedValuesTableRows(documentRoot *yaml.Node, chartValuesDescriptions map[string]helm.ChartValueDescription) ([]valueRow, error) {
valuesTableRows, err := createValueRowsFromField(
"",
nil,
chartDocumentationInfo.ChartValues.Content[0],
chartDocumentationInfo.ChartValuesDescriptions,
documentRoot,
chartValuesDescriptions,
true,
)

if err != nil {
return nil, err
}

sortOrder := viper.GetString("sort-values-order")
if sortOrder == FileSortOrder {
sort.Slice(valuesTableRows, func(i, j int) bool {
Expand All @@ -73,6 +61,29 @@ func getChartTemplateData(chartDocumentationInfo helm.ChartDocumentationInfo, he
})
}

return valuesTableRows, nil
}


func getChartTemplateData(chartDocumentationInfo helm.ChartDocumentationInfo, helmDocsVersion string) (chartTemplateData, error) {
// handle empty values file case
if chartDocumentationInfo.ChartValues.Kind == 0 {
return chartTemplateData{
ChartDocumentationInfo: chartDocumentationInfo,
HelmDocsVersion: helmDocsVersion,
Values: make([]valueRow, 0),
}, nil
}

if chartDocumentationInfo.ChartValues.Kind != yaml.DocumentNode {
return chartTemplateData{}, fmt.Errorf("invalid node kind supplied: %d", chartDocumentationInfo.ChartValues.Kind)
}
if chartDocumentationInfo.ChartValues.Content[0].Kind != yaml.MappingNode {
return chartTemplateData{}, fmt.Errorf("values file must resolve to a map, not %s", strconv.Itoa(int(chartDocumentationInfo.ChartValues.Kind)))
}

valuesTableRows, err := getSortedValuesTableRows(chartDocumentationInfo.ChartValues.Content[0], chartDocumentationInfo.ChartValuesDescriptions)

if err != nil {
return chartTemplateData{}, err
}
Expand Down
72 changes: 36 additions & 36 deletions pkg/document/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func parseYamlValues(yamlValues string) *yaml.Node {

func TestEmptyValues(t *testing.T) {
helmValues := parseYamlValues(`{}`)
valuesRows, err := createValueRowsFromObject("", nil, helmValues, make(map[string]helm.ChartValueDescription), true)
valuesRows, err := getSortedValuesTableRows(helmValues, make(map[string]helm.ChartValueDescription))
assert.Nil(t, err)
assert.Len(t, valuesRows, 0)
}
Expand All @@ -35,7 +35,7 @@ hello: "world"
oscar: 3.14159
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 4)
Expand Down Expand Up @@ -84,7 +84,7 @@ oscar: 3.14159
"oscar": {Description: "oscar"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 4)
Expand Down Expand Up @@ -133,7 +133,7 @@ oscar: 3.14159
"oscar": {Description: "oscar", Default: "values"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 4)
Expand Down Expand Up @@ -174,7 +174,7 @@ recursive:
oscar: dog
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -206,7 +206,7 @@ oscar: dog
"oscar": {Description: "oscar"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -238,7 +238,7 @@ oscar: dog
"oscar": {Description: "oscar", Default: "default"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand All @@ -264,7 +264,7 @@ recursive: {}
oscar: dog
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -294,7 +294,7 @@ oscar: dog
"recursive": {Description: "an empty object"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -324,7 +324,7 @@ oscar: dog
"recursive": {Description: "an empty object", Default: "default"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand All @@ -349,7 +349,7 @@ birds: []
echo: cat
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -380,7 +380,7 @@ echo: cat
"echo": {Description: "echo"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -411,7 +411,7 @@ echo: cat
"echo": {Description: "echo", Default: "default value"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand All @@ -436,7 +436,7 @@ func TestListOfStrings(t *testing.T) {
cats: [echo, foxtrot]
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -467,7 +467,7 @@ cats: [echo, foxtrot]
"cats[1]": {Description: "the friendly one"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -498,7 +498,7 @@ cats: [echo, foxtrot]
"cats[1]": {Description: "the friendly one", Default: "default value"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -528,7 +528,7 @@ animals:
type: dog
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 5)
Expand Down Expand Up @@ -584,7 +584,7 @@ animals:
"animals[1].elements[0]": {Description: "the sleepy one"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 5)
Expand Down Expand Up @@ -640,7 +640,7 @@ animals:
"animals[1].elements[0]": {Description: "the sleepy one", Default: "value"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 5)
Expand Down Expand Up @@ -694,7 +694,7 @@ animals:
"animals": {Description: "all the animals of the house"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 1)
Expand All @@ -720,7 +720,7 @@ animals:
"animals": {Description: "all the animals of the house", Default: "cat and dog"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 1)
Expand All @@ -746,7 +746,7 @@ animals:
"animals[0]": {Description: "all the cats of the house", Default: "only cats here"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 3)
Expand Down Expand Up @@ -786,7 +786,7 @@ animals:
"animals.byTrait": {Description: "animals listed by their various characteristics"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 1)
Expand All @@ -812,7 +812,7 @@ animals:
"animals.byTrait": {Description: "animals listed by their various characteristics", Default: "animals, you know"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 1)
Expand Down Expand Up @@ -841,7 +841,7 @@ animals:
"animals.byTrait.friendly[0]": {Description: "best cat ever"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 4)
Expand Down Expand Up @@ -891,7 +891,7 @@ animals:
"animals.byTrait.friendly[0]": {Description: "best cat ever", Default: "value"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 4)
Expand Down Expand Up @@ -939,7 +939,7 @@ animals:
"animals.nonWeirdCats": {Description: "the cats that we have that are not weird"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 3)
Expand Down Expand Up @@ -980,7 +980,7 @@ animals:
"animals.nonWeirdCats": {Description: "the cats that we have that are not weird", Default: "default"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 3)
Expand Down Expand Up @@ -1015,7 +1015,7 @@ fullNames:
John Norwood: me
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -1048,7 +1048,7 @@ fullNames:
`websites."stupidchess.jmn23.com"`: {Description: "status of the stupidchess website"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -1081,7 +1081,7 @@ fullNames:
`websites."stupidchess.jmn23.com"`: {Description: "status of the stupidchess website", Default: "value"},
}

valuesRows, err := createValueRowsFromObject("", nil, helmValues, descriptions, true)
valuesRows, err := getSortedValuesTableRows(helmValues, descriptions)

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -1116,7 +1116,7 @@ hello: "world"
oscar: 3.14159
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 4)
Expand Down Expand Up @@ -1165,7 +1165,7 @@ animals:
oscar: 3.14159
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 3)
Expand Down Expand Up @@ -1202,7 +1202,7 @@ animals:
- foxtrot
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -1236,7 +1236,7 @@ animalLocations:
cats: []
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 2)
Expand Down Expand Up @@ -1267,7 +1267,7 @@ animals:
- foxtrot
`)

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

assert.Nil(t, err)
assert.Len(t, valuesRows, 1)
Expand Down

0 comments on commit 445a511

Please sign in to comment.