diff --git a/pkg/helmexec/exec.go b/pkg/helmexec/exec.go index 4cdb15b2..c1e1c69b 100644 --- a/pkg/helmexec/exec.go +++ b/pkg/helmexec/exec.go @@ -84,6 +84,10 @@ func (helm *execer) SetHelmBinary(bin string) { func (helm *execer) AddRepo(name, repository, cafile, certfile, keyfile, username, password string) error { var args []string + if name == "" && repository != "" { + helm.logger.Infof("empty field name\n") + return fmt.Errorf("empty field name") + } args = append(args, "repo", "add", name, repository) if certfile != "" && keyfile != "" { args = append(args, "--cert-file", certfile, "--key-file", keyfile) diff --git a/pkg/helmexec/exec_test.go b/pkg/helmexec/exec_test.go index ec96825d..7a5ffc7d 100644 --- a/pkg/helmexec/exec_test.go +++ b/pkg/helmexec/exec_test.go @@ -109,6 +109,15 @@ exec: helm repo add myRepo https://repo.example.com/ --kube-context dev: expected = `Adding repo myRepo https://repo.example.com/ exec: helm repo add myRepo https://repo.example.com/ --username example_user --password example_password --kube-context dev exec: helm repo add myRepo https://repo.example.com/ --username example_user --password example_password --kube-context dev: +` + if buffer.String() != expected { + t.Errorf("helmexec.AddRepo()\nactual = %v\nexpect = %v", buffer.String(), expected) + } + + buffer.Reset() + helm.AddRepo("", "https://repo.example.com/", "", "", "", "", "") + expected = `empty field name + ` if buffer.String() != expected { t.Errorf("helmexec.AddRepo()\nactual = %v\nexpect = %v", buffer.String(), expected)