From bff6ab13f46d271a69b616faf832f545472ba3fd Mon Sep 17 00:00:00 2001 From: Cyril Jouve Date: Sat, 12 Nov 2022 13:18:00 +0100 Subject: [PATCH] non-regression for #11385 Signed-off-by: Cyril Jouve --- cmd/helm/testdata/output/upgrade-json.txt | 1 + cmd/helm/testdata/output/upgrade-oci-json.txt | 1 + .../testcharts/test-upgrade-chart-0.1.7.tgz | Bin 0 -> 400 bytes cmd/helm/upgrade_test.go | 32 +++++++++++++++++- pkg/repo/repotest/server.go | 17 ++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 cmd/helm/testdata/output/upgrade-json.txt create mode 100644 cmd/helm/testdata/output/upgrade-oci-json.txt create mode 100644 cmd/helm/testdata/testcharts/test-upgrade-chart-0.1.7.tgz diff --git a/cmd/helm/testdata/output/upgrade-json.txt b/cmd/helm/testdata/output/upgrade-json.txt new file mode 100644 index 000000000..b60ae5fa3 --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-json.txt @@ -0,0 +1 @@ +{"name":"funny-bunny","info":{"first_deployed":"1977-09-02T22:04:05Z","last_deployed":"1977-09-02T22:04:05Z","deleted":"","description":"Upgrade complete","status":"deployed"},"chart":{"metadata":{"name":"test-upgrade-chart","version":"0.1.3","description":"A Helm chart for Kubernetes","apiVersion":"v1"},"lock":null,"templates":null,"values":null,"schema":null,"files":null},"config":{"name":"value"},"version":7,"namespace":"default"} diff --git a/cmd/helm/testdata/output/upgrade-oci-json.txt b/cmd/helm/testdata/output/upgrade-oci-json.txt new file mode 100644 index 000000000..3abec031a --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-oci-json.txt @@ -0,0 +1 @@ +{"name":"funny-bunny","info":{"first_deployed":"1977-09-02T22:04:05Z","last_deployed":"1977-09-02T22:04:05Z","deleted":"","description":"Upgrade complete","status":"deployed"},"chart":{"metadata":{"name":"test-upgrade-chart","version":"0.1.7","description":"A Helm chart for Kubernetes","apiVersion":"v1"},"lock":null,"templates":[{"name":"templates/configmap.yaml","data":"YXBpVmVyc2lvbjogdjEKa2luZDogQ29uZmlnTWFwCm1ldGFkYXRhOgogIG5hbWU6ICJ7eyAuUmVsZWFzZS5OYW1lIH19LWNvbmZpZ21hcCIKZGF0YToKICBteXZhbHVlOiAiSGVsbG8gV29ybGQiCiAgZHJpbms6IHt7IC5WYWx1ZXMuZmF2b3JpdGVEcmluayB9fQ=="}],"values":{"favoriteDrink":"beer"},"schema":null,"files":null},"config":{"name":"value"},"manifest":"---\n# Source: test-upgrade-chart/templates/configmap.yaml\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: \"funny-bunny-configmap\"\ndata:\n myvalue: \"Hello World\"\n drink: beer\n","version":8,"namespace":"default"} diff --git a/cmd/helm/testdata/testcharts/test-upgrade-chart-0.1.7.tgz b/cmd/helm/testdata/testcharts/test-upgrade-chart-0.1.7.tgz new file mode 100644 index 0000000000000000000000000000000000000000..e27e1b3ae62eae70e582d34e8d6fd6d181a83ee9 GIT binary patch literal 400 zcmV;B0dM{viwG0|00000|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PK~|isC>JhjZ?yC~`Me%sd)R|}E=}nMyOYq}35ev~ z2O|zlM)aU4!}NDZ6A0a@q`vxDHg?iBTTKN|*8fS{>HK&N_N1iu7!VQDI389+9IqJ0 z=!J0=i>+!ukGa>?41b(KRGih|8rmyI3nf53vJ zf}ty5Q)~Fuu2@%W*@%i1=kU3EM0ef|gD}X%tLt-I=Yszo$(GFn2f!`=aTbmIPr@j3 z{y&2ab+s-n|I}r*%VEW=U;RpsCvw4m%c_xN*-Y1UwJEoXn)`;qE&pe;c;tVUV(k2X z2BZAnl~s|$eE9FbsS%1T6=W$F0H?_J4+jYTvSczG{2|5A_mlTV@x}RRwI6aM2Y^vhW2!ahf#8ZI-8``7nc^?_d2*91e%$JMb0&0RR8Gpwp-T5C8znmce%b literal 0 HcmV?d00001 diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index 8afcb139b..e62b20905 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -29,6 +29,7 @@ import ( "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/release" + "helm.sh/helm/v3/pkg/repo/repotest" ) func TestUpgradeCmd(t *testing.T) { @@ -37,7 +38,7 @@ func TestUpgradeCmd(t *testing.T) { cfile := &chart.Chart{ Metadata: &chart.Metadata{ APIVersion: chart.APIVersionV1, - Name: "testUpgradeChart", + Name: "test-upgrade-chart", Description: "A Helm chart for Kubernetes", Version: "0.1.0", }, @@ -90,6 +91,23 @@ func TestUpgradeCmd(t *testing.T) { return release.Mock(&release.MockReleaseOptions{Name: n, Version: v, Chart: ch}) } + srv, err := repotest.NewTempServerWithCleanup(t, "testdata/testcharts/*.tgz") + if err != nil { + t.Fatal(err) + } + defer srv.Stop() + outdir := srv.Root() + + ociSrv, err := repotest.NewOCIServer(t, srv.Root()) + if err != nil { + t.Fatal(err) + } + ociSrv.Run(t) + + if err := srv.LinkIndices(); err != nil { + t.Fatal(err) + } + tests := []cmdTestCase{ { name: "upgrade a release", @@ -115,6 +133,18 @@ func TestUpgradeCmd(t *testing.T) { golden: "output/upgrade-with-reset-values2.txt", rels: []*release.Release{relMock("funny-bunny", 5, ch2)}, }, + { + name: "upgrade a release with json output", + cmd: fmt.Sprintf("upgrade --output json funny-bunny '%s'", chartPath), + golden: "output/upgrade-json.txt", + rels: []*release.Release{relMock("funny-bunny", 6, ch)}, + }, + { + name: "upgrade a oci release with json output", + cmd: fmt.Sprintf("upgrade --output json funny-bunny 'oci://%s/u/ocitestuser/test-upgrade-chart' --version 0.1.7 --registry-config %s", ociSrv.RegistryURL, filepath.Join(outdir, "config.json")), + golden: "output/upgrade-oci-json.txt", + rels: []*release.Release{relMock("funny-bunny", 7, ch)}, + }, { name: "install a release with 'upgrade --install'", cmd: fmt.Sprintf("upgrade zany-bunny -i '%s'", chartPath), diff --git a/pkg/repo/repotest/server.go b/pkg/repo/repotest/server.go index 90ad3d856..5494a51d3 100644 --- a/pkg/repo/repotest/server.go +++ b/pkg/repo/repotest/server.go @@ -210,6 +210,22 @@ func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) { result.Config.Digest, result.Config.Size, result.Chart.Digest, result.Chart.Size) + upgradeRef := fmt.Sprintf("%s/u/ocitestuser/test-upgrade-chart:0.1.7", srv.RegistryURL) + contentBytes, err = os.ReadFile(filepath.Join(srv.Dir, "test-upgrade-chart-0.1.7.tgz")) + if err != nil { + t.Fatal("could not load chart into memory") + } + result, err = registryClient.Push(contentBytes, upgradeRef) + if err != nil { + t.Fatalf("error pushing chart: %s", err) + } + t.Logf("Manifest.Digest: %s, Manifest.Size: %d, "+ + "Config.Digest: %s, Config.Size: %d, "+ + "Chart.Digest: %s, Chart.Size: %d", + result.Manifest.Digest, result.Manifest.Size, + result.Config.Digest, result.Config.Size, + result.Chart.Digest, result.Chart.Size) + srv.Client = registryClient c := cfg.DependingChart if c == nil { @@ -400,6 +416,7 @@ func (s *Server) Stop() { // URL returns the URL of the server. // // Example: +// // http://localhost:1776 func (s *Server) URL() string { return s.srv.URL