diff --git a/main.go b/main.go index 849b5a4..a3a0bed 100644 --- a/main.go +++ b/main.go @@ -90,6 +90,6 @@ func run(c *cli.Context) error { }, } resolveSecrets(&plugin) - + plugin.debug() return plugin.Exec() } diff --git a/plugin.go b/plugin.go index 93d4673..491dc35 100644 --- a/plugin.go +++ b/plugin.go @@ -147,6 +147,11 @@ func getEnvVars(envvars string) [][]string { return extracted } +func resolveEnvVar(key string, prefix string) string { + envvars := getEnvVars(key) + return replaceEnvvars(envvars, prefix, key) +} + func replaceEnvvars(envvars [][]string, prefix string, s string) string { for _, envvar := range envvars { envvarName := envvar[0] @@ -160,18 +165,9 @@ func replaceEnvvars(envvars [][]string, prefix string, s string) string { s = strings.Replace(s, envvarName, envval, -1) } } - // fmt.Println(s) return s } -// this functions checks if $VAR or ${VAR} exists and -// returns the text with resolved vars -func resolveEnvVar(key string, prefix string) string { - envvars := getEnvVars(key) - // fmt.Println(envvars) - return replaceEnvvars(envvars, prefix, key) -} - func (p *Plugin) debug() { fmt.Println(p) // debug env vars diff --git a/plugin_test.go b/plugin_test.go index afae42e..7799b63 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "io/ioutil" "os" "strings" @@ -60,8 +59,6 @@ func TestGetHelmCommand(t *testing.T) { setHelmCommand(plugin) res := strings.Join(plugin.Config.HelmCommand[:], " ") expected := "upgrade --install test-release ./chart/test --set image.tag=v.0.1.0,nameOverride=my-over-app --dry-run --debug" - fmt.Println(res) - fmt.Println(expected) if res != expected { t.Errorf("Result is %s and we expected %s", res, expected) } @@ -126,3 +123,23 @@ func TestReplaceEnvvars(t *testing.T) { t.Errorf("EnvVar MY_TAG no replaced by %s ", tag) } } + +func TestSetHelmHelp(t *testing.T) { + plugin := &Plugin{ + Config: Config{ + HelmCommand: nil, + Namespace: "default", + SkipTLSVerify: true, + Debug: true, + DryRun: true, + Chart: "./chart/test", + Release: "test-release", + Prefix: "MY", + Values: "image.tag=$TAG,api=${API_SERVER},nameOverride=my-over-app,second.tag=${TAG}", + }, + } + setHelmHelp(plugin) + if plugin.Config.HelmCommand == nil { + t.Error("Helm help is not displayed") + } +}