Repository: FairwindsOps/pluto (go)

Issue:
detect-helm reports no error if API is unreachable
We should definitely get an error for this instead:

```
$ kubectl get no
The connection to the server 127.0.0.1:32768 was refused - did you specify the right host or port?                                                                                                                                                                       
$ pluto detect-helm --helm-version 2
There were no apiVersions found that match our records.
$ pluto detect-helm --helm-version 3
There were no apiVersions found that match our records.
```

Pull request description:
catch errors from helm client
fixes #64

Patch:
diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go
index 51ab718..9afb1e4 100644
--- a/pkg/helm/helm.go
+++ b/pkg/helm/helm.go
@@ -70,7 +70,10 @@ func (h *Helm) getManifestsVersionTwo() error {
 	}
 	hcm := driverv2.NewConfigMaps(h.Kube.Client.CoreV1().ConfigMaps(""))
 	helmClient := helmstoragev2.Init(hcm)
-	list, _ := helmClient.ListDeployed()
+	list, err := helmClient.ListDeployed()
+	if err != nil {
+		return err
+	}
 	for _, release := range list {
 		outList, err := checkForAPIVersion([]byte(release.Manifest))
 		if err != nil {
@@ -88,7 +91,10 @@ func (h *Helm) getManifestsVersionThree() error {
 	}
 	hs := driverv3.NewSecrets(h.Kube.Client.CoreV1().Secrets(""))
 	helmClient := helmstoragev3.Init(hs)
-	list, _ := helmClient.ListDeployed()
+	list, err := helmClient.ListDeployed()
+	if err != nil {
+		return err
+	}
 	for _, release := range list {
 		outList, err := checkForAPIVersion([]byte(release.Manifest))
 		if err != nil {


Test patch:
diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go
index e8ec2f2..e678cdd 100644
--- a/pkg/helm/helm_test.go
+++ b/pkg/helm/helm_test.go
@@ -20,6 +20,8 @@ import (
 	"github.com/stretchr/testify/assert"
 	v1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/client-go/kubernetes"
+	"k8s.io/client-go/rest"
 
 	"github.com/fairwindsops/pluto/pkg/api"
 )
@@ -86,6 +88,14 @@ func newMockHelm(version string) *Helm {
 	}
 }
 
+func newBadKubeClient() (k *kube) {
+	conf := new(rest.Config)
+	conf.Host = "127.0.0.1:9999"
+	k = new(kube)
+	k.Client, _ = kubernetes.NewForConfig(conf)
+	return
+}
+
 func Test_checkForAPIVersion(t *testing.T) {
 	tests := []struct {
 		name     string
@@ -205,6 +215,51 @@ func TestHelm_getManifestsVersionThree(t *testing.T) {
 	}
 }
 
+func TestHelm_getManifest_badClient(t *testing.T) {
+	tests := []struct {
+		name        string
+		helmVersion string
+		wantErr     bool
+		errMessage  string
+		secret      *v1.Secret
+		want        []*api.Output
+	}{
+		{
+			name:        "two - bad client",
+			helmVersion: "2",
+			wantErr:     true,
+			errMessage:  "helm 3 function called without helm 3 version set",
+		},
+		{
+			name:        "three - bad client",
+			helmVersion: "3",
+			wantErr:     true,
+			errMessage:  "helm 3 function called without helm 3 version set",
+		},
+	}
+
+	for _, tt := range tests {
+		h := &Helm{
+			Version: tt.helmVersion,
+			Kube:    newBadKubeClient(),
+		}
+		t.Run(tt.name, func(t *testing.T) {
+			var err error
+			switch tt.helmVersion {
+			case "2":
+				err = h.getManifestsVersionTwo()
+			case "3":
+				err = h.getManifestsVersionThree()
+			}
+			if tt.wantErr {
+				assert.Error(t, err)
+				assert.Contains(t, err.Error(), "connect: connection refused")
+				return
+			}
+		})
+	}
+}
+
 func TestHelm_FindVersions(t *testing.T) {
 	tests := []struct {
 		name        string