Repository: helm/helm (go)

Issue:
Helm panics with an unknown storage driver
<!-- If you need help or think you have found a bug, please help us with your issue by entering the following information (otherwise you can delete this text): -->

Output of `helm version`: 3.15.2

Output of `kubectl version`: N/A

Cloud Provider/Platform (AKS, GKE, Minikube etc.):  N/A

When there is an unknown storage driver (for helm releases) there is a panic. For example...

```console
$ HELM_DRIVER=foo helm help
panic: Unknown driver in HELM_DRIVER: foo

goroutine 1 [running]:
helm.sh/helm/v3/pkg/action.(*Configuration).Init(0xc00057a140, {0x2559598, 0xc0001dcfc0}, {0x2085221, 0x7}, {0xc00001201c, 0x3}, 0x2354a58)
	helm.sh/helm/v3/pkg/action/action.go:419 +0x7b9
main.main.func1()
	helm.sh/helm/v3/cmd/helm/helm.go:75 +0x7b
github.com/spf13/cobra.(*Command).preRun(...)
	github.com/spf13/cobra@v1.8.0/command.go:1017
github.com/spf13/cobra.(*Command).execute(0xc000696308, {0x368d8e0, 0x0, 0x0})
	github.com/spf13/cobra@v1.8.0/command.go:927 +0x5a2
github.com/spf13/cobra.(*Command).ExecuteC(0xc000418008)
	github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
	helm.sh/helm/v3/cmd/helm/helm.go:83 +0x209
```




Pull request:
fix: update error handling in Configuration.Init method, add tests for the method
fixes #13127 

**What this PR does / why we need it**:
Replaced panic with an error in the `Configuration.Init` method and added tests for the method

- [Y] this PR contains unit tests

Patch:
diff --git a/pkg/action/action.go b/pkg/action/action.go
index 863c48f07..145c78090 100644
--- a/pkg/action/action.go
+++ b/pkg/action/action.go
@@ -330,7 +330,7 @@ func GetVersionSet(client discovery.ServerResourcesInterface) (chartutil.Version
 	}
 
 	versionMap := make(map[string]interface{})
-	versions := []string{}
+	var versions []string
 
 	// Extract the groups
 	for _, g := range groups {
@@ -411,12 +411,11 @@ func (cfg *Configuration) Init(getter genericclioptions.RESTClientGetter, namesp
 			namespace,
 		)
 		if err != nil {
-			panic(fmt.Sprintf("Unable to instantiate SQL driver: %v", err))
+			return errors.Wrap(err, "unable to instantiate SQL driver")
 		}
 		store = storage.Init(d)
 	default:
-		// Not sure what to do here.
-		panic("Unknown driver in HELM_DRIVER: " + helmDriver)
+		return errors.Errorf("unknown driver %q", helmDriver)
 	}
 
 	cfg.RESTClientGetter = getter


Test patch:
diff --git a/pkg/action/action_test.go b/pkg/action/action_test.go
index fdcfa7558..149eb85b1 100644
--- a/pkg/action/action_test.go
+++ b/pkg/action/action_test.go
@@ -17,9 +17,11 @@ package action
 
 import (
 	"flag"
+	"fmt"
 	"io"
 	"testing"
 
+	"github.com/stretchr/testify/assert"
 	fakeclientset "k8s.io/client-go/kubernetes/fake"
 
 	"helm.sh/helm/v3/pkg/chart"
@@ -273,6 +275,74 @@ func namedReleaseStub(name string, status release.Status) *release.Release {
 	}
 }
 
+func TestConfiguration_Init(t *testing.T) {
+	tests := []struct {
+		name               string
+		helmDriver         string
+		expectedDriverType interface{}
+		expectErr          bool
+		errMsg             string
+	}{
+		{
+			name:               "Test secret driver",
+			helmDriver:         "secret",
+			expectedDriverType: &driver.Secrets{},
+		},
+		{
+			name:               "Test secrets driver",
+			helmDriver:         "secrets",
+			expectedDriverType: &driver.Secrets{},
+		},
+		{
+			name:               "Test empty driver",
+			helmDriver:         "",
+			expectedDriverType: &driver.Secrets{},
+		},
+		{
+			name:               "Test configmap driver",
+			helmDriver:         "configmap",
+			expectedDriverType: &driver.ConfigMaps{},
+		},
+		{
+			name:               "Test configmaps driver",
+			helmDriver:         "configmaps",
+			expectedDriverType: &driver.ConfigMaps{},
+		},
+		{
+			name:               "Test memory driver",
+			helmDriver:         "memory",
+			expectedDriverType: &driver.Memory{},
+		},
+		{
+			name:       "Test sql driver",
+			helmDriver: "sql",
+			expectErr:  true,
+			errMsg:     "unable to instantiate SQL driver",
+		},
+		{
+			name:       "Test unknown driver",
+			helmDriver: "someDriver",
+			expectErr:  true,
+			errMsg:     fmt.Sprintf("unknown driver %q", "someDriver"),
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			cfg := &Configuration{}
+
+			actualErr := cfg.Init(nil, "default", tt.helmDriver, nil)
+			if tt.expectErr {
+				assert.Error(t, actualErr)
+				assert.Contains(t, actualErr.Error(), tt.errMsg)
+			} else {
+				assert.NoError(t, actualErr)
+				assert.IsType(t, tt.expectedDriverType, cfg.Releases.Driver)
+			}
+		})
+	}
+}
+
 func TestGetVersionSet(t *testing.T) {
 	client := fakeclientset.NewSimpleClientset()