Merge pull request #3567 from jumal/master

Create missing directories when saving files in chartutil.SaveDir
pull/3478/head
Matthew Fisher 7 years ago committed by GitHub
commit b5af54d44c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -70,6 +70,12 @@ func SaveDir(c *chart.Chart, dest string) error {
// Save files // Save files
for _, f := range c.Files { for _, f := range c.Files {
n := filepath.Join(outdir, f.TypeUrl) n := filepath.Join(outdir, f.TypeUrl)
d := filepath.Dir(n)
if err := os.MkdirAll(d, 0755); err != nil {
return err
}
if err := ioutil.WriteFile(n, f.Value, 0755); err != nil { if err := ioutil.WriteFile(n, f.Value, 0755); err != nil {
return err return err
} }

@ -22,6 +22,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/golang/protobuf/ptypes/any"
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
) )
@ -40,6 +41,9 @@ func TestSave(t *testing.T) {
Values: &chart.Config{ Values: &chart.Config{
Raw: "ship: Pequod", Raw: "ship: Pequod",
}, },
Files: []*any.Any{
{TypeUrl: "scheherazade/shahryar.txt", Value: []byte("1,001 Nights")},
},
} }
where, err := Save(c, tmp) where, err := Save(c, tmp)
@ -64,6 +68,9 @@ func TestSave(t *testing.T) {
if c2.Values.Raw != c.Values.Raw { if c2.Values.Raw != c.Values.Raw {
t.Fatal("Values data did not match") t.Fatal("Values data did not match")
} }
if len(c2.Files) != 1 || c2.Files[0].TypeUrl != "scheherazade/shahryar.txt" {
t.Fatal("Files data did not match")
}
} }
func TestSaveDir(t *testing.T) { func TestSaveDir(t *testing.T) {
@ -81,6 +88,9 @@ func TestSaveDir(t *testing.T) {
Values: &chart.Config{ Values: &chart.Config{
Raw: "ship: Pequod", Raw: "ship: Pequod",
}, },
Files: []*any.Any{
{TypeUrl: "scheherazade/shahryar.txt", Value: []byte("1,001 Nights")},
},
} }
if err := SaveDir(c, tmp); err != nil { if err := SaveDir(c, tmp); err != nil {
@ -98,4 +108,7 @@ func TestSaveDir(t *testing.T) {
if c2.Values.Raw != c.Values.Raw { if c2.Values.Raw != c.Values.Raw {
t.Fatal("Values data did not match") t.Fatal("Values data did not match")
} }
if len(c2.Files) != 1 || c2.Files[0].TypeUrl != "scheherazade/shahryar.txt" {
t.Fatal("Files data did not match")
}
} }

Loading…
Cancel
Save