pull/32558/merge
Angel Montero 2 days ago committed by GitHub
commit 7969e31a5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -81,27 +81,25 @@ func executeActionCommandC(store *storage.Storage, cmd string) (*cobra.Command,
return executeActionCommandStdinC(store, nil, cmd) return executeActionCommandStdinC(store, nil, cmd)
} }
func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string) (*cobra.Command, string, error) { func executeActionCommandWithWriters(store *storage.Storage, in *os.File, outWriter, errWriter io.Writer, cmd string) (*cobra.Command, error) {
args, err := shellwords.Parse(cmd) args, err := shellwords.Parse(cmd)
if err != nil { if err != nil {
return nil, "", err return nil, err
} }
buf := new(bytes.Buffer)
actionConfig := &action.Configuration{ actionConfig := &action.Configuration{
Releases: store, Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard}, KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: common.DefaultCapabilities, Capabilities: common.DefaultCapabilities,
} }
root, err := newRootCmdWithConfig(actionConfig, buf, args, SetupLogging) root, err := newRootCmdWithConfig(actionConfig, outWriter, args, SetupLogging)
if err != nil { if err != nil {
return nil, "", err return nil, err
} }
root.SetOut(buf) root.SetOut(outWriter)
root.SetErr(buf) root.SetErr(errWriter)
root.SetArgs(args) root.SetArgs(args)
oldStdin := os.Stdin oldStdin := os.Stdin
@ -118,10 +116,13 @@ func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string)
mem.SetNamespace(settings.Namespace()) mem.SetNamespace(settings.Namespace())
} }
c, err := root.ExecuteC() c, err := root.ExecuteC()
return c, err
}
result := buf.String() func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string) (*cobra.Command, string, error) {
buf := new(bytes.Buffer)
return c, result, err c, err := executeActionCommandWithWriters(store, in, buf, buf, cmd)
return c, buf.String(), err
} }
// cmdTestCase describes a test case that works with releases. // cmdTestCase describes a test case that works with releases.
@ -301,3 +302,10 @@ func TestCmdGetDryRunFlagStrategy(t *testing.T) {
}) })
} }
} }
func executeActionCommandErr(store *storage.Storage, in *os.File, cmd string) (*cobra.Command, string, string, error) {
bufOut := new(bytes.Buffer)
bufErr := new(bytes.Buffer)
c, err := executeActionCommandWithWriters(store, in, bufOut, bufErr, cmd)
return c, bufOut.String(), bufErr.String(), err
}

@ -19,6 +19,7 @@ package cmd
import ( import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"strings"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -86,6 +87,43 @@ func TestShowPreReleaseChart(t *testing.T) {
} }
} }
func TestShowOCIChartRegistryPullMetadataGoesToStderr(t *testing.T) {
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
)
defer srv.Stop()
ociSrv, err := repotest.NewOCIServer(t, srv.Root())
if err != nil {
t.Fatal(err)
}
ociSrv.Run(t)
contentTmp := t.TempDir()
outdir := srv.Root()
cmdStr := fmt.Sprintf("show chart oci://%s/u/ocitestuser/oci-dependent-chart --version 0.1.0 --registry-config %s --content-cache %s --plain-http",
ociSrv.RegistryURL,
filepath.Join(outdir, "config.json"),
contentTmp,
)
_, outStr, errStr, err := executeActionCommandErr(storageFixture(), nil, cmdStr)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if strings.Contains(outStr, "Pulled: ") || strings.Contains(outStr, "Digest: ") {
t.Fatalf("expected stdout to exclude registry pull metadata, got: %s", outStr)
}
if !strings.Contains(errStr, "Pulled: ") {
t.Fatalf("expected stderr to contain registry pull metadata, got: %s", errStr)
}
if !strings.Contains(outStr, "apiVersion:") {
t.Fatalf("expected chart metadata in output, got: %s", outStr)
}
}
func TestShowVersionCompletion(t *testing.T) { func TestShowVersionCompletion(t *testing.T) {
repoFile := "testdata/helmhome/helm/repositories.yaml" repoFile := "testdata/helmhome/helm/repositories.yaml"
repoCache := "testdata/helmhome/helm/repository" repoCache := "testdata/helmhome/helm/repository"

@ -19,7 +19,10 @@ package cmd
import ( import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"strings"
"testing" "testing"
"helm.sh/helm/v4/pkg/repo/v1/repotest"
) )
var chartPath = "testdata/testcharts/subchart" var chartPath = "testdata/testcharts/subchart"
@ -176,6 +179,43 @@ func TestTemplateCmd(t *testing.T) {
runTestCmd(t, tests) runTestCmd(t, tests)
} }
func TestTemplateOCIChartRegistryPullMetadataGoesToStderr(t *testing.T) {
srv := repotest.NewTempServer(
t,
repotest.WithChartSourceGlob("testdata/testcharts/*.tgz*"),
)
defer srv.Stop()
ociSrv, err := repotest.NewOCIServer(t, srv.Root())
if err != nil {
t.Fatal(err)
}
ociSrv.Run(t)
contentTmp := t.TempDir()
outdir := srv.Root()
cmdStr := fmt.Sprintf("template --generate-name oci://%s/u/ocitestuser/oci-dependent-chart --version 0.1.0 --registry-config %s --content-cache %s --plain-http",
ociSrv.RegistryURL,
filepath.Join(outdir, "config.json"),
contentTmp,
)
_, outStr, errStr, err := executeActionCommandErr(storageFixture(), nil, cmdStr)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if strings.Contains(outStr, "Pulled: ") || strings.Contains(outStr, "Digest: ") {
t.Fatalf("expected stdout to exclude registry pull metadata, got: %s", outStr)
}
if !strings.Contains(errStr, "Pulled: ") {
t.Fatalf("expected stderr to contain registry pull metadata, got: %s", errStr)
}
if !strings.Contains(outStr, "# Source:") {
t.Fatalf("expected rendered manifests in output, got: %s", outStr)
}
}
func TestTemplateVersionCompletion(t *testing.T) { func TestTemplateVersionCompletion(t *testing.T) {
repoFile := "testdata/helmhome/helm/repositories.yaml" repoFile := "testdata/helmhome/helm/repositories.yaml"
repoCache := "testdata/helmhome/helm/repository" repoCache := "testdata/helmhome/helm/repository"

Loading…
Cancel
Save