pull/11060/merge
emerson_gong 1 year ago committed by GitHub
commit a7b24b02eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -159,6 +159,24 @@ func getReleaseHistory(rls []*release.Release) (history releaseHistory) {
return history return history
} }
func getChartname(c *chart.Chart) string {
if c == nil || c.Metadata == nil {
// This is an edge case that has happened in prod, though we don't
// know how: https://github.com/helm/helm/issues/1347
return "MISSING"
}
return c.Metadata.Name
}
func getChartVerison(c *chart.Chart) string {
if c == nil || c.Metadata == nil {
// This is an edge case that has happened in prod, though we don't
// know how: https://github.com/helm/helm/issues/1347
return "MISSING"
}
return c.Metadata.Version
}
func formatChartname(c *chart.Chart) string { func formatChartname(c *chart.Chart) string {
if c == nil || c.Metadata == nil { if c == nil || c.Metadata == nil {
// This is an edge case that has happened in prod, though we don't // This is an edge case that has happened in prod, though we don't

@ -20,6 +20,8 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/stretchr/testify/assert"
"helm.sh/helm/v3/pkg/release" "helm.sh/helm/v3/pkg/release"
) )
@ -122,3 +124,28 @@ func TestHistoryFileCompletion(t *testing.T) {
checkFileCompletion(t, "history", false) checkFileCompletion(t, "history", false)
checkFileCompletion(t, "history myrelease", false) checkFileCompletion(t, "history myrelease", false)
} }
func TestGetChartDetails(t *testing.T) {
demoRelease := release.Mock(&release.MockReleaseOptions{
Name: "demo",
Version: 1.0,
Status: release.StatusDeployed,
})
assert.Equal(t, formatAppVersion(demoRelease.Chart), "1.0", nil)
assert.Equal(t, getChartVerison(demoRelease.Chart), "0.1.0-beta.1", nil)
assert.Equal(t, getChartname(demoRelease.Chart), "foo", nil)
}
func TestGetChartDetailsWithNullChart(t *testing.T) {
demoRelease := release.Mock(&release.MockReleaseOptions{
Name: "demo",
Version: 1.0,
Status: release.StatusDeployed,
})
demoRelease.Chart = nil
assert.Equal(t, formatAppVersion(demoRelease.Chart), "MISSING", nil)
assert.Equal(t, getChartVerison(demoRelease.Chart), "MISSING", nil)
assert.Equal(t, getChartname(demoRelease.Chart), "MISSING", nil)
}

@ -139,6 +139,8 @@ type releaseElement struct {
Updated string `json:"updated"` Updated string `json:"updated"`
Status string `json:"status"` Status string `json:"status"`
Chart string `json:"chart"` Chart string `json:"chart"`
ChartName string `json:"chart_name"`
ChartVersion string `json:"chart_version"`
AppVersion string `json:"app_version"` AppVersion string `json:"app_version"`
} }
@ -157,6 +159,8 @@ func newReleaseListWriter(releases []*release.Release, timeFormat string, noHead
Revision: strconv.Itoa(r.Version), Revision: strconv.Itoa(r.Version),
Status: r.Info.Status.String(), Status: r.Info.Status.String(),
Chart: formatChartname(r.Chart), Chart: formatChartname(r.Chart),
ChartName: getChartname(r.Chart),
ChartVersion: getChartVerison(r.Chart),
AppVersion: formatAppVersion(r.Chart), AppVersion: formatAppVersion(r.Chart),
} }

@ -148,6 +148,16 @@ func TestListCmd(t *testing.T) {
cmd: "list", cmd: "list",
golden: "output/list.txt", golden: "output/list.txt",
rels: releaseFixture, rels: releaseFixture,
}, {
name: "list releases in full yaml format",
cmd: "list --output yaml",
golden: "output/list-full-yaml.txt",
rels: releaseFixture,
}, {
name: "list releases in full json format",
cmd: "list --output json",
golden: "output/list-full-json.txt",
rels: releaseFixture,
}, { }, {
name: "list without headers", name: "list without headers",
cmd: "list --no-headers", cmd: "list --no-headers",

@ -0,0 +1 @@
[{"name":"hummingbird","namespace":"default","revision":"1","updated":"2016-01-16 00:00:03 +0000 UTC","status":"deployed","chart":"chickadee-1.0.0","chart_name":"chickadee","chart_version":"1.0.0","app_version":"0.0.1"},{"name":"iguana","namespace":"default","revision":"2","updated":"2016-01-16 00:00:04 +0000 UTC","status":"deployed","chart":"chickadee-1.0.0","chart_name":"chickadee","chart_version":"1.0.0","app_version":"0.0.1"},{"name":"rocket","namespace":"default","revision":"1","updated":"2016-01-16 00:00:02 +0000 UTC","status":"failed","chart":"chickadee-1.0.0","chart_name":"chickadee","chart_version":"1.0.0","app_version":"0.0.1"},{"name":"starlord","namespace":"default","revision":"2","updated":"2016-01-16 00:00:01 +0000 UTC","status":"deployed","chart":"chickadee-1.0.0","chart_name":"chickadee","chart_version":"1.0.0","app_version":"0.0.1"}]

@ -0,0 +1,36 @@
- app_version: 0.0.1
chart: chickadee-1.0.0
chart_name: chickadee
chart_version: 1.0.0
name: hummingbird
namespace: default
revision: "1"
status: deployed
updated: 2016-01-16 00:00:03 +0000 UTC
- app_version: 0.0.1
chart: chickadee-1.0.0
chart_name: chickadee
chart_version: 1.0.0
name: iguana
namespace: default
revision: "2"
status: deployed
updated: 2016-01-16 00:00:04 +0000 UTC
- app_version: 0.0.1
chart: chickadee-1.0.0
chart_name: chickadee
chart_version: 1.0.0
name: rocket
namespace: default
revision: "1"
status: failed
updated: 2016-01-16 00:00:02 +0000 UTC
- app_version: 0.0.1
chart: chickadee-1.0.0
chart_name: chickadee
chart_version: 1.0.0
name: starlord
namespace: default
revision: "2"
status: deployed
updated: 2016-01-16 00:00:01 +0000 UTC
Loading…
Cancel
Save