fi(helm): add more tests for plugins

This adds tests for setupEnv, and also updates some documentation to
mirror the current state of plugins.
parent ac628a82
......@@ -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")
}
}
......@@ -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)
}
}
}
......@@ -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.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment