fix: update ociDigestRegex to match empty digest in Helm 4.2.1 OCI pull output

Helm 4.2.1 outputs "Digest: sha256:" (empty hash) when pulling OCI charts.
The regex required at least one hex char ([0-9a-f]+), so it did not match
and the digest was not normalized to $DIGEST in snapshot tests.

Also fix the replacement string: Go regex ReplaceAllString interprets $DIGEST
as a capture group reference (resolving to empty). Use $$DIGEST to produce
a literal $DIGEST in the output.

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2026-06-13 09:33:55 +08:00
parent b055cde21f
commit 8eec42f899
1 changed files with 2 additions and 2 deletions

View File

@ -31,7 +31,7 @@ var (
helmShortVersionRegex = regexp.MustCompile(`v\d+\.\d+\.\d+\+[a-z0-9]+`)
// OCI digest regex. e.g. Digest: sha256:abc123...
// The digest is non-deterministic because helm packages include build timestamps.
ociDigestRegex = regexp.MustCompile(`Digest: sha256:[0-9a-f]+`)
ociDigestRegex = regexp.MustCompile(`Digest: sha256:[0-9a-f]*`)
)
type Config struct {
@ -405,7 +405,7 @@ func testHelmfileTemplateWithBuildCommand(t *testing.T, GoYamlV3 bool) {
// Normalize OCI digest values that change between test runs because
// helm packages include build timestamps making each digest unique.
gotStr = ociDigestRegex.ReplaceAllString(gotStr, "Digest: sha256:$DIGEST")
gotStr = ociDigestRegex.ReplaceAllString(gotStr, "Digest: sha256:$$DIGEST")
sc := bufio.NewScanner(strings.NewReader(gotStr))
for sc.Scan() {