Merge pull request #1621 from technosophos/fix/tests-for-plugins

fi(helm): add more tests for plugins
pull/1634/head
Matt Butcher 8 years ago committed by GitHub
commit aec6c50708

@ -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"
@ -128,3 +129,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.

Loading…
Cancel
Save