show crds command output separated by document separator

Signed-off-by: Daniel Pap <papfdani@gmail.com>
pull/12624/head
Daniel Pap 2 years ago
parent e6edb15067
commit f25e0d6073

@ -139,10 +139,10 @@ func (s *Show) Run(chartpath string) (string, error) {
if s.OutputFormat == ShowCRDs || s.OutputFormat == ShowAll {
crds := s.chart.CRDObjects()
if len(crds) > 0 {
if s.OutputFormat == ShowAll && !bytes.HasPrefix(crds[0].File.Data, []byte("---")) {
fmt.Fprintln(&out, "---")
}
for _, crd := range crds {
if !bytes.HasPrefix(crd.File.Data, []byte("---")) {
fmt.Fprintln(&out, "---")
}
fmt.Fprintf(&out, "%s\n", string(crd.File.Data))
}
}

@ -32,6 +32,7 @@ func TestShow(t *testing.T) {
{Name: "crds/ignoreme.txt", Data: []byte("error")},
{Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")},
{Name: "crds/bar.json", Data: []byte("---\nbar\n")},
{Name: "crds/baz.yaml", Data: []byte("baz\n")},
},
Raw: []*chart.File{
{Name: "values.yaml", Data: []byte("VALUES\n")},
@ -58,6 +59,9 @@ foo
---
bar
---
baz
`
if output != expect {
t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)
@ -102,6 +106,7 @@ func TestShowCRDs(t *testing.T) {
{Name: "crds/ignoreme.txt", Data: []byte("error")},
{Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")},
{Name: "crds/bar.json", Data: []byte("---\nbar\n")},
{Name: "crds/baz.yaml", Data: []byte("baz\n")},
},
}
@ -116,6 +121,9 @@ foo
---
bar
---
baz
`
if output != expect {
t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)

Loading…
Cancel
Save