mirror of
https://github.com/helm/helm.git
synced 2026-08-13 17:07:28 +00:00
Create missing directories when saving files in chartutil.SaveDir
This commit is contained in:
@@ -70,6 +70,12 @@ func SaveDir(c *chart.Chart, dest string) error {
|
||||
// Save files
|
||||
for _, f := range c.Files {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/any"
|
||||
"k8s.io/helm/pkg/proto/hapi/chart"
|
||||
)
|
||||
|
||||
@@ -40,6 +41,9 @@ func TestSave(t *testing.T) {
|
||||
Values: &chart.Config{
|
||||
Raw: "ship: Pequod",
|
||||
},
|
||||
Files: []*any.Any{
|
||||
{TypeUrl: "scheherazade/shahryar.txt", Value: []byte("1,001 Nights")},
|
||||
},
|
||||
}
|
||||
|
||||
where, err := Save(c, tmp)
|
||||
@@ -64,6 +68,9 @@ func TestSave(t *testing.T) {
|
||||
if c2.Values.Raw != c.Values.Raw {
|
||||
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) {
|
||||
@@ -81,6 +88,9 @@ func TestSaveDir(t *testing.T) {
|
||||
Values: &chart.Config{
|
||||
Raw: "ship: Pequod",
|
||||
},
|
||||
Files: []*any.Any{
|
||||
{TypeUrl: "scheherazade/shahryar.txt", Value: []byte("1,001 Nights")},
|
||||
},
|
||||
}
|
||||
|
||||
if err := SaveDir(c, tmp); err != nil {
|
||||
@@ -98,4 +108,7 @@ func TestSaveDir(t *testing.T) {
|
||||
if c2.Values.Raw != c.Values.Raw {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user