fi(helm): add more tests for plugins

This adds tests for setupEnv, and also updates some documentation to
mirror the current state of plugins.
pull/1621/head
Matt Butcher 8 years ago
parent ac628a82cf
commit a5d818dc4a
No known key found for this signature in database
GPG Key ID: DCD5F5E5EF32C345

@ -173,10 +173,14 @@ func setupEnv(shortname, base, plugdirs string, home helmpath.Home) {
"HELM_PATH_REPOSITORY_FILE": home.RepositoryFile(), "HELM_PATH_REPOSITORY_FILE": home.RepositoryFile(),
"HELM_PATH_CACHE": home.Cache(), "HELM_PATH_CACHE": home.Cache(),
"HELM_PATH_LOCAL_REPOSITORY": home.LocalRepository(), "HELM_PATH_LOCAL_REPOSITORY": home.LocalRepository(),
//"HELM_PATH_STARTER": home.Starter(), "HELM_PATH_STARTER": home.Starters(),
"TILLER_HOST": tillerHost, "TILLER_HOST": tillerHost,
} { } {
os.Setenv(key, val) os.Setenv(key, val)
} }
if flagDebug {
os.Setenv("HELM_DEBUG", "1")
}
} }

@ -18,6 +18,7 @@ package main
import ( import (
"bytes" "bytes"
"os" "os"
"path/filepath"
"strings" "strings"
"testing" "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 ## A Note on Flag Parsing
When executing a plugin, Helm will parse global flags for its own use, but pass When executing a plugin, Helm will parse global flags for its own use. Some of
all flags to the plugin. these flags are _not_ passed on to the plugin.
Plugins MUST NOT produce an error for the following flags: - `--debug`: If this is specified, `$HELM_DEBUG` is set to `1`
- `--home`: This is converted to `$HELM_HOME`
- `--debug` - `--host`: This is convereted to `$HELM_HOST`
- `--home` - `--kube-context`: This is simply dropped. If your plugin uses `useTunnel`, this
- `--host` is used to set up the tunnel for you.
- `--kube-context`
- `-h`
- `--help`
Plugins _should_ display help text and then exit for `-h` and `--help`. In all 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