From a5d818dc4af65fc1660ce10ae3db43328694b53f Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Thu, 1 Dec 2016 16:28:59 -0700 Subject: [PATCH] fi(helm): add more tests for plugins This adds tests for setupEnv, and also updates some documentation to mirror the current state of plugins. --- cmd/helm/plugins.go | 6 +++++- cmd/helm/plugins_test.go | 34 ++++++++++++++++++++++++++++++++++ docs/plugins.md | 19 ++++++++----------- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/cmd/helm/plugins.go b/cmd/helm/plugins.go index d0f317a4b..af3848379 100644 --- a/cmd/helm/plugins.go +++ b/cmd/helm/plugins.go @@ -173,10 +173,14 @@ func setupEnv(shortname, base, plugdirs string, home helmpath.Home) { "HELM_PATH_REPOSITORY_FILE": home.RepositoryFile(), "HELM_PATH_CACHE": home.Cache(), "HELM_PATH_LOCAL_REPOSITORY": home.LocalRepository(), - //"HELM_PATH_STARTER": home.Starter(), + "HELM_PATH_STARTER": home.Starters(), "TILLER_HOST": tillerHost, } { os.Setenv(key, val) } + + if flagDebug { + os.Setenv("HELM_DEBUG", "1") + } } diff --git a/cmd/helm/plugins_test.go b/cmd/helm/plugins_test.go index 77828ea3b..cd6cc8f71 100644 --- a/cmd/helm/plugins_test.go +++ b/cmd/helm/plugins_test.go @@ -18,6 +18,7 @@ package main import ( "bytes" "os" + "path/filepath" "strings" "testing" @@ -123,3 +124,36 @@ func TestLoadPlugins(t *testing.T) { } } } + +func TestSetupEnv(t *testing.T) { + name := "pequod" + hh := helmpath.Home("testdata/helmhome") + base := filepath.Join(hh.Plugins(), name) + plugdirs := hh.Plugins() + flagDebug = true + defer func() { + flagDebug = false + }() + + setupEnv(name, base, plugdirs, hh) + for _, tt := range []struct { + name string + expect string + }{ + {"HELM_PLUGIN_NAME", name}, + {"HELM_PLUGIN_DIR", base}, + {"HELM_PLUGIN", hh.Plugins()}, + {"HELM_DEBUG", "1"}, + {"HELM_HOME", hh.String()}, + {"HELM_PATH_REPOSITORY", hh.Repository()}, + {"HELM_PATH_REPOSITORY_FILE", hh.RepositoryFile()}, + {"HELM_PATH_CACHE", hh.Cache()}, + {"HELM_PATH_LOCAL_REPOSITORY", hh.LocalRepository()}, + {"HELM_PATH_STARTER", hh.Starters()}, + {"TILLER_HOST", tillerHost}, + } { + if got := os.Getenv(tt.name); got != tt.expect { + t.Errorf("Expected $%s=%q, got %q", tt.name, tt.expect, got) + } + } +} diff --git a/docs/plugins.md b/docs/plugins.md index d8aae6bea..3bb7a043e 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -159,18 +159,15 @@ to use the tunnel. ## A Note on Flag Parsing -When executing a plugin, Helm will parse global flags for its own use, but pass -all flags to the plugin. +When executing a plugin, Helm will parse global flags for its own use. Some of +these flags are _not_ passed on to the plugin. -Plugins MUST NOT produce an error for the following flags: - -- `--debug` -- `--home` -- `--host` -- `--kube-context` -- `-h` -- `--help` +- `--debug`: If this is specified, `$HELM_DEBUG` is set to `1` +- `--home`: This is converted to `$HELM_HOME` +- `--host`: This is convereted to `$HELM_HOST` +- `--kube-context`: This is simply dropped. If your plugin uses `useTunnel`, this + is used to set up the tunnel for you. Plugins _should_ display help text and then exit for `-h` and `--help`. In all -other cases, plugins may simply ignore the flags. +other cases, plugins may use flags as appropriate.