Skip to content

Commit

Permalink
fix: Better method to detect helm chart version in
Browse files Browse the repository at this point in the history
template tests
  • Loading branch information
harshshahsumo committed Jun 25, 2024
1 parent 84f1817 commit f23743e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/helm/goldenfile_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helm

import (
"fmt"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -132,10 +133,19 @@ func runGoldenFileTest(t *testing.T, valuesFileName string, outputFileName strin
// expected templates
func fixupRenderedYaml(yaml string, chartVersion string) string {
checksumRegex := regexp.MustCompile("checksum/config: [a-z0-9]{64}")
patternString := fmt.Sprintf(`(?m)^(\s*app\.kubernetes\.io\/version:\s*"%s"\s*)$|^(\s*chart:\s*"sumologic-%s"\s*)$|^(\s*chart:\s*sumologic-%s\s*)$|^(\s*client:\s*k8s_%s\s*)$|^(\s*value:\s*"%s"\s*)$`,
chartVersion, chartVersion, chartVersion, chartVersion, chartVersion)
pattern := regexp.MustCompile(patternString)
replacement := `%CURRENT_CHART_VERSION%`

output := yaml
output = strings.ReplaceAll(output, releaseName, "RELEASE-NAME")
output = strings.ReplaceAll(output, chartVersion, "%CURRENT_CHART_VERSION%")
output = pattern.ReplaceAllStringFunc(output, func(match string) string {
versionRegex := regexp.MustCompile(chartVersion)
version := versionRegex.FindString(match)

return strings.Replace(match, version, replacement, 1)
})
output = checksumRegex.ReplaceAllLiteralString(output, "checksum/config: '%CONFIG_CHECKSUM%'")
output = strings.TrimSuffix(output, "\n")
return output
Expand Down

0 comments on commit f23743e

Please sign in to comment.