mirror of https://github.com/helm/helm
- Stamp chart.Metadata.RepoURL in Install/Upgrade actions instead of
pkg/cmd, so library consumers also get provenance recorded.
- Don't mislabel local installs as path; fill RepoURL only for
resolved repos, OCI refs, and absolute http(s) URLs.
- Unexport ChartDownloader.RepositoryURL; expose via accessor to
preserve ABI for downstream unkeyed-struct users.
- Fix render test template to use .Chart.RepoURL.
Signed-off-by: Aleksei Krugliak <aleksei.krugliak@altenar.com>
pull/31792/head
parent
31132a16fe
commit
97e54c8f11
@ -0,0 +1,62 @@
|
|||||||
|
package action
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"helm.sh/helm/v4/pkg/chart/v2/loader"
|
||||||
|
chartutil "helm.sh/helm/v4/pkg/chart/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRenderRepoURL2_ValidAndInvalid(t *testing.T) {
|
||||||
|
cfg := actionConfigFixture(t)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
chartPath string
|
||||||
|
expectPart string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "valid repoURL",
|
||||||
|
chartPath: "testdata/charts/chart-with-repourl-valid",
|
||||||
|
expectPart: `repoURL: "https://example.com/charts"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid repoURL",
|
||||||
|
chartPath: "testdata/charts/chart-with-repourl-invalid",
|
||||||
|
expectPart: `repoURL: "ht!tp://not-a-valid-url"`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
ch, err := loader.Load(tt.chartPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if ch.Metadata == nil {
|
||||||
|
md, err := chartutil.LoadChartfile(filepath.Join(tt.chartPath, "Chart.yaml"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
ch.Metadata = md
|
||||||
|
}
|
||||||
|
|
||||||
|
_, buf, _, err := cfg.renderResources(
|
||||||
|
ch,
|
||||||
|
map[string]interface{}{},
|
||||||
|
"test-release",
|
||||||
|
"",
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, buf)
|
||||||
|
assert.Contains(t, buf.String(), tt.expectPart)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
apiVersion: v2
|
||||||
|
name: chart-with-repourl-invalid
|
||||||
|
version: 0.1.0
|
||||||
|
description: Test chart containing an invalid repoURL in metadata
|
||||||
|
repoURL: "ht!tp://not-a-valid-url"
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: chart-with-repourl-invalid-cm
|
||||||
|
data:
|
||||||
|
repoURL: {{ .Chart.RepoURL | quote }}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
apiVersion: v2
|
||||||
|
name: chart-with-repourl-valid
|
||||||
|
version: 0.1.0
|
||||||
|
description: Test chart containing a valid repoURL in metadata
|
||||||
|
repoURL: https://example.com/charts
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: chart-with-repourl-valid-cm
|
||||||
|
data:
|
||||||
|
repoURL: {{ .Chart.RepoURL | quote }}
|
||||||
Loading…
Reference in new issue