Run all builtins as plugins (#5536)

This commit is contained in:
Becca Petrin
2018-11-06 17:21:24 -08:00
committed by GitHub
parent f63bcdf106
commit fb89af7cfa
88 changed files with 1474 additions and 778 deletions

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/helper/consts"
"github.com/mitchellh/cli"
)
@@ -36,13 +37,13 @@ func TestPluginRegisterCommand_Run(t *testing.T) {
},
{
"too_many_args",
[]string{"foo", "bar"},
[]string{"foo", "bar", "fizz"},
"Too many arguments",
1,
},
{
"not_a_plugin",
[]string{"nope_definitely_never_a_plugin_nope"},
[]string{consts.PluginTypeCredential.String(), "nope_definitely_never_a_plugin_nope"},
"",
2,
},
@@ -90,7 +91,7 @@ func TestPluginRegisterCommand_Run(t *testing.T) {
code := cmd.Run([]string{
"-sha256", sha256Sum,
pluginName,
consts.PluginTypeCredential.String(), pluginName,
})
if exp := 0; code != exp {
t.Errorf("expected %d to be %d", code, exp)
@@ -102,19 +103,23 @@ func TestPluginRegisterCommand_Run(t *testing.T) {
t.Errorf("expected %q to contain %q", combined, expected)
}
resp, err := client.Sys().ListPlugins(&api.ListPluginsInput{})
resp, err := client.Sys().ListPlugins(&api.ListPluginsInput{
Type: consts.PluginTypeCredential,
})
if err != nil {
t.Fatal(err)
}
found := false
for _, p := range resp.Names {
if p == pluginName {
found = true
for _, plugins := range resp.PluginsByType {
for _, p := range plugins {
if p == pluginName {
found = true
}
}
}
if !found {
t.Errorf("expected %q to be in %q", pluginName, resp.Names)
t.Errorf("expected %q to be in %q", pluginName, resp.PluginsByType)
}
})
@@ -129,7 +134,7 @@ func TestPluginRegisterCommand_Run(t *testing.T) {
code := cmd.Run([]string{
"-sha256", "abcd1234",
"my-plugin",
consts.PluginTypeCredential.String(), "my-plugin",
})
if exp := 2; code != exp {
t.Errorf("expected %d to be %d", code, exp)