Merge pull request #8915 from zheng1/master

Bugfix: panic when chart contains requirements.lock
pull/8960/head
Matt Farina 4 years ago committed by GitHub
commit c0d3877231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -123,6 +123,9 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil { if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil {
return c, errors.Wrap(err, "cannot load requirements.lock") return c, errors.Wrap(err, "cannot load requirements.lock")
} }
if c.Metadata == nil {
c.Metadata = new(chart.Metadata)
}
if c.Metadata.APIVersion == chart.APIVersionV1 { if c.Metadata.APIVersion == chart.APIVersionV1 {
c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data}) c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data})
} }

@ -206,6 +206,32 @@ func TestLoadFile(t *testing.T) {
verifyDependencies(t, c) verifyDependencies(t, c)
} }
func TestLoadFiles_BadCases(t *testing.T) {
for _, tt := range []struct {
name string
bufferedFiles []*BufferedFile
expectError string
}{
{
name: "These files contain only requirements.lock",
bufferedFiles: []*BufferedFile{
{
Name: "requirements.lock",
Data: []byte(""),
},
},
expectError: "validation: chart.metadata.apiVersion is required"},
} {
_, err := LoadFiles(tt.bufferedFiles)
if err == nil {
t.Fatal("expected error when load illegal files")
}
if !strings.Contains(err.Error(), tt.expectError) {
t.Errorf("Expected error to contain %q, got %q for %s", tt.expectError, err.Error(), tt.name)
}
}
}
func TestLoadFiles(t *testing.T) { func TestLoadFiles(t *testing.T) {
goodFiles := []*BufferedFile{ goodFiles := []*BufferedFile{
{ {

Loading…
Cancel
Save