test: add env var tests for HELM_MAX_CHART_SIZE and HELM_MAX_FILE_SIZE

Signed-off-by: Benoit Tigeot <benoit.tigeot@lifen.fr>
pull/30743/head
Benoit Tigeot 2 months ago
parent e7e92cbeb5
commit d3cd80d00c
No known key found for this signature in database
GPG Key ID: 8E6D4FC8AEBDA62C

@ -373,6 +373,8 @@ func TestUserAgentHeaderInK8sRESTClientConfig(t *testing.T) {
}
func TestQuantityBytesValue(t *testing.T) {
// This test only verifies that the pflag.Value wrapper correctly propagates
// values and errors. Comprehensive parsing logic is tested in TestEnvInt64OrQuantityBytes.
tests := []struct {
name string
input string
@ -380,35 +382,15 @@ func TestQuantityBytesValue(t *testing.T) {
expectError bool
}{
{
name: "plain int64",
input: "12345",
expected: 12345,
},
{
name: "quantity Mi",
name: "valid quantity sets value",
input: "256Mi",
expected: 256 * 1024 * 1024,
},
{
name: "quantity Gi",
input: "1Gi",
expected: 1 * 1024 * 1024 * 1024,
},
{
name: "quantity with whitespace",
input: " 512Mi ",
expected: 512 * 1024 * 1024,
},
{
name: "invalid value",
name: "invalid value propagates error",
input: "not-a-number",
expectError: true,
},
{
name: "lowercase suffix rejected",
input: "1gi",
expectError: true,
},
}
for _, tt := range tests {

@ -23,6 +23,7 @@ import (
"path/filepath"
"testing"
"helm.sh/helm/v4/pkg/cli"
"helm.sh/helm/v4/pkg/repo/v1/repotest"
)
@ -285,6 +286,56 @@ func TestInstall(t *testing.T) {
runTestCmd(t, tests)
}
func TestInstallWithEnvVars(t *testing.T) {
tests := []struct {
name string
cmd string
envVars map[string]string
wantError bool
golden string
}{
{
name: "install with HELM_MAX_CHART_SIZE env var with bytes",
cmd: "install too-big testdata/testcharts/compressedchart-0.1.0.tgz",
envVars: map[string]string{
"HELM_MAX_CHART_SIZE": "42",
},
wantError: true,
golden: "output/install-with-restricted-chart-size.txt",
},
{
name: "install with HELM_MAX_FILE_SIZE env var with Quantity suffix",
cmd: "install test-max-file testdata/testcharts/bigchart-0.1.0.tgz",
envVars: map[string]string{
"HELM_MAX_FILE_SIZE": "1Ki",
},
wantError: true,
golden: "output/install-with-restricted-file-size.txt",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer resetEnv()()
for k, v := range tt.envVars {
t.Setenv(k, v)
}
// Reset settings to pick up env vars
settings = cli.New()
test := cmdTestCase{
name: tt.name,
cmd: tt.cmd,
golden: tt.golden,
wantError: tt.wantError,
}
runTestCmd(t, []cmdTestCase{test})
})
}
}
func TestInstallOutputCompletion(t *testing.T) {
outputFlagCompletionTest(t, "install")
}

@ -0,0 +1 @@
Error: INSTALLATION FAILED: unable to load chart archive: decompressed chart file "bigchart/Chart.yaml" is larger than the maximum file size 1Ki

@ -0,0 +1 @@
Error: unable to load chart archive: decompressed chart is larger than the maximum size 10

@ -0,0 +1 @@
Error: unable to load chart archive: decompressed chart file "bigchart/values.yaml" is larger than the maximum file size 2Ki

@ -29,6 +29,7 @@ import (
chart "helm.sh/helm/v4/pkg/chart/v2"
"helm.sh/helm/v4/pkg/chart/v2/loader"
chartutil "helm.sh/helm/v4/pkg/chart/v2/util"
"helm.sh/helm/v4/pkg/cli"
rcommon "helm.sh/helm/v4/pkg/release/common"
release "helm.sh/helm/v4/pkg/release/v1"
)
@ -201,6 +202,56 @@ func TestUpgradeCmd(t *testing.T) {
runTestCmd(t, tests)
}
func TestUpgradeWithEnvVars(t *testing.T) {
tests := []struct {
name string
cmd string
envVars map[string]string
wantError bool
golden string
}{
{
name: "upgrade with HELM_MAX_CHART_SIZE env var with bytes",
cmd: "upgrade too-big testdata/testcharts/compressedchart-0.1.0.tgz",
envVars: map[string]string{
"HELM_MAX_CHART_SIZE": "10",
},
wantError: true,
golden: "output/upgrade-with-restricted-chart-size-env.txt",
},
{
name: "upgrade with HELM_MAX_FILE_SIZE env var with Quantity suffix",
cmd: "upgrade test-max-file testdata/testcharts/bigchart-0.1.0.tgz",
envVars: map[string]string{
"HELM_MAX_FILE_SIZE": "2Ki",
},
wantError: true,
golden: "output/upgrade-with-restricted-file-size-env.txt",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer resetEnv()()
for k, v := range tt.envVars {
t.Setenv(k, v)
}
// Reset settings to pick up env vars
settings = cli.New()
test := cmdTestCase{
name: tt.name,
cmd: tt.cmd,
golden: tt.golden,
wantError: tt.wantError,
}
runTestCmd(t, []cmdTestCase{test})
})
}
}
func TestUpgradeWithValue(t *testing.T) {
releaseName := "funny-bunny-v2"
relMock, ch, chartPath := prepareMockRelease(t, releaseName)

Loading…
Cancel
Save