fix(install): add more tests and check nil file data

Signed-off-by: Manuel Alonso <434575+manute@users.noreply.github.com>
pull/31578/head
Manuel Alonso 2 months ago
parent 0357e8d0f7
commit 00f0a48a7d
No known key found for this signature in database
GPG Key ID: 9315A3EFCBD4D56A

@ -184,12 +184,20 @@ func (i *Install) installCRDs(crds []chart.CRD) error {
return fmt.Errorf("failed to install CRD %s: file is empty", obj.Name)
}
if obj.File.Data == nil {
return fmt.Errorf("failed to install CRD %s: file data is empty", obj.Name)
}
// Read in the resources
res, err := i.cfg.KubeClient.Build(bytes.NewBuffer(obj.File.Data), false)
if err != nil {
return fmt.Errorf("failed to install CRD %s: %w", obj.Name, err)
}
if len(res) == 0 {
return fmt.Errorf("failed to install CRD %s: resources are empty", obj.Name)
}
// Send them to Kube
if _, err := i.cfg.KubeClient.Create(
res,

@ -1072,23 +1072,20 @@ func TestInstallRun_UnreachableKubeClient(t *testing.T) {
func TestInstallCRDs_CheckNilErrors(t *testing.T) {
tests := []struct {
name string
input []chart.CRD
expectedErr bool
name string
input []chart.CRD
}{
{
name: "only one crd with file nil",
input: []chart.CRD{
{Name: "one", File: nil},
},
expectedErr: true,
},
{
name: "only one crd with its file data nil",
input: []chart.CRD{
{Name: "one", File: &common.File{Name: "crds/foo.yaml", Data: nil}},
},
expectedErr: false,
},
{
name: "at least a crd with its file data nil",
@ -1097,7 +1094,6 @@ func TestInstallCRDs_CheckNilErrors(t *testing.T) {
{Name: "two", File: &common.File{Name: "crds/foo2.yaml", Data: nil}},
{Name: "three", File: &common.File{Name: "crds/foo3.yaml", Data: []byte("data")}},
},
expectedErr: false,
},
}
@ -1106,8 +1102,8 @@ func TestInstallCRDs_CheckNilErrors(t *testing.T) {
instAction := installAction(t)
err := instAction.installCRDs(tt.input)
if tt.expectedErr && err == nil {
t.Errorf("got error %v expected nil", err)
if err == nil {
t.Errorf("got nil expected err")
}
})
}

@ -240,7 +240,7 @@ func TestInstall(t *testing.T) {
// Install chart with only crds
{
name: "install chart with only crds",
cmd: "install crd-test testdata/testcharts/chart-with-only-crds --namespace default",
cmd: "install crd-test testdata/testcharts/chart-with-only-crds --namespace default --dry-run",
},
// Verify the user/pass works
{

Loading…
Cancel
Save